YoushouldhavereceivedacopyoftheGNUGeneralPublicLicense alongwiththisprogram;ifnot,writetotheFreeSoftware
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335 USA */
// Get time difference between to FILETIME objects in seconds. staticdouble GetTimeDiffInSeconds(FILETIME *a, FILETIME *b)
{ return ((FileTimeToQuadWord(a) - FileTimeToQuadWord(b)) / 1e7);
} #endif
@todoImplementresourcecaptureforOSesnotlikeBSD.
*/ void PROF_MEASUREMENT::collect()
{
time_usecs= my_interval_timer() / 1e3; /* ns to us */ #ifdef HAVE_GETRUSAGE
getrusage(RUSAGE_SELF, &rusage); #elifdefined(_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);
GetProcessIoCounters(GetCurrentProcess(), &io_count);
GetProcessMemoryInfo(GetCurrentProcess(), &mem_count, sizeof(mem_count)); #endif
}
/* The last fence-post, so we can support the span before this. */
status_change("ending", NULL, NULL, 0);
if (enabled && /* ON at end? */
(current->query_source != NULL) &&
(! current->entries.is_empty()))
{
current->profiling_query_id= next_profile_id(); /* assign an id */
history.push_back(current);
last= current; /* never contains something that is not in the history. */
/* Maintain the history size. */ while (history.elements > thd->variables.profiling_history_size) delete history.pop();
} else delete current;
QUERY_PROFILE *query; /* Go through each query in this thread's stored history... */ void *history_iterator; for (history_iterator= history.new_iterator();
history_iterator != NULL;
history_iterator= history.iterator_next(history_iterator))
{
query= history.iterator_value(history_iterator);
void *entry_iterator;
PROF_MEASUREMENT *entry, *previous= NULL; /* ...and for each query, go through all its state-change steps. */ for (entry_iterator= query->entries.new_iterator();
entry_iterator != NULL;
entry_iterator= query->entries.iterator_next(entry_iterator),
previous=entry)
{
entry= query->entries.iterator_value(entry_iterator);
seq= entry->m_seq;
/* Skip the first. We count spans of fence, not fence-posts. */ if (previous == NULL) continue;
if (thd_arg->lex->sql_command == SQLCOM_SHOW_PROFILE)
{ /* WegothereviaaSHOWcommand.Thatmeansthatwestored informationaboutthequerywewishtoshowandthatisn't inaWHEREclauseatahigherleveltofilteroutrowswe wishtoexclude.
Becausethatfunctionalityisn'tavailableintheserveryet, wemustfilterhere,atthewronglevel.Onceonecancon- structwhereandhavingconditionsattheSQLlayer,thenthis conditionshouldberippedout.
*/ if (thd_arg->lex->profile_query_id == 0) /* 0 == show final query */
{ if (query != last) continue;
} else
{ if (thd_arg->lex->profile_query_id != query->profiling_query_id) continue;
}
}
/* Set default values for this row. */
restore_record(table, s->default_values);
/* Theorderofthesefieldsissetbythequery_profile_statistics_info array.
*/
table->field[0]->store((ulonglong) query->profiling_query_id, TRUE);
table->field[1]->store((ulonglong) seq, TRUE); /* the step in the sequence */ /* Thisentry,n,hasapointintime,T(n),andastatusphrase,S(n). ThestatusphraseS(n)describestheperiodoftimethatbeginsat T(n).ThepreviousstatusphraseS(n-1)describestheperiodoftime thatstartsatT(n-1)andendsatT(n).Sincewewanttodescribethe timethatastatusphrasetookT(n)-T(n-1),thislinemustdescribethe previousstatus.
*/
table->field[2]->store(previous->status, strlen(previous->status),
system_charset_info);
// Store the result.
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(); #else /* TODO: Add CPU-usage info for non-BSD systems */ #endif
#ifdef HAVE_GETRUSAGE
table->field[6]->store((uint32)(entry->rusage.ru_nvcsw -
previous->rusage.ru_nvcsw));
table->field[6]->set_notnull();
table->field[7]->store((uint32)(entry->rusage.ru_nivcsw -
previous->rusage.ru_nivcsw));
table->field[7]->set_notnull(); #else /* TODO: Add context switch info for non-BSD systems */ #endif
table->field[9]->store((uint32)writes_delta);
table->field[9]->set_notnull(); #else /* TODO: Add block IO info for non-BSD systems */ #endif
#ifdef HAVE_GETRUSAGE
table->field[10]->store((uint32)(entry->rusage.ru_msgsnd -
previous->rusage.ru_msgsnd), true);
table->field[10]->set_notnull();
table->field[11]->store((uint32)(entry->rusage.ru_msgrcv -
previous->rusage.ru_msgrcv), true);
table->field[11]->set_notnull(); #else /* TODO: Add message info for non-BSD systems */ #endif
#ifdef HAVE_GETRUSAGE
table->field[12]->store((uint32)(entry->rusage.ru_majflt -
previous->rusage.ru_majflt), true);
table->field[12]->set_notnull();
table->field[13]->store((uint32)(entry->rusage.ru_minflt -
previous->rusage.ru_minflt), true);
table->field[13]->set_notnull(); #elifdefined(_WIN32) /* Windows APIs don't easily distinguish between hard and soft page faults,sowejustfillthe'major'columnandleavethesecondNULL.
*/
table->field[12]->store((uint32)(entry->mem_count.PageFaultCount -
previous->mem_count.PageFaultCount), true);
table->field[12]->set_notnull(); #else /* TODO: Add page fault info for non-BSD systems */ #endif
#ifdef HAVE_GETRUSAGE
table->field[14]->store((uint32)(entry->rusage.ru_nswap -
previous->rusage.ru_nswap), true);
table->field[14]->set_notnull(); #else /* TODO: Add swap info for non-BSD systems */ #endif
/* Emit the location that started this step, not that ended it. */ if ((previous->function != NULL) && (previous->file != NULL))
{
table->field[15]->store(previous->function, strlen(previous->function),
system_charset_info);
table->field[15]->set_notnull();
table->field[16]->store(previous->file, strlen(previous->file), system_charset_info);
table->field[16]->set_notnull();
table->field[17]->store(previous->line, true);
table->field[17]->set_notnull();
}
if (schema_table_store_record(thd_arg, table))
DBUG_RETURN(1);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.