~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/logging_stats/cumulative_stats.cc

  • Committer: Monty Taylor
  • Date: 2010-06-02 22:35:45 UTC
  • mto: This revision was merged to the branch mainline in revision 1586.
  • Revision ID: mordred@inaugust.com-20100602223545-q8ekf9b40a85nwuf
Rearragned unittests into a single exe because of how we need to link it
(thanks lifeless)
Link with server symbols without needing to build a library.
Added an additional atomics test which tests whatever version of the atomics
lib the running platform would actually use.

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
#include "cumulative_stats.h"
32
32
 
33
33
using namespace std;
34
 
using namespace drizzled;
35
34
 
36
35
CumulativeStats::CumulativeStats(uint32_t in_cumulative_stats_by_user_max) 
37
36
    :
50
49
  last_valid_index= INVALID_INDEX;
51
50
  isOpenUserSlots= true;
52
51
  global_stats= new GlobalStats();
53
 
  global_status_vars= new StatusVars();
54
 
 
55
 
  /* calculate the approximate memory allocation for the cumulative statistics */
56
 
  size_t statusVarsSize= sizeof(StatusVars) + sizeof(system_status_var);
57
 
  size_t userCommandsSize= sizeof(UserCommands) + sizeof(uint64_t) * SQLCOM_END;
58
 
 
59
 
  cumulative_size_bytes= (statusVarsSize + userCommandsSize) * cumulative_stats_by_user_max; 
60
52
}
61
53
 
62
54
CumulativeStats::~CumulativeStats()
69
61
  cumulative_stats_by_user_vector->clear();
70
62
  delete cumulative_stats_by_user_vector;
71
63
  delete global_stats;
72
 
  delete global_status_vars;
73
64
}
74
65
 
75
 
void CumulativeStats::logUserStats(ScoreboardSlot *scoreboard_slot, bool reserveSlot)
 
66
void CumulativeStats::logUserStats(ScoreboardSlot *scoreboard_slot)
76
67
{
77
68
  vector<ScoreboardSlot *>::iterator cumulative_it= cumulative_stats_by_user_vector->begin();
 
69
  bool found= false;
78
70
 
79
71
  /* Search if this is a pre-existing user */
80
72
 
91
83
    string user= cumulative_scoreboard_slot->getUser();
92
84
    if (user.compare(scoreboard_slot->getUser()) == 0)
93
85
    {
94
 
      reserveSlot= false;
 
86
      found= true;
95
87
      cumulative_scoreboard_slot->merge(scoreboard_slot);
96
88
      break;
97
89
    }
98
90
    ++cumulative_it;
99
91
  }
100
 
  
101
 
  if (reserveSlot)
 
92
 
 
93
  if (! found)
102
94
  {
103
95
    /* the user was not found */
104
96
    /* its possible multiple simultaneous connections with the same user
130
122
  global_stats->updateUserCommands(scoreboard_slot); 
131
123
}
132
124
 
133
 
void CumulativeStats::logGlobalStatusVars(ScoreboardSlot* scoreboard_slot)
134
 
{
135
 
  global_status_vars->merge(scoreboard_slot->getStatusVars());
136
 
}
137
 
 
138
 
int32_t CumulativeStats::getCumulativeStatsLastValidIndex()
 
125
int32_t  CumulativeStats::getCumulativeStatsLastValidIndex()
139
126
{
140
127
  if (last_valid_index < cumulative_stats_by_user_max)
141
128
  {
146
133
    return cumulative_stats_by_user_max;
147
134
  }
148
135
}
149
 
 
150
 
void CumulativeStats::sumCurrentScoreboard(Scoreboard *scoreboard,
151
 
                                           StatusVars *current_status_vars,
152
 
                                           UserCommands *current_user_commands)
153
 
{
154
 
  /* the vector of vectors */
155
 
  vector<vector<ScoreboardSlot* >* > *vector_of_scoreboard_vectors= 
156
 
    scoreboard->getVectorOfScoreboardVectors();
157
 
 
158
 
  /* iterate through each vector from above and sum each ScoreboardSlot */
159
 
 
160
 
  vector<vector<ScoreboardSlot* >* >::iterator v_of_scoreboard_v_begin_it= vector_of_scoreboard_vectors->begin(); 
161
 
 
162
 
  vector<vector<ScoreboardSlot* >* >::iterator v_of_scoreboard_v_end_it= vector_of_scoreboard_vectors->end(); 
163
 
 
164
 
  for (; v_of_scoreboard_v_begin_it != v_of_scoreboard_v_end_it; ++v_of_scoreboard_v_begin_it)
165
 
  {
166
 
    vector<ScoreboardSlot* > *scoreboard_vector= *v_of_scoreboard_v_begin_it;
167
 
    
168
 
    vector<ScoreboardSlot* >::iterator scoreboard_vector_it= scoreboard_vector->begin();
169
 
    vector<ScoreboardSlot* >::iterator scoreboard_vector_end= scoreboard_vector->end();
170
 
    for (; scoreboard_vector_it != scoreboard_vector_end; ++scoreboard_vector_it)
171
 
    {
172
 
      ScoreboardSlot *scoreboard_slot= *scoreboard_vector_it;
173
 
      if (scoreboard_slot->isInUse())
174
 
      {
175
 
        if (current_status_vars)
176
 
        {
177
 
          current_status_vars->merge(scoreboard_slot->getStatusVars());
178
 
        }
179
 
 
180
 
        if (current_user_commands)
181
 
        {
182
 
          current_user_commands->merge(scoreboard_slot->getUserCommands());
183
 
        }
184
 
      }
185
 
    }
186
 
  }
187
 
}