2012-06-29 13:36:01 +02:00
|
|
|
/* Copyright (c) 2007, 2012, Oracle and/or its affiliates. All rights reserved.
|
2007-01-03 23:15:10 +01:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
2007-02-26 19:11:36 +01:00
|
|
|
the Free Software Foundation; version 2 of the License.
|
2007-01-03 23:15:10 +01:00
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
2011-06-30 17:46:53 +02:00
|
|
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
|
2007-01-03 23:15:10 +01:00
|
|
|
|
2007-02-22 16:03:08 +01:00
|
|
|
|
2007-11-09 20:45:44 +01:00
|
|
|
/**
|
|
|
|
@file
|
|
|
|
|
|
|
|
Implement query profiling as as list of metaphorical fences, with one fence
|
|
|
|
per query, and each fencepost a change of thd->proc_info state (with a
|
|
|
|
snapshot of system statistics). When asked, we can then iterate over the
|
|
|
|
fenceposts and calculate the distance between them, to inform the user what
|
|
|
|
happened during a particular query or thd->proc_info state.
|
|
|
|
|
|
|
|
User variables that inform profiling behavior:
|
|
|
|
- "profiling", boolean, session only, "Are queries profiled?"
|
|
|
|
- "profiling_history_size", integer, session + global, "Num queries stored?"
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2010-03-31 16:05:33 +02:00
|
|
|
#include "sql_priv.h"
|
|
|
|
#include "unireg.h" // REQUIRED: for other includes
|
|
|
|
#include "sql_profile.h"
|
2007-02-22 16:03:08 +01:00
|
|
|
#include "my_sys.h"
|
2010-03-31 16:05:33 +02:00
|
|
|
#include "sql_show.h" // schema_table_store_record
|
|
|
|
#include "sql_class.h" // THD
|
2007-02-22 16:03:08 +01:00
|
|
|
|
2007-03-02 15:14:33 +01:00
|
|
|
#define TIME_FLOAT_DIGITS 9
|
2007-11-13 15:46:17 +01:00
|
|
|
/** two vals encoded: (dec*100)+len */
|
|
|
|
#define TIME_I_S_DECIMAL_SIZE (TIME_FLOAT_DIGITS*100)+(TIME_FLOAT_DIGITS-3)
|
|
|
|
|
2007-02-22 16:03:08 +01:00
|
|
|
#define MAX_QUERY_LENGTH 300
|
2012-10-12 19:38:45 +02:00
|
|
|
#define MAX_QUERY_HISTORY 101
|
2007-02-22 16:03:08 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
Connects Information_Schema and Profiling.
|
|
|
|
*/
|
2007-11-09 20:45:44 +01:00
|
|
|
int fill_query_profile_statistics_info(THD *thd, TABLE_LIST *tables,
|
2007-02-22 16:03:08 +01:00
|
|
|
Item *cond)
|
|
|
|
{
|
2009-10-09 15:59:25 +02:00
|
|
|
#if defined(ENABLED_PROFILING)
|
2007-02-22 16:03:08 +01:00
|
|
|
return(thd->profiling.fill_statistics_info(thd, tables, cond));
|
|
|
|
#else
|
2007-11-02 16:41:58 +01:00
|
|
|
my_error(ER_FEATURE_DISABLED, MYF(0), "SHOW PROFILE", "enable-profiling");
|
2007-02-22 16:03:08 +01:00
|
|
|
return(1);
|
|
|
|
#endif
|
|
|
|
}
|
2007-01-03 23:15:10 +01:00
|
|
|
|
2007-02-22 16:03:08 +01:00
|
|
|
ST_FIELD_INFO query_profile_statistics_info[]=
|
|
|
|
{
|
2007-10-31 21:39:59 +01:00
|
|
|
/* name, length, type, value, maybe_null, old_name, open_method */
|
2007-11-02 16:41:58 +01:00
|
|
|
{"QUERY_ID", 20, MYSQL_TYPE_LONG, 0, false, "Query_id", SKIP_OPEN_TABLE},
|
|
|
|
{"SEQ", 20, MYSQL_TYPE_LONG, 0, false, "Seq", SKIP_OPEN_TABLE},
|
|
|
|
{"STATE", 30, MYSQL_TYPE_STRING, 0, false, "Status", SKIP_OPEN_TABLE},
|
2007-11-09 20:45:44 +01:00
|
|
|
{"DURATION", TIME_I_S_DECIMAL_SIZE, MYSQL_TYPE_DECIMAL, 0, false, "Duration", SKIP_OPEN_TABLE},
|
|
|
|
{"CPU_USER", TIME_I_S_DECIMAL_SIZE, MYSQL_TYPE_DECIMAL, 0, true, "CPU_user", SKIP_OPEN_TABLE},
|
|
|
|
{"CPU_SYSTEM", TIME_I_S_DECIMAL_SIZE, MYSQL_TYPE_DECIMAL, 0, true, "CPU_system", SKIP_OPEN_TABLE},
|
2007-11-02 16:41:58 +01:00
|
|
|
{"CONTEXT_VOLUNTARY", 20, MYSQL_TYPE_LONG, 0, true, "Context_voluntary", SKIP_OPEN_TABLE},
|
|
|
|
{"CONTEXT_INVOLUNTARY", 20, MYSQL_TYPE_LONG, 0, true, "Context_involuntary", SKIP_OPEN_TABLE},
|
|
|
|
{"BLOCK_OPS_IN", 20, MYSQL_TYPE_LONG, 0, true, "Block_ops_in", SKIP_OPEN_TABLE},
|
|
|
|
{"BLOCK_OPS_OUT", 20, MYSQL_TYPE_LONG, 0, true, "Block_ops_out", SKIP_OPEN_TABLE},
|
|
|
|
{"MESSAGES_SENT", 20, MYSQL_TYPE_LONG, 0, true, "Messages_sent", SKIP_OPEN_TABLE},
|
|
|
|
{"MESSAGES_RECEIVED", 20, MYSQL_TYPE_LONG, 0, true, "Messages_received", SKIP_OPEN_TABLE},
|
|
|
|
{"PAGE_FAULTS_MAJOR", 20, MYSQL_TYPE_LONG, 0, true, "Page_faults_major", SKIP_OPEN_TABLE},
|
|
|
|
{"PAGE_FAULTS_MINOR", 20, MYSQL_TYPE_LONG, 0, true, "Page_faults_minor", SKIP_OPEN_TABLE},
|
|
|
|
{"SWAPS", 20, MYSQL_TYPE_LONG, 0, true, "Swaps", SKIP_OPEN_TABLE},
|
|
|
|
{"SOURCE_FUNCTION", 30, MYSQL_TYPE_STRING, 0, true, "Source_function", SKIP_OPEN_TABLE},
|
|
|
|
{"SOURCE_FILE", 20, MYSQL_TYPE_STRING, 0, true, "Source_file", SKIP_OPEN_TABLE},
|
|
|
|
{"SOURCE_LINE", 20, MYSQL_TYPE_LONG, 0, true, "Source_line", SKIP_OPEN_TABLE},
|
2007-11-09 20:45:44 +01:00
|
|
|
{NULL, 0, MYSQL_TYPE_STRING, 0, true, NULL, 0}
|
2007-02-22 16:03:08 +01:00
|
|
|
};
|
|
|
|
|
2007-07-02 13:27:39 +02:00
|
|
|
|
|
|
|
int make_profile_table_for_show(THD *thd, ST_SCHEMA_TABLE *schema_table)
|
|
|
|
{
|
2012-06-29 13:25:57 +02:00
|
|
|
uint profile_options = thd->lex->profile_options;
|
|
|
|
uint fields_include_condition_truth_values[]= {
|
2007-07-02 13:27:39 +02:00
|
|
|
FALSE, /* Query_id */
|
|
|
|
FALSE, /* Seq */
|
|
|
|
TRUE, /* Status */
|
|
|
|
TRUE, /* Duration */
|
|
|
|
profile_options & PROFILE_CPU, /* CPU_user */
|
|
|
|
profile_options & PROFILE_CPU, /* CPU_system */
|
|
|
|
profile_options & PROFILE_CONTEXT, /* Context_voluntary */
|
|
|
|
profile_options & PROFILE_CONTEXT, /* Context_involuntary */
|
|
|
|
profile_options & PROFILE_BLOCK_IO, /* Block_ops_in */
|
|
|
|
profile_options & PROFILE_BLOCK_IO, /* Block_ops_out */
|
|
|
|
profile_options & PROFILE_IPC, /* Messages_sent */
|
|
|
|
profile_options & PROFILE_IPC, /* Messages_received */
|
|
|
|
profile_options & PROFILE_PAGE_FAULTS, /* Page_faults_major */
|
|
|
|
profile_options & PROFILE_PAGE_FAULTS, /* Page_faults_minor */
|
|
|
|
profile_options & PROFILE_SWAPS, /* Swaps */
|
|
|
|
profile_options & PROFILE_SOURCE, /* Source_function */
|
|
|
|
profile_options & PROFILE_SOURCE, /* Source_file */
|
|
|
|
profile_options & PROFILE_SOURCE, /* Source_line */
|
|
|
|
};
|
|
|
|
|
|
|
|
ST_FIELD_INFO *field_info;
|
|
|
|
Name_resolution_context *context= &thd->lex->select_lex.context;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i= 0; schema_table->fields_info[i].field_name != NULL; i++)
|
|
|
|
{
|
|
|
|
if (! fields_include_condition_truth_values[i])
|
|
|
|
continue;
|
|
|
|
|
|
|
|
field_info= &schema_table->fields_info[i];
|
|
|
|
Item_field *field= new Item_field(context,
|
|
|
|
NullS, NullS, field_info->field_name);
|
|
|
|
if (field)
|
|
|
|
{
|
|
|
|
field->set_name(field_info->old_name,
|
2009-02-13 17:41:47 +01:00
|
|
|
(uint) strlen(field_info->old_name),
|
2007-07-02 13:27:39 +02:00
|
|
|
system_charset_info);
|
|
|
|
if (add_item_to_list(thd, field))
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-10-09 15:59:25 +02:00
|
|
|
#if defined(ENABLED_PROFILING)
|
2007-02-22 16:03:08 +01:00
|
|
|
|
|
|
|
#define RUSAGE_USEC(tv) ((tv).tv_sec*1000*1000 + (tv).tv_usec)
|
2007-01-03 23:15:10 +01:00
|
|
|
#define RUSAGE_DIFF_USEC(tv1, tv2) (RUSAGE_USEC((tv1))-RUSAGE_USEC((tv2)))
|
|
|
|
|
2010-02-05 13:57:15 +01:00
|
|
|
#ifdef _WIN32
|
|
|
|
static ULONGLONG FileTimeToQuadWord(FILETIME *ft)
|
|
|
|
{
|
|
|
|
// Overlay FILETIME onto a ULONGLONG.
|
|
|
|
union {
|
|
|
|
ULONGLONG qwTime;
|
|
|
|
FILETIME ft;
|
|
|
|
} u;
|
|
|
|
|
|
|
|
u.ft = *ft;
|
|
|
|
return u.qwTime;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Get time difference between to FILETIME objects in seconds.
|
|
|
|
static double GetTimeDiffInSeconds(FILETIME *a, FILETIME *b)
|
|
|
|
{
|
|
|
|
return ((FileTimeToQuadWord(a) - FileTimeToQuadWord(b)) / 1e7);
|
|
|
|
}
|
|
|
|
#endif
|
2007-01-03 23:15:10 +01:00
|
|
|
|
2007-11-09 20:45:44 +01:00
|
|
|
PROF_MEASUREMENT::PROF_MEASUREMENT(QUERY_PROFILE *profile_arg, const char
|
|
|
|
*status_arg)
|
2007-02-22 16:03:08 +01:00
|
|
|
:profile(profile_arg)
|
2007-01-03 23:15:10 +01:00
|
|
|
{
|
|
|
|
collect();
|
2007-11-09 20:45:44 +01:00
|
|
|
set_label(status_arg, NULL, NULL, 0);
|
2007-01-03 23:15:10 +01:00
|
|
|
}
|
|
|
|
|
2007-11-09 20:45:44 +01:00
|
|
|
PROF_MEASUREMENT::PROF_MEASUREMENT(QUERY_PROFILE *profile_arg,
|
|
|
|
const char *status_arg,
|
|
|
|
const char *function_arg,
|
|
|
|
const char *file_arg,
|
|
|
|
unsigned int line_arg)
|
2007-01-03 23:15:10 +01:00
|
|
|
:profile(profile_arg)
|
|
|
|
{
|
|
|
|
collect();
|
2007-11-09 20:45:44 +01:00
|
|
|
set_label(status_arg, function_arg, file_arg, line_arg);
|
2007-01-03 23:15:10 +01:00
|
|
|
}
|
|
|
|
|
2007-11-09 20:45:44 +01:00
|
|
|
PROF_MEASUREMENT::~PROF_MEASUREMENT()
|
2007-01-03 23:15:10 +01:00
|
|
|
{
|
Bug#34043: Server loops excessively in _checkchunk() when safemalloc is enabled
Essentially, the problem is that safemalloc is excruciatingly
slow as it checks all allocated blocks for overrun at each
memory management primitive, yielding a almost exponential
slowdown for the memory management functions (malloc, realloc,
free). The overrun check basically consists of verifying some
bytes of a block for certain magic keys, which catches some
simple forms of overrun. Another minor problem is violation
of aliasing rules and that its own internal list of blocks
is prone to corruption.
Another issue with safemalloc is rather the maintenance cost
as the tool has a significant impact on the server code.
Given the magnitude of memory debuggers available nowadays,
especially those that are provided with the platform malloc
implementation, maintenance of a in-house and largely obsolete
memory debugger becomes a burden that is not worth the effort
due to its slowness and lack of support for detecting more
common forms of heap corruption.
Since there are third-party tools that can provide the same
functionality at a lower or comparable performance cost, the
solution is to simply remove safemalloc. Third-party tools
can provide the same functionality at a lower or comparable
performance cost.
The removal of safemalloc also allows a simplification of the
malloc wrappers, removing quite a bit of kludge: redefinition
of my_malloc, my_free and the removal of the unused second
argument of my_free. Since free() always check whether the
supplied pointer is null, redudant checks are also removed.
Also, this patch adds unit testing for my_malloc and moves
my_realloc implementation into the same file as the other
memory allocation primitives.
2010-07-08 23:20:08 +02:00
|
|
|
my_free(allocated_status_memory);
|
2007-02-22 16:03:08 +01:00
|
|
|
status= function= file= NULL;
|
2007-01-03 23:15:10 +01:00
|
|
|
}
|
2007-11-09 20:45:44 +01:00
|
|
|
|
|
|
|
void PROF_MEASUREMENT::set_label(const char *status_arg,
|
|
|
|
const char *function_arg,
|
|
|
|
const char *file_arg, unsigned int line_arg)
|
2007-01-03 23:15:10 +01:00
|
|
|
{
|
2007-02-22 16:03:08 +01:00
|
|
|
size_t sizes[3]; /* 3 == status+function+file */
|
|
|
|
char *cursor;
|
|
|
|
|
|
|
|
/*
|
|
|
|
Compute all the space we'll need to allocate one block for everything
|
|
|
|
we'll need, instead of N mallocs.
|
|
|
|
*/
|
2007-02-26 19:11:36 +01:00
|
|
|
sizes[0]= (status_arg == NULL) ? 0 : strlen(status_arg) + 1;
|
|
|
|
sizes[1]= (function_arg == NULL) ? 0 : strlen(function_arg) + 1;
|
|
|
|
sizes[2]= (file_arg == NULL) ? 0 : strlen(file_arg) + 1;
|
2007-11-09 20:45:44 +01:00
|
|
|
|
2007-02-22 16:03:08 +01:00
|
|
|
allocated_status_memory= (char *) my_malloc(sizes[0] + sizes[1] + sizes[2], MYF(0));
|
|
|
|
DBUG_ASSERT(allocated_status_memory != NULL);
|
|
|
|
|
|
|
|
cursor= allocated_status_memory;
|
|
|
|
|
|
|
|
if (status_arg != NULL)
|
|
|
|
{
|
|
|
|
strcpy(cursor, status_arg);
|
|
|
|
status= cursor;
|
|
|
|
cursor+= sizes[0];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
status= NULL;
|
|
|
|
|
|
|
|
if (function_arg != NULL)
|
|
|
|
{
|
|
|
|
strcpy(cursor, function_arg);
|
|
|
|
function= cursor;
|
|
|
|
cursor+= sizes[1];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
function= NULL;
|
|
|
|
|
|
|
|
if (file_arg != NULL)
|
|
|
|
{
|
|
|
|
strcpy(cursor, file_arg);
|
|
|
|
file= cursor;
|
|
|
|
cursor+= sizes[2];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
file= NULL;
|
|
|
|
|
|
|
|
line= line_arg;
|
2007-01-03 23:15:10 +01:00
|
|
|
}
|
|
|
|
|
2007-11-09 20:45:44 +01:00
|
|
|
/**
|
|
|
|
This updates the statistics for this moment of time. It captures the state
|
|
|
|
of the running system, so later we can compare points in time and infer what
|
|
|
|
happened in the mean time. It should only be called immediately upon
|
|
|
|
instantiation of this PROF_MEASUREMENT.
|
|
|
|
|
|
|
|
@todo Implement resource capture for OSes not like BSD.
|
|
|
|
*/
|
|
|
|
void PROF_MEASUREMENT::collect()
|
2007-01-03 23:15:10 +01:00
|
|
|
{
|
2007-02-22 16:03:08 +01:00
|
|
|
time_usecs= (double) my_getsystime() / 10.0; /* 1 sec was 1e7, now is 1e6 */
|
|
|
|
#ifdef HAVE_GETRUSAGE
|
2007-01-03 23:15:10 +01:00
|
|
|
getrusage(RUSAGE_SELF, &rusage);
|
2010-02-05 13:57:15 +01:00
|
|
|
#elif defined(_WIN32)
|
|
|
|
FILETIME ftDummy;
|
|
|
|
// NOTE: Get{Process|Thread}Times has a granularity of the clock interval,
|
|
|
|
// which is typically ~15ms. So intervals shorter than that will not be
|
|
|
|
// measurable by this function.
|
|
|
|
GetProcessTimes(GetCurrentProcess(), &ftDummy, &ftDummy, &ftKernel, &ftUser);
|
2007-02-22 16:03:08 +01:00
|
|
|
#endif
|
2007-01-03 23:15:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-09 20:45:44 +01:00
|
|
|
QUERY_PROFILE::QUERY_PROFILE(PROFILING *profiling_arg, const char *status_arg)
|
|
|
|
:profiling(profiling_arg), profiling_query_id(0), query_source(NULL)
|
2007-01-03 23:15:10 +01:00
|
|
|
{
|
2012-10-12 19:38:45 +02:00
|
|
|
m_seq_counter= 1;
|
|
|
|
PROF_MEASUREMENT *prof= new PROF_MEASUREMENT(this, status_arg);
|
|
|
|
prof->m_seq= m_seq_counter++;
|
|
|
|
m_start_time_usecs= prof->time_usecs;
|
|
|
|
m_end_time_usecs= m_start_time_usecs;
|
|
|
|
entries.push_back(prof);
|
2007-02-22 16:03:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
QUERY_PROFILE::~QUERY_PROFILE()
|
|
|
|
{
|
2007-04-03 23:59:52 +02:00
|
|
|
while (! entries.is_empty())
|
|
|
|
delete entries.pop();
|
2007-02-22 16:03:08 +01:00
|
|
|
|
Bug#34043: Server loops excessively in _checkchunk() when safemalloc is enabled
Essentially, the problem is that safemalloc is excruciatingly
slow as it checks all allocated blocks for overrun at each
memory management primitive, yielding a almost exponential
slowdown for the memory management functions (malloc, realloc,
free). The overrun check basically consists of verifying some
bytes of a block for certain magic keys, which catches some
simple forms of overrun. Another minor problem is violation
of aliasing rules and that its own internal list of blocks
is prone to corruption.
Another issue with safemalloc is rather the maintenance cost
as the tool has a significant impact on the server code.
Given the magnitude of memory debuggers available nowadays,
especially those that are provided with the platform malloc
implementation, maintenance of a in-house and largely obsolete
memory debugger becomes a burden that is not worth the effort
due to its slowness and lack of support for detecting more
common forms of heap corruption.
Since there are third-party tools that can provide the same
functionality at a lower or comparable performance cost, the
solution is to simply remove safemalloc. Third-party tools
can provide the same functionality at a lower or comparable
performance cost.
The removal of safemalloc also allows a simplification of the
malloc wrappers, removing quite a bit of kludge: redefinition
of my_malloc, my_free and the removal of the unused second
argument of my_free. Since free() always check whether the
supplied pointer is null, redudant checks are also removed.
Also, this patch adds unit testing for my_malloc and moves
my_realloc implementation into the same file as the other
memory allocation primitives.
2010-07-08 23:20:08 +02:00
|
|
|
my_free(query_source);
|
2007-01-03 23:15:10 +01:00
|
|
|
}
|
|
|
|
|
2007-11-09 20:45:44 +01:00
|
|
|
/**
|
|
|
|
@todo Provide a way to include the full text, as in SHOW PROCESSLIST.
|
|
|
|
*/
|
|
|
|
void QUERY_PROFILE::set_query_source(char *query_source_arg,
|
|
|
|
uint query_length_arg)
|
|
|
|
{
|
|
|
|
/* Truncate to avoid DoS attacks. */
|
|
|
|
uint length= min(MAX_QUERY_LENGTH, query_length_arg);
|
|
|
|
|
|
|
|
DBUG_ASSERT(query_source == NULL); /* we don't leak memory */
|
|
|
|
if (query_source_arg != NULL)
|
|
|
|
query_source= my_strndup(query_source_arg, length, MYF(0));
|
|
|
|
}
|
|
|
|
|
|
|
|
void QUERY_PROFILE::new_status(const char *status_arg,
|
|
|
|
const char *function_arg, const char *file_arg,
|
|
|
|
unsigned int line_arg)
|
2007-01-03 23:15:10 +01:00
|
|
|
{
|
2007-11-09 20:45:44 +01:00
|
|
|
PROF_MEASUREMENT *prof;
|
2007-02-22 16:03:08 +01:00
|
|
|
DBUG_ENTER("QUERY_PROFILE::status");
|
2007-01-03 23:15:10 +01:00
|
|
|
|
2007-11-09 20:45:44 +01:00
|
|
|
DBUG_ASSERT(status_arg != NULL);
|
2007-01-03 23:15:10 +01:00
|
|
|
|
2007-11-09 20:45:44 +01:00
|
|
|
if ((function_arg != NULL) && (file_arg != NULL))
|
2011-07-20 08:50:47 +02:00
|
|
|
prof= new PROF_MEASUREMENT(this, status_arg, function_arg, base_name(file_arg), line_arg);
|
2007-11-09 20:45:44 +01:00
|
|
|
else
|
|
|
|
prof= new PROF_MEASUREMENT(this, status_arg);
|
2007-01-03 23:15:10 +01:00
|
|
|
|
2012-10-12 19:38:45 +02:00
|
|
|
prof->m_seq= m_seq_counter++;
|
|
|
|
m_end_time_usecs= prof->time_usecs;
|
2007-11-09 20:45:44 +01:00
|
|
|
entries.push_back(prof);
|
2007-02-22 16:03:08 +01:00
|
|
|
|
2012-10-12 19:38:45 +02:00
|
|
|
/* Maintain the query history size. */
|
|
|
|
while (entries.elements > MAX_QUERY_HISTORY)
|
|
|
|
delete entries.pop();
|
|
|
|
|
2007-01-03 23:15:10 +01:00
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
}
|
|
|
|
|
2007-02-22 16:03:08 +01:00
|
|
|
|
2007-01-03 23:15:10 +01:00
|
|
|
|
|
|
|
PROFILING::PROFILING()
|
2007-11-09 20:45:44 +01:00
|
|
|
:profile_id_counter(1), current(NULL), last(NULL)
|
2007-01-03 23:15:10 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
PROFILING::~PROFILING()
|
|
|
|
{
|
2007-04-03 23:59:52 +02:00
|
|
|
while (! history.is_empty())
|
|
|
|
delete history.pop();
|
2007-02-22 16:03:08 +01:00
|
|
|
|
|
|
|
if (current != NULL)
|
|
|
|
delete current;
|
2007-01-03 23:15:10 +01:00
|
|
|
}
|
|
|
|
|
2007-11-09 20:45:44 +01:00
|
|
|
/**
|
|
|
|
A new state is given, and that signals the profiler to start a new
|
|
|
|
timed step for the current query's profile.
|
|
|
|
|
|
|
|
@param status_arg name of this step
|
|
|
|
@param function_arg calling function (usually supplied from compiler)
|
|
|
|
@param function_arg calling file (usually supplied from compiler)
|
|
|
|
@param function_arg calling line number (usually supplied from compiler)
|
|
|
|
*/
|
2007-02-22 16:03:08 +01:00
|
|
|
void PROFILING::status_change(const char *status_arg,
|
|
|
|
const char *function_arg,
|
|
|
|
const char *file_arg, unsigned int line_arg)
|
2007-01-03 23:15:10 +01:00
|
|
|
{
|
2007-02-22 16:03:08 +01:00
|
|
|
DBUG_ENTER("PROFILING::status_change");
|
|
|
|
|
2007-11-09 20:45:44 +01:00
|
|
|
if (status_arg == NULL) /* We don't know how to handle that */
|
|
|
|
DBUG_VOID_RETURN;
|
2007-01-03 23:15:10 +01:00
|
|
|
|
2007-11-09 20:45:44 +01:00
|
|
|
if (current == NULL) /* This profile was already discarded. */
|
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
|
|
|
|
if (unlikely(enabled))
|
|
|
|
current->new_status(status_arg, function_arg, file_arg, line_arg);
|
2007-02-22 16:03:08 +01:00
|
|
|
|
2007-01-03 23:15:10 +01:00
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
}
|
|
|
|
|
2007-11-09 20:45:44 +01:00
|
|
|
/**
|
|
|
|
Prepare to start processing a new query. It is an error to do this
|
|
|
|
if there's a query already in process; nesting is not supported.
|
|
|
|
|
|
|
|
@param initial_state (optional) name of period before first state change
|
|
|
|
*/
|
|
|
|
void PROFILING::start_new_query(const char *initial_state)
|
2007-01-03 23:15:10 +01:00
|
|
|
{
|
2007-11-09 20:45:44 +01:00
|
|
|
DBUG_ENTER("PROFILING::start_new_query");
|
2007-01-03 23:15:10 +01:00
|
|
|
|
2007-11-09 20:45:44 +01:00
|
|
|
/* This should never happen unless the server is radically altered. */
|
|
|
|
if (unlikely(current != NULL))
|
2007-02-22 16:03:08 +01:00
|
|
|
{
|
2007-11-09 20:45:44 +01:00
|
|
|
DBUG_PRINT("warning", ("profiling code was asked to start a new query "
|
|
|
|
"before the old query was finished. This is "
|
|
|
|
"probably a bug."));
|
|
|
|
finish_current_query();
|
2007-02-22 16:03:08 +01:00
|
|
|
}
|
2007-01-03 23:15:10 +01:00
|
|
|
|
2009-12-22 10:35:56 +01:00
|
|
|
enabled= ((thd->variables.option_bits & OPTION_PROFILING) != 0);
|
2007-11-09 20:45:44 +01:00
|
|
|
|
|
|
|
if (! enabled) DBUG_VOID_RETURN;
|
|
|
|
|
|
|
|
DBUG_ASSERT(current == NULL);
|
|
|
|
current= new QUERY_PROFILE(this, initial_state);
|
|
|
|
|
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Throw away the current profile, because it's useless or unwanted
|
|
|
|
or corrupted.
|
|
|
|
*/
|
|
|
|
void PROFILING::discard_current_query()
|
|
|
|
{
|
|
|
|
DBUG_ENTER("PROFILING::discard_current_profile");
|
|
|
|
|
|
|
|
delete current;
|
|
|
|
current= NULL;
|
2007-04-04 01:50:55 +02:00
|
|
|
|
2007-11-09 20:45:44 +01:00
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Try to save the current profile entry, clean up the data if it shouldn't be
|
|
|
|
saved, and maintain the profile history size. Naturally, this may not
|
|
|
|
succeed if the profile was previously discarded, and that's expected.
|
|
|
|
*/
|
|
|
|
void PROFILING::finish_current_query()
|
|
|
|
{
|
|
|
|
DBUG_ENTER("PROFILING::finish_current_profile");
|
2007-02-22 16:03:08 +01:00
|
|
|
if (current != NULL)
|
2007-01-03 23:15:10 +01:00
|
|
|
{
|
2007-11-09 20:45:44 +01:00
|
|
|
/* The last fence-post, so we can support the span before this. */
|
|
|
|
status_change("ending", NULL, NULL, 0);
|
|
|
|
|
|
|
|
if ((enabled) && /* ON at start? */
|
2009-12-22 10:35:56 +01:00
|
|
|
((thd->variables.option_bits & OPTION_PROFILING) != 0) && /* and ON at end? */
|
2007-11-10 02:29:02 +01:00
|
|
|
(current->query_source != NULL) &&
|
2007-11-09 20:45:44 +01:00
|
|
|
(! current->entries.is_empty()))
|
2007-02-22 16:03:08 +01:00
|
|
|
{
|
|
|
|
current->profiling_query_id= next_profile_id(); /* assign an id */
|
|
|
|
|
2007-01-03 23:15:10 +01:00
|
|
|
history.push_back(current);
|
2007-11-09 20:45:44 +01:00
|
|
|
last= current; /* never contains something that is not in the history. */
|
2007-01-03 23:15:10 +01:00
|
|
|
current= NULL;
|
2007-11-09 20:45:44 +01:00
|
|
|
}
|
2007-02-22 16:03:08 +01:00
|
|
|
else
|
|
|
|
{
|
2007-01-03 23:15:10 +01:00
|
|
|
delete current;
|
2007-02-22 16:03:08 +01:00
|
|
|
current= NULL;
|
2007-01-03 23:15:10 +01:00
|
|
|
}
|
|
|
|
}
|
2007-02-22 16:03:08 +01:00
|
|
|
|
2007-11-09 20:45:44 +01:00
|
|
|
/* Maintain the history size. */
|
2007-10-31 17:29:32 +01:00
|
|
|
while (history.elements > thd->variables.profiling_history_size)
|
|
|
|
delete history.pop();
|
|
|
|
|
2007-01-03 23:15:10 +01:00
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool PROFILING::show_profiles()
|
|
|
|
{
|
2007-02-22 16:03:08 +01:00
|
|
|
DBUG_ENTER("PROFILING::show_profiles");
|
|
|
|
QUERY_PROFILE *prof;
|
2007-01-03 23:15:10 +01:00
|
|
|
List<Item> field_list;
|
|
|
|
|
|
|
|
field_list.push_back(new Item_return_int("Query_ID", 10,
|
|
|
|
MYSQL_TYPE_LONG));
|
2007-02-22 16:03:08 +01:00
|
|
|
field_list.push_back(new Item_return_int("Duration", TIME_FLOAT_DIGITS-1,
|
|
|
|
MYSQL_TYPE_DOUBLE));
|
|
|
|
field_list.push_back(new Item_empty_string("Query", 40));
|
2007-11-09 20:45:44 +01:00
|
|
|
|
Backport of revno 2630.28.10, 2630.28.31, 2630.28.26, 2630.33.1,
2630.39.1, 2630.28.29, 2630.34.3, 2630.34.2, 2630.34.1, 2630.29.29,
2630.29.28, 2630.31.1, 2630.28.13, 2630.28.10, 2617.23.14 and
some other minor revisions.
This patch implements:
WL#4264 "Backup: Stabilize Service Interface" -- all the
server prerequisites except si_objects.{h,cc} themselves (they can
be just copied over, when needed).
WL#4435: Support OUT-parameters in prepared statements.
(and all issues in the initial patches for these two
tasks, that were discovered in pushbuild and during testing).
Bug#39519: mysql_stmt_close() should flush all data
associated with the statement.
After execution of a prepared statement, send OUT parameters of the invoked
stored procedure, if any, to the client.
When using the binary protocol, send the parameters in an additional result
set over the wire. When using the text protocol, assign out parameters to
the user variables from the CALL(@var1, @var2, ...) specification.
The following refactoring has been made:
- Protocol::send_fields() was renamed to Protocol::send_result_set_metadata();
- A new Protocol::send_result_set_row() was introduced to incapsulate
common functionality for sending row data.
- Signature of Protocol::prepare_for_send() was changed: this operation
does not need a list of items, the number of items is fully sufficient.
The following backward incompatible changes have been made:
- CLIENT_MULTI_RESULTS is now enabled by default in the client;
- CLIENT_PS_MULTI_RESUTLS is now enabled by default in the client.
2009-10-21 22:02:06 +02:00
|
|
|
if (thd->protocol->send_result_set_metadata(&field_list,
|
2007-01-03 23:15:10 +01:00
|
|
|
Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF))
|
|
|
|
DBUG_RETURN(TRUE);
|
2007-11-09 20:45:44 +01:00
|
|
|
|
2007-01-03 23:15:10 +01:00
|
|
|
SELECT_LEX *sel= &thd->lex->select_lex;
|
|
|
|
SELECT_LEX_UNIT *unit= &thd->lex->unit;
|
|
|
|
ha_rows idx= 0;
|
2007-02-22 16:03:08 +01:00
|
|
|
Protocol *protocol= thd->protocol;
|
2007-01-03 23:15:10 +01:00
|
|
|
|
|
|
|
unit->set_limit(sel);
|
2007-11-09 20:45:44 +01:00
|
|
|
|
2007-04-03 23:59:52 +02:00
|
|
|
void *iterator;
|
2007-11-09 20:45:44 +01:00
|
|
|
for (iterator= history.new_iterator();
|
|
|
|
iterator != NULL;
|
2007-04-03 23:59:52 +02:00
|
|
|
iterator= history.iterator_next(iterator))
|
2007-01-03 23:15:10 +01:00
|
|
|
{
|
2007-04-03 23:59:52 +02:00
|
|
|
prof= history.iterator_value(iterator);
|
|
|
|
|
2007-02-22 16:03:08 +01:00
|
|
|
String elapsed;
|
|
|
|
|
2012-10-12 19:38:45 +02:00
|
|
|
double query_time_usecs= prof->m_end_time_usecs - prof->m_start_time_usecs;
|
2007-01-03 23:15:10 +01:00
|
|
|
|
|
|
|
if (++idx <= unit->offset_limit_cnt)
|
|
|
|
continue;
|
|
|
|
if (idx > unit->select_limit_cnt)
|
|
|
|
break;
|
|
|
|
|
|
|
|
protocol->prepare_for_resend();
|
2007-02-22 16:03:08 +01:00
|
|
|
protocol->store((uint32)(prof->profiling_query_id));
|
2012-10-12 19:38:45 +02:00
|
|
|
protocol->store((double)(query_time_usecs/(1000.0*1000)),
|
2007-02-22 16:03:08 +01:00
|
|
|
(uint32) TIME_FLOAT_DIGITS-1, &elapsed);
|
|
|
|
if (prof->query_source != NULL)
|
2007-11-09 20:45:44 +01:00
|
|
|
protocol->store(prof->query_source, strlen(prof->query_source),
|
2007-02-22 16:03:08 +01:00
|
|
|
system_charset_info);
|
|
|
|
else
|
|
|
|
protocol->store_null();
|
2007-11-09 20:45:44 +01:00
|
|
|
|
2007-01-03 23:15:10 +01:00
|
|
|
if (protocol->write())
|
|
|
|
DBUG_RETURN(TRUE);
|
|
|
|
}
|
2008-02-19 21:47:15 +01:00
|
|
|
my_eof(thd);
|
2007-01-03 23:15:10 +01:00
|
|
|
DBUG_RETURN(FALSE);
|
|
|
|
}
|
|
|
|
|
2007-11-09 20:45:44 +01:00
|
|
|
/**
|
|
|
|
At a point in execution where we know the query source, save the text
|
|
|
|
of it in the query profile.
|
|
|
|
|
|
|
|
This must be called exactly once per descrete statement.
|
2007-02-22 16:03:08 +01:00
|
|
|
*/
|
|
|
|
void PROFILING::set_query_source(char *query_source_arg, uint query_length_arg)
|
|
|
|
{
|
|
|
|
DBUG_ENTER("PROFILING::set_query_source");
|
|
|
|
|
2007-11-09 20:45:44 +01:00
|
|
|
if (! enabled)
|
|
|
|
DBUG_VOID_RETURN;
|
2007-02-22 16:03:08 +01:00
|
|
|
|
|
|
|
if (current != NULL)
|
|
|
|
current->set_query_source(query_source_arg, query_length_arg);
|
|
|
|
else
|
|
|
|
DBUG_PRINT("info", ("no current profile to send query source to"));
|
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Fill the information schema table, "query_profile", as defined in show.cc .
|
2007-07-02 13:27:39 +02:00
|
|
|
There are two ways to get to this function: Selecting from the information
|
2007-11-09 20:45:44 +01:00
|
|
|
schema, and a SHOW command.
|
2007-02-22 16:03:08 +01:00
|
|
|
*/
|
2010-03-14 17:01:45 +01:00
|
|
|
int PROFILING::fill_statistics_info(THD *thd_arg, TABLE_LIST *tables, Item *cond)
|
2007-02-22 16:03:08 +01:00
|
|
|
{
|
|
|
|
DBUG_ENTER("PROFILING::fill_statistics_info");
|
|
|
|
TABLE *table= tables->table;
|
|
|
|
ulonglong row_number= 0;
|
|
|
|
|
|
|
|
QUERY_PROFILE *query;
|
|
|
|
/* Go through each query in this thread's stored history... */
|
2007-04-03 23:59:52 +02:00
|
|
|
void *history_iterator;
|
2007-11-09 20:45:44 +01:00
|
|
|
for (history_iterator= history.new_iterator();
|
|
|
|
history_iterator != NULL;
|
2007-04-03 23:59:52 +02:00
|
|
|
history_iterator= history.iterator_next(history_iterator))
|
2007-02-22 16:03:08 +01:00
|
|
|
{
|
2007-04-03 23:59:52 +02:00
|
|
|
query= history.iterator_value(history_iterator);
|
2007-02-22 16:03:08 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
Because we put all profiling info into a table that may be reordered, let
|
|
|
|
us also include a numbering of each state per query. The query_id and
|
|
|
|
the "seq" together are unique.
|
|
|
|
*/
|
2012-10-12 19:38:45 +02:00
|
|
|
ulong seq;
|
2007-02-22 16:03:08 +01:00
|
|
|
|
2007-04-03 23:59:52 +02:00
|
|
|
void *entry_iterator;
|
2007-11-09 20:45:44 +01:00
|
|
|
PROF_MEASUREMENT *entry, *previous= NULL;
|
2007-02-22 16:03:08 +01:00
|
|
|
/* ...and for each query, go through all its state-change steps. */
|
2012-10-12 19:38:45 +02:00
|
|
|
for (entry_iterator= query->entries.new_iterator();
|
2007-11-09 20:45:44 +01:00
|
|
|
entry_iterator != NULL;
|
2007-04-03 23:59:52 +02:00
|
|
|
entry_iterator= query->entries.iterator_next(entry_iterator),
|
2012-10-12 19:38:45 +02:00
|
|
|
previous=entry, row_number++)
|
2007-02-22 16:03:08 +01:00
|
|
|
{
|
2007-04-03 23:59:52 +02:00
|
|
|
entry= query->entries.iterator_value(entry_iterator);
|
2012-10-12 19:38:45 +02:00
|
|
|
seq= entry->m_seq;
|
2007-04-03 23:59:52 +02:00
|
|
|
|
2007-11-09 20:45:44 +01:00
|
|
|
/* Skip the first. We count spans of fence, not fence-posts. */
|
|
|
|
if (previous == NULL) continue;
|
|
|
|
|
2010-03-14 17:01:45 +01:00
|
|
|
if (thd_arg->lex->sql_command == SQLCOM_SHOW_PROFILE)
|
2007-07-02 13:27:39 +02:00
|
|
|
{
|
2007-11-09 20:45:44 +01:00
|
|
|
/*
|
2007-07-02 13:27:39 +02:00
|
|
|
We got here via a SHOW command. That means that we stored
|
|
|
|
information about the query we wish to show and that isn't
|
|
|
|
in a WHERE clause at a higher level to filter out rows we
|
|
|
|
wish to exclude.
|
|
|
|
|
|
|
|
Because that functionality isn't available in the server yet,
|
|
|
|
we must filter here, at the wrong level. Once one can con-
|
|
|
|
struct where and having conditions at the SQL layer, then this
|
|
|
|
condition should be ripped out.
|
|
|
|
*/
|
2010-03-14 17:01:45 +01:00
|
|
|
if (thd_arg->lex->profile_query_id == 0) /* 0 == show final query */
|
2007-07-02 13:27:39 +02:00
|
|
|
{
|
|
|
|
if (query != last)
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-03-14 17:01:45 +01:00
|
|
|
if (thd_arg->lex->profile_query_id != query->profiling_query_id)
|
2007-07-02 13:27:39 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-02-22 16:03:08 +01:00
|
|
|
/* Set default values for this row. */
|
|
|
|
restore_record(table, s->default_values);
|
|
|
|
|
|
|
|
/*
|
|
|
|
The order of these fields is set by the query_profile_statistics_info
|
|
|
|
array.
|
|
|
|
*/
|
2009-01-12 17:17:15 +01:00
|
|
|
table->field[0]->store((ulonglong) query->profiling_query_id, TRUE);
|
|
|
|
table->field[1]->store((ulonglong) seq, TRUE); /* the step in the sequence */
|
2007-04-04 01:45:28 +02:00
|
|
|
/*
|
|
|
|
This entry, n, has a point in time, T(n), and a status phrase, S(n).
|
|
|
|
The status phrase S(n) describes the period of time that begins at
|
|
|
|
T(n). The previous status phrase S(n-1) describes the period of time
|
|
|
|
that starts at T(n-1) and ends at T(n). Since we want to describe the
|
|
|
|
time that a status phrase took T(n)-T(n-1), this line must describe the
|
|
|
|
previous status.
|
|
|
|
*/
|
2007-11-09 20:45:44 +01:00
|
|
|
table->field[2]->store(previous->status, strlen(previous->status),
|
2007-02-22 16:03:08 +01:00
|
|
|
system_charset_info);
|
2007-07-03 18:20:19 +02:00
|
|
|
|
2007-11-09 20:45:44 +01:00
|
|
|
my_decimal duration_decimal;
|
|
|
|
double2my_decimal(E_DEC_FATAL_ERROR,
|
2007-07-03 18:20:19 +02:00
|
|
|
(entry->time_usecs-previous->time_usecs)/(1000.0*1000),
|
2007-11-09 20:45:44 +01:00
|
|
|
&duration_decimal);
|
|
|
|
|
|
|
|
table->field[3]->store_decimal(&duration_decimal);
|
|
|
|
|
2007-02-22 16:03:08 +01:00
|
|
|
|
|
|
|
#ifdef HAVE_GETRUSAGE
|
|
|
|
|
2007-11-09 20:45:44 +01:00
|
|
|
my_decimal cpu_utime_decimal, cpu_stime_decimal;
|
|
|
|
|
|
|
|
double2my_decimal(E_DEC_FATAL_ERROR,
|
|
|
|
RUSAGE_DIFF_USEC(entry->rusage.ru_utime,
|
2007-07-03 18:20:19 +02:00
|
|
|
previous->rusage.ru_utime) /
|
|
|
|
(1000.0*1000),
|
2007-11-09 20:45:44 +01:00
|
|
|
&cpu_utime_decimal);
|
2007-07-03 18:20:19 +02:00
|
|
|
|
2007-11-09 20:45:44 +01:00
|
|
|
double2my_decimal(E_DEC_FATAL_ERROR,
|
2007-07-03 18:20:19 +02:00
|
|
|
RUSAGE_DIFF_USEC(entry->rusage.ru_stime,
|
2007-11-09 20:45:44 +01:00
|
|
|
previous->rusage.ru_stime) /
|
2007-07-03 18:20:19 +02:00
|
|
|
(1000.0*1000),
|
2007-11-09 20:45:44 +01:00
|
|
|
&cpu_stime_decimal);
|
2007-07-03 18:20:19 +02:00
|
|
|
|
2010-02-05 13:57:15 +01:00
|
|
|
table->field[4]->store_decimal(&cpu_utime_decimal);
|
|
|
|
table->field[5]->store_decimal(&cpu_stime_decimal);
|
|
|
|
table->field[4]->set_notnull();
|
|
|
|
table->field[5]->set_notnull();
|
|
|
|
#elif defined(_WIN32)
|
|
|
|
my_decimal cpu_utime_decimal, cpu_stime_decimal;
|
|
|
|
|
|
|
|
double2my_decimal(E_DEC_FATAL_ERROR,
|
|
|
|
GetTimeDiffInSeconds(&entry->ftUser,
|
|
|
|
&previous->ftUser),
|
|
|
|
&cpu_utime_decimal);
|
|
|
|
double2my_decimal(E_DEC_FATAL_ERROR,
|
|
|
|
GetTimeDiffInSeconds(&entry->ftKernel,
|
|
|
|
&previous->ftKernel),
|
|
|
|
&cpu_stime_decimal);
|
|
|
|
|
|
|
|
// Store the result.
|
2007-11-09 20:45:44 +01:00
|
|
|
table->field[4]->store_decimal(&cpu_utime_decimal);
|
|
|
|
table->field[5]->store_decimal(&cpu_stime_decimal);
|
2007-07-03 18:20:19 +02:00
|
|
|
table->field[4]->set_notnull();
|
2007-02-26 19:11:36 +01:00
|
|
|
table->field[5]->set_notnull();
|
2007-02-22 16:03:08 +01:00
|
|
|
#else
|
|
|
|
/* TODO: Add CPU-usage info for non-BSD systems */
|
|
|
|
#endif
|
2007-11-09 20:45:44 +01:00
|
|
|
|
2007-02-22 16:03:08 +01:00
|
|
|
#ifdef HAVE_GETRUSAGE
|
2007-11-09 20:45:44 +01:00
|
|
|
table->field[6]->store((uint32)(entry->rusage.ru_nvcsw -
|
2007-04-04 01:45:28 +02:00
|
|
|
previous->rusage.ru_nvcsw));
|
2007-02-26 19:11:36 +01:00
|
|
|
table->field[6]->set_notnull();
|
2007-11-09 20:45:44 +01:00
|
|
|
table->field[7]->store((uint32)(entry->rusage.ru_nivcsw -
|
2007-04-04 01:45:28 +02:00
|
|
|
previous->rusage.ru_nivcsw));
|
2007-02-26 19:11:36 +01:00
|
|
|
table->field[7]->set_notnull();
|
2007-02-22 16:03:08 +01:00
|
|
|
#else
|
|
|
|
/* TODO: Add context switch info for non-BSD systems */
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_GETRUSAGE
|
2007-11-09 20:45:44 +01:00
|
|
|
table->field[8]->store((uint32)(entry->rusage.ru_inblock -
|
2007-04-04 01:45:28 +02:00
|
|
|
previous->rusage.ru_inblock));
|
2007-02-26 19:11:36 +01:00
|
|
|
table->field[8]->set_notnull();
|
2007-11-09 20:45:44 +01:00
|
|
|
table->field[9]->store((uint32)(entry->rusage.ru_oublock -
|
2007-04-04 01:45:28 +02:00
|
|
|
previous->rusage.ru_oublock));
|
2007-02-26 19:11:36 +01:00
|
|
|
table->field[9]->set_notnull();
|
2007-02-22 16:03:08 +01:00
|
|
|
#else
|
|
|
|
/* TODO: Add block IO info for non-BSD systems */
|
|
|
|
#endif
|
2007-11-09 20:45:44 +01:00
|
|
|
|
2007-02-22 16:03:08 +01:00
|
|
|
#ifdef HAVE_GETRUSAGE
|
2007-11-09 20:45:44 +01:00
|
|
|
table->field[10]->store((uint32)(entry->rusage.ru_msgsnd -
|
2007-04-04 01:45:28 +02:00
|
|
|
previous->rusage.ru_msgsnd), true);
|
2007-02-26 19:11:36 +01:00
|
|
|
table->field[10]->set_notnull();
|
2007-11-09 20:45:44 +01:00
|
|
|
table->field[11]->store((uint32)(entry->rusage.ru_msgrcv -
|
2007-04-04 01:45:28 +02:00
|
|
|
previous->rusage.ru_msgrcv), true);
|
2007-02-26 19:11:36 +01:00
|
|
|
table->field[11]->set_notnull();
|
2007-02-22 16:03:08 +01:00
|
|
|
#else
|
|
|
|
/* TODO: Add message info for non-BSD systems */
|
|
|
|
#endif
|
2007-11-09 20:45:44 +01:00
|
|
|
|
2007-02-22 16:03:08 +01:00
|
|
|
#ifdef HAVE_GETRUSAGE
|
2007-11-09 20:45:44 +01:00
|
|
|
table->field[12]->store((uint32)(entry->rusage.ru_majflt -
|
2007-04-04 01:45:28 +02:00
|
|
|
previous->rusage.ru_majflt), true);
|
2007-02-26 19:11:36 +01:00
|
|
|
table->field[12]->set_notnull();
|
2007-11-09 20:45:44 +01:00
|
|
|
table->field[13]->store((uint32)(entry->rusage.ru_minflt -
|
2007-04-04 01:45:28 +02:00
|
|
|
previous->rusage.ru_minflt), true);
|
2007-02-26 19:11:36 +01:00
|
|
|
table->field[13]->set_notnull();
|
2007-02-22 16:03:08 +01:00
|
|
|
#else
|
|
|
|
/* TODO: Add page fault info for non-BSD systems */
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_GETRUSAGE
|
2007-11-09 20:45:44 +01:00
|
|
|
table->field[14]->store((uint32)(entry->rusage.ru_nswap -
|
2007-04-04 01:45:28 +02:00
|
|
|
previous->rusage.ru_nswap), true);
|
2007-02-26 19:11:36 +01:00
|
|
|
table->field[14]->set_notnull();
|
2007-02-22 16:03:08 +01:00
|
|
|
#else
|
|
|
|
/* TODO: Add swap info for non-BSD systems */
|
|
|
|
#endif
|
2007-11-09 20:45:44 +01:00
|
|
|
|
|
|
|
/* Emit the location that started this step, not that ended it. */
|
|
|
|
if ((previous->function != NULL) && (previous->file != NULL))
|
2007-02-22 16:03:08 +01:00
|
|
|
{
|
2007-11-09 20:45:44 +01:00
|
|
|
table->field[15]->store(previous->function, strlen(previous->function),
|
|
|
|
system_charset_info);
|
2007-02-26 19:11:36 +01:00
|
|
|
table->field[15]->set_notnull();
|
2007-11-09 20:45:44 +01:00
|
|
|
table->field[16]->store(previous->file, strlen(previous->file), system_charset_info);
|
2007-02-26 19:11:36 +01:00
|
|
|
table->field[16]->set_notnull();
|
2007-11-09 20:45:44 +01:00
|
|
|
table->field[17]->store(previous->line, true);
|
2007-02-26 19:11:36 +01:00
|
|
|
table->field[17]->set_notnull();
|
2007-02-22 16:03:08 +01:00
|
|
|
}
|
|
|
|
|
2010-03-14 17:01:45 +01:00
|
|
|
if (schema_table_store_record(thd_arg, table))
|
2007-02-22 16:03:08 +01:00
|
|
|
DBUG_RETURN(1);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
|
|
|
#endif /* ENABLED_PROFILING */
|