// // Generate summary report. // void ProfilerGenerateReport(const std::wstring& fileName, struct tm* timeInfo) { FILE* f = _wfopen(fileName.c_str(), L"wt"); if (f == NULL) { RuntimeError("Error: ProfilerGenerateReport: Cannot create file <%ls>.\n", fileName.c_str()); } fprintfOrDie(f, "CNTK Performance Profiler Summary Report\n\n"); char timeStr[32]; strftime(timeStr, sizeof(timeStr), "%Y/%m/%d %H:%M:%S", timeInfo); fprintfOrDie(f, "Time Stamp: %s\n\n", timeStr); fprintfOrDie(f, "Description................ ............Mean ..........StdDev .............Min .............Max ...........Count ...........Total\n\n"); for (int evtIdx = 0; evtIdx < profilerEvtMax; evtIdx++) { bool printLine = false; switch (c_fixedEvtDesc[evtIdx].eventType) { case profilerEvtTime: if (g_profilerState->fixedEvents[evtIdx].cnt > 0) { printLine = true; fprintfOrDie(f, "%-26s: ", c_fixedEvtDesc[evtIdx].eventDescription); char str[32]; double mean = TicksToSeconds(g_profilerState->fixedEvents[evtIdx].sum) / g_profilerState->fixedEvents[evtIdx].cnt; FormatTimeStr(str, sizeof(str), mean); fprintfOrDie(f, "%s ", str); double sum = TicksToSeconds(g_profilerState->fixedEvents[evtIdx].sum); double sumsq = TicksSqToSecondsSq(g_profilerState->fixedEvents[evtIdx].sumsq); double stdDev = sumsq - (pow(sum, 2.0) / g_profilerState->fixedEvents[evtIdx].cnt); if (stdDev < 0.0) stdDev = 0.0; stdDev = sqrt(stdDev / (double)g_profilerState->fixedEvents[evtIdx].cnt); FormatTimeStr(str, sizeof(str), stdDev); fprintfOrDie(f, "%s ", str); FormatTimeStr(str, sizeof(str), TicksToSeconds(g_profilerState->fixedEvents[evtIdx].min)); fprintfOrDie(f, "%s ", str); FormatTimeStr(str, sizeof(str), TicksToSeconds(g_profilerState->fixedEvents[evtIdx].max)); fprintfOrDie(f, "%s ", str); fprintfOrDie(f, "%16d ", g_profilerState->fixedEvents[evtIdx].cnt); FormatTimeStr(str, sizeof(str), TicksToSeconds(g_profilerState->fixedEvents[evtIdx].sum)); fprintfOrDie(f, "%s", str); } break; case profilerEvtThroughput: if (g_profilerState->fixedEvents[evtIdx].cnt > 0) { printLine = true; fprintfOrDie(f, "%-26s: ", c_fixedEvtDesc[evtIdx].eventDescription); char str[32]; double mean = ((double)g_profilerState->fixedEvents[evtIdx].sum / (double)g_profilerState->fixedEvents[evtIdx].cnt); FormatThroughputStr(str, sizeof(str), mean); fprintfOrDie(f, "%s ", str); double stdDev = g_profilerState->fixedEvents[evtIdx].sumsq - (pow((double)g_profilerState->fixedEvents[evtIdx].sum, 2.0) / (double)g_profilerState->fixedEvents[evtIdx].cnt); if (stdDev < 0.0) stdDev = 0.0; stdDev = sqrt(stdDev / (double)g_profilerState->fixedEvents[evtIdx].cnt); FormatThroughputStr(str, sizeof(str), stdDev); fprintfOrDie(f, "%s ", str); FormatThroughputStr(str, sizeof(str), (double)g_profilerState->fixedEvents[evtIdx].min); fprintfOrDie(f, "%s ", str); FormatThroughputStr(str, sizeof(str), (double)g_profilerState->fixedEvents[evtIdx].max); fprintfOrDie(f, "%s ", str); fprintfOrDie(f, "%16d ", g_profilerState->fixedEvents[evtIdx].cnt); FormatBytesStr(str, sizeof(str), g_profilerState->fixedEvents[evtIdx].totalBytes); fprintfOrDie(f, "%s", str); } break; case profilerEvtSeparator: printLine = true; fprintfOrDie(f, "%s", c_fixedEvtDesc[evtIdx].eventDescription); break; } if (printLine) fprintfOrDie(f, "\n"); } fclose(f); }
double Timer::GetProfileSeconds() { static UInt64 StartTime = GetProfileTicks(); return TicksToSeconds(GetProfileTicks()-StartTime); }