~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/show.cc

Merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
737
737
  {}
738
738
};
739
739
 
740
 
void mysqld_list_processes(Session *session, const char *user)
741
 
{
742
 
  Item *field;
743
 
  List<Item> field_list;
744
 
  vector<thread_info> thread_infos;
745
 
 
746
 
  field_list.push_back(new Item_int("Id", 0, MY_INT32_NUM_DECIMAL_DIGITS));
747
 
  field_list.push_back(new Item_empty_string("User",16));
748
 
  field_list.push_back(new Item_empty_string("Host",LIST_PROCESS_HOST_LEN));
749
 
  field_list.push_back(field=new Item_empty_string("db",NAME_CHAR_LEN));
750
 
  field->maybe_null= true;
751
 
  field_list.push_back(new Item_empty_string("Command",16));
752
 
  field_list.push_back(new Item_return_int("Time",7, DRIZZLE_TYPE_LONG));
753
 
  field_list.push_back(field=new Item_empty_string("State",30));
754
 
  field->maybe_null= true;
755
 
  field_list.push_back(field=new Item_empty_string("Info", PROCESS_LIST_WIDTH));
756
 
  field->maybe_null= true;
757
 
  if (session->client->sendFields(&field_list))
758
 
    return;
759
 
 
760
 
  pthread_mutex_lock(&LOCK_thread_count); // For unlink from list
761
 
  if (!session->killed)
762
 
  {
763
 
    Session *tmp;
764
 
    for(vector<Session*>::iterator it= getSessionList().begin(); it != getSessionList().end(); ++it)
765
 
    {
766
 
      tmp= *it;
767
 
      const SecurityContext *tmp_sctx= &tmp->getSecurityContext();
768
 
      internal::st_my_thread_var *mysys_var;
769
 
      if (tmp->client->isConnected() && (not user || (not tmp_sctx->getUser().compare(user))))
770
 
      {
771
 
 
772
 
        if ((mysys_var= tmp->mysys_var))
773
 
          pthread_mutex_lock(&mysys_var->mutex);
774
 
 
775
 
        const string tmp_proc_info((tmp->killed == Session::KILL_CONNECTION) ? "Killed" : command_name[tmp->command].str);
776
 
 
777
 
        const string tmp_state_info(tmp->client->isWriting()
778
 
                                     ? "Writing to net"
779
 
                                     : tmp->client->isReading()
780
 
                                       ? (tmp->command == COM_SLEEP
781
 
                                            ? ""
782
 
                                            : "Reading from net")
783
 
                                       : tmp->get_proc_info()
784
 
                                         ? tmp->get_proc_info()
785
 
                                         : (tmp->mysys_var && tmp->mysys_var->current_cond)
786
 
                                           ? "Waiting on cond"
787
 
                                           : "");
788
 
        if (mysys_var)
789
 
          pthread_mutex_unlock(&mysys_var->mutex);
790
 
 
791
 
        const string tmp_query((tmp->process_list_info[0]) ? tmp->process_list_info : "");
792
 
        thread_infos.push_back(thread_info(tmp->thread_id,
793
 
                                           tmp->start_time,
794
 
                                           tmp->command,
795
 
                                           tmp_sctx->getUser().empty()
796
 
                                             ? string("unauthenticated user")
797
 
                                             : tmp_sctx->getUser(),
798
 
                                           tmp_sctx->getIp(),
799
 
                                           tmp->db,
800
 
                                           tmp_proc_info,
801
 
                                           tmp_state_info,
802
 
                                           tmp_query));
803
 
      }
804
 
    }
805
 
  }
806
 
  pthread_mutex_unlock(&LOCK_thread_count);
807
 
  time_t now= time(NULL);
808
 
  for(vector<thread_info>::iterator iter= thread_infos.begin();
809
 
      iter != thread_infos.end();
810
 
      ++iter)
811
 
  {
812
 
    session->client->store((uint64_t) (*iter).thread_id);
813
 
    session->client->store((*iter).user);
814
 
    session->client->store((*iter).host);
815
 
    session->client->store((*iter).db);
816
 
    session->client->store((*iter).proc_info);
817
 
 
818
 
    if ((*iter).start_time)
819
 
      session->client->store((uint32_t) (now - (*iter).start_time));
820
 
    else
821
 
      session->client->store();
822
 
 
823
 
    session->client->store((*iter).state_info);
824
 
    session->client->store((*iter).query);
825
 
 
826
 
    if (session->client->flush())
827
 
      break;
828
 
  }
829
 
  session->my_eof();
830
 
 
831
 
  return;
832
 
}
833
 
 
834
740
/*****************************************************************************
835
741
  Status functions
836
742
*****************************************************************************/
837
743
 
838
 
static vector<SHOW_VAR *> all_status_vars;
 
744
static vector<drizzle_show_var *> all_status_vars;
839
745
static bool status_vars_inited= 0;
840
746
static int show_var_cmp(const void *var1, const void *var2)
841
747
{
842
 
  return strcmp(((SHOW_VAR*)var1)->name, ((SHOW_VAR*)var2)->name);
 
748
  return strcmp(((drizzle_show_var*)var1)->name, ((drizzle_show_var*)var2)->name);
843
749
}
844
750
 
845
751
class show_var_cmp_functor
846
752
{
847
753
  public:
848
754
  show_var_cmp_functor() { }
849
 
  inline bool operator()(const SHOW_VAR *var1, const SHOW_VAR *var2) const
 
755
  inline bool operator()(const drizzle_show_var *var1, const drizzle_show_var *var2) const
850
756
  {
851
757
    int val= strcmp(var1->name, var2->name);
852
758
    return (val < 0);
857
763
{
858
764
  public:
859
765
  show_var_remove_if() { }
860
 
  inline bool operator()(const SHOW_VAR *curr) const
 
766
  inline bool operator()(const drizzle_show_var *curr) const
861
767
  {
862
768
    return (curr->type == SHOW_UNDEF);
863
769
  }
864
770
};
865
771
 
866
 
SHOW_VAR *getFrontOfStatusVars()
 
772
drizzle_show_var *getFrontOfStatusVars()
867
773
{
868
774
  return all_status_vars.front();
869
775
}
870
776
 
871
 
SHOW_VAR *getCommandStatusVars()
 
777
drizzle_show_var *getCommandStatusVars()
872
778
{
873
 
  SHOW_VAR *tmp= all_status_vars.front();
 
779
  drizzle_show_var *tmp= all_status_vars.front();
874
780
 
875
781
  for (; tmp->name; tmp++)
876
782
  {
877
783
    if (tmp->type == SHOW_ARRAY)
878
 
      return (SHOW_VAR *) tmp->value;
 
784
      return (drizzle_show_var *) tmp->value;
879
785
  }
880
786
 
881
787
  return NULL;
882
788
}
883
789
 
884
790
/*
885
 
  Adds an array of SHOW_VAR entries to the output of SHOW STATUS
 
791
  Adds an array of drizzle_show_var entries to the output of SHOW STATUS
886
792
 
887
793
  SYNOPSIS
888
 
    add_status_vars(SHOW_VAR *list)
889
 
    list - an array of SHOW_VAR entries to add to all_status_vars
 
794
    add_status_vars(drizzle_show_var *list)
 
795
    list - an array of drizzle_show_var entries to add to all_status_vars
890
796
           the last entry must be {0,0,SHOW_UNDEF}
891
797
 
892
798
  NOTE
898
804
    init_status_vars(), it assumes "startup mode" - neither concurrent access
899
805
    to the array nor SHOW STATUS are possible (thus it skips locks and qsort)
900
806
*/
901
 
int add_status_vars(SHOW_VAR *list)
 
807
int add_status_vars(drizzle_show_var *list)
902
808
{
903
809
  int res= 0;
904
810
  if (status_vars_inited)
930
836
 
931
837
void reset_status_vars()
932
838
{
933
 
  vector<SHOW_VAR *>::iterator p= all_status_vars.begin();
 
839
  vector<drizzle_show_var *>::iterator p= all_status_vars.begin();
934
840
  while (p != all_status_vars.end())
935
841
  {
936
842
    /* Note that SHOW_LONG_NOFLUSH variables are not reset */
955
861
}
956
862
 
957
863
/*
958
 
  Removes an array of SHOW_VAR entries from the output of SHOW STATUS
 
864
  Removes an array of drizzle_show_var entries from the output of SHOW STATUS
959
865
 
960
866
  SYNOPSIS
961
 
    remove_status_vars(SHOW_VAR *list)
962
 
    list - an array of SHOW_VAR entries to remove to all_status_vars
 
867
    remove_status_vars(drizzle_show_var *list)
 
868
    list - an array of drizzle_show_var entries to remove to all_status_vars
963
869
           the last entry must be {0,0,SHOW_UNDEF}
964
870
 
965
871
  NOTE
968
874
    initialization in the mysqld startup.
969
875
*/
970
876
 
971
 
void remove_status_vars(SHOW_VAR *list)
 
877
void remove_status_vars(drizzle_show_var *list)
972
878
{
973
879
  if (status_vars_inited)
974
880
  {
975
881
    pthread_mutex_lock(&LOCK_status);
976
 
    SHOW_VAR *all= all_status_vars.front();
 
882
    drizzle_show_var *all= all_status_vars.front();
977
883
    int a= 0, b= all_status_vars.size(), c= (a+b)/2;
978
884
 
979
885
    for (; list->name; list++)
1000
906
  }
1001
907
  else
1002
908
  {
1003
 
    SHOW_VAR *all= all_status_vars.front();
 
909
    drizzle_show_var *all= all_status_vars.front();
1004
910
    uint32_t i;
1005
911
    for (; list->name; list++)
1006
912
    {
1021
927
 
1022
928
/* collect status for all running threads */
1023
929
 
1024
 
void calc_sum_of_all_status(STATUS_VAR *to)
 
930
void calc_sum_of_all_status(system_status_var *to)
1025
931
{
1026
932
  /* Ensure that thread id not killed during loop */
1027
933
  pthread_mutex_lock(&LOCK_thread_count); // For unlink from list