640
/*****************************************************************************
642
*****************************************************************************/
644
static vector<drizzle_show_var *> all_status_vars;
645
static bool status_vars_inited= 0;
646
static int show_var_cmp(const void *var1, const void *var2)
648
return strcmp(((drizzle_show_var*)var1)->name, ((drizzle_show_var*)var2)->name);
651
class show_var_cmp_functor
654
show_var_cmp_functor() { }
655
inline bool operator()(const drizzle_show_var *var1, const drizzle_show_var *var2) const
657
int val= strcmp(var1->name, var2->name);
662
class show_var_remove_if
665
show_var_remove_if() { }
666
inline bool operator()(const drizzle_show_var *curr) const
668
return (curr->type == SHOW_UNDEF);
672
drizzle_show_var *getFrontOfStatusVars()
674
return all_status_vars.front();
678
Adds an array of drizzle_show_var entries to the output of SHOW STATUS
681
add_status_vars(drizzle_show_var *list)
682
list - an array of drizzle_show_var entries to add to all_status_vars
683
the last entry must be {0,0,SHOW_UNDEF}
686
The handling of all_status_vars[] is completely internal, it's allocated
687
automatically when something is added to it, and deleted completely when
688
the last entry is removed.
690
As a special optimization, if add_status_vars() is called before
691
init_status_vars(), it assumes "startup mode" - neither concurrent access
692
to the array nor SHOW STATUS are possible (thus it skips locks and qsort)
694
int add_status_vars(drizzle_show_var *list)
697
if (status_vars_inited)
698
pthread_mutex_lock(&LOCK_status);
700
all_status_vars.insert(all_status_vars.begin(), list++);
701
if (status_vars_inited)
702
sort(all_status_vars.begin(), all_status_vars.end(),
703
show_var_cmp_functor());
704
if (status_vars_inited)
705
pthread_mutex_unlock(&LOCK_status);
710
Make all_status_vars[] usable for SHOW STATUS
713
See add_status_vars(). Before init_status_vars() call, add_status_vars()
714
works in a special fast "startup" mode. Thus init_status_vars()
715
should be called as late as possible but before enabling multi-threading.
717
void init_status_vars()
719
status_vars_inited= 1;
720
sort(all_status_vars.begin(), all_status_vars.end(),
721
show_var_cmp_functor());
724
void reset_status_vars()
726
vector<drizzle_show_var *>::iterator p;
728
p= all_status_vars.begin();
729
while (p != all_status_vars.end())
731
/* Note that SHOW_LONG_NOFLUSH variables are not reset */
732
if ((*p)->type == SHOW_LONG)
739
catch-all cleanup function, cleans up everything no matter what
742
This function is not strictly required if all add_to_status/
743
remove_status_vars are properly paired, but it's a safety measure that
744
deletes everything from the all_status_vars vector even if some
745
remove_status_vars were forgotten
747
void free_status_vars()
749
all_status_vars.clear();
753
Removes an array of drizzle_show_var entries from the output of SHOW STATUS
756
remove_status_vars(drizzle_show_var *list)
757
list - an array of drizzle_show_var entries to remove to all_status_vars
758
the last entry must be {0,0,SHOW_UNDEF}
761
there's lots of room for optimizing this, especially in non-sorted mode,
762
but nobody cares - it may be called only in case of failed plugin
763
initialization in the mysqld startup.
766
void remove_status_vars(drizzle_show_var *list)
768
if (status_vars_inited)
770
pthread_mutex_lock(&LOCK_status);
771
drizzle_show_var *all= all_status_vars.front();
772
int a= 0, b= all_status_vars.size(), c= (a+b)/2;
774
for (; list->name; list++)
777
for (a= 0, b= all_status_vars.size(); b-a > 1; c= (a+b)/2)
779
res= show_var_cmp(list, all+c);
788
all[c].type= SHOW_UNDEF;
790
/* removes all the SHOW_UNDEF elements from the vector */
791
all_status_vars.erase(std::remove_if(all_status_vars.begin(),
792
all_status_vars.end(),show_var_remove_if()),
793
all_status_vars.end());
794
pthread_mutex_unlock(&LOCK_status);
798
drizzle_show_var *all= all_status_vars.front();
800
for (; list->name; list++)
802
for (i= 0; i < all_status_vars.size(); i++)
804
if (show_var_cmp(list, all+i))
806
all[i].type= SHOW_UNDEF;
810
/* removes all the SHOW_UNDEF elements from the vector */
811
all_status_vars.erase(std::remove_if(all_status_vars.begin(),
812
all_status_vars.end(),show_var_remove_if()),
813
all_status_vars.end());
817
/* collect status for all running threads */
819
void calc_sum_of_all_status(system_status_var *to)
821
/* Ensure that thread id not killed during loop */
822
pthread_mutex_lock(&LOCK_thread_count); // For unlink from list
824
/* Get global values as base */
825
*to= global_status_var;
827
/* Add to this status from existing threads */
828
for(SessionList::iterator it= getSessionList().begin(); it != getSessionList().end(); ++it )
830
add_to_status(to, &((*it)->status_var));
833
pthread_mutex_unlock(&LOCK_thread_count);
837
640
} /* namespace drizzled */