Drizzled Public API Documentation

status_vars.cc

00001 /*
00002  * Copyright (C) 2010 Joseph Daly <skinny.moey@gmail.com>
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions are met:
00007  *
00008  *   * Redistributions of source code must retain the above copyright notice,
00009  *     this list of conditions and the following disclaimer.
00010  *   * Redistributions in binary form must reproduce the above copyright notice,
00011  *     this list of conditions and the following disclaimer in the documentation
00012  *     and/or other materials provided with the distribution.
00013  *   * Neither the name of Joseph Daly nor the names of its contributors
00014  *     may be used to endorse or promote products derived from this software
00015  *     without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00018  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
00021  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00022  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00023  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00024  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00025  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00026  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
00027  * THE POSSIBILITY OF SUCH DAMAGE.
00028  */
00029 
00030 #include <config.h>
00031 #include <drizzled/plugin.h>
00032 #include <drizzled/statistics_variables.h>
00033 #include <drizzled/session.h>
00034 #include <drizzled/drizzled.h>
00035 #include "status_vars.h"
00036 
00037 using namespace drizzled;
00038 
00039 StatusVars::StatusVars()
00040 {
00041   status_var_counters= (system_status_var*) malloc(sizeof(system_status_var));
00042   memset(status_var_counters, 0, sizeof(system_status_var));
00043   sent_row_count= 0;
00044 }
00045 
00046 StatusVars::StatusVars(const StatusVars &status_vars)
00047 {
00048   status_var_counters= (system_status_var*) malloc(sizeof(system_status_var));
00049   memset(status_var_counters, 0, sizeof(system_status_var));
00050   copySystemStatusVar(status_var_counters, status_vars.status_var_counters); 
00051   sent_row_count= 0;
00052 }
00053 
00054 StatusVars::~StatusVars()
00055 {
00056   free(status_var_counters); 
00057 }
00058 
00059 void StatusVars::copySystemStatusVar(system_status_var *to_var, 
00060                                      system_status_var *from_var)
00061 {
00062   uint64_t *end= (uint64_t*) ((unsigned char*) to_var + offsetof(system_status_var,
00063                  last_system_status_var) + sizeof(uint64_t));
00064 
00065   uint64_t *to= (uint64_t*) to_var;
00066   uint64_t *from= (uint64_t*) from_var;
00067 
00068   while (to != end)
00069   {
00070     *(to++)= *(from++);
00071   }
00072   to_var->last_query_cost= from_var->last_query_cost;
00073 }
00074 
00075 void StatusVars::merge(StatusVars *status_vars)
00076 {
00077   system_status_var* from_var= status_vars->getStatusVarCounters(); 
00078 
00079   uint64_t *end= (uint64_t*) ((unsigned char*) status_var_counters + offsetof(system_status_var,
00080                  last_system_status_var) + sizeof(uint64_t));
00081 
00082   uint64_t *to= (uint64_t*) status_var_counters;
00083   uint64_t *from= (uint64_t*) from_var;
00084 
00085   while (to != end)
00086   {
00087     *(to++)+= *(from++);
00088   }
00089 
00090   sent_row_count+= status_vars->sent_row_count;
00091 }
00092 
00093 void StatusVars::reset()
00094 {
00095   memset(status_var_counters, 0, sizeof(system_status_var));
00096   sent_row_count= 0;
00097 }
00098 
00099 void StatusVars::logStatusVar(Session *session)
00100 {
00101   copySystemStatusVar(status_var_counters, &session->status_var);
00102   sent_row_count+= session->sent_row_count;
00103 }
00104 
00105 bool StatusVars::hasBeenFlushed(Session *session)
00106 {
00107   system_status_var *current_status_var= &session->status_var;
00108 
00109   /* check bytes received if its lower then a flush has occurred */
00110   uint64_t current_bytes_received= current_status_var->bytes_received;
00111   uint64_t my_bytes_received= status_var_counters->bytes_received;
00112   if (current_bytes_received < my_bytes_received)
00113   {
00114     return true;
00115   }
00116   else 
00117   {
00118     return false;
00119   }
00120 }
00121 
00122 void StatusVars::copyGlobalVariables(StatusVars *global_status_vars)
00123 {
00124   system_status_var* from_var= global_status_vars->getStatusVarCounters();
00125   status_var_counters->aborted_connects= from_var->aborted_connects;  
00126   status_var_counters->aborted_threads= from_var->aborted_threads;
00127   status_var_counters->connection_time= from_var->connection_time;
00128 }