| 1 |
////////////////////////////////////////////////////////////////////////////// |
| 2 |
////////////////////////////////////////////////////////////////////////////// |
| 3 |
// |
| 4 |
// copyright : (C) 2014 Eran Ifrah |
| 5 |
// file name : performance.cpp |
| 6 |
// |
| 7 |
// ------------------------------------------------------------------------- |
| 8 |
// A |
| 9 |
// _____ _ _ _ _ |
| 10 |
// / __ \ | | | | (_) | |
| 11 |
// | / \/ ___ __| | ___| | _| |_ ___ |
| 12 |
// | | / _ \ / _ |/ _ \ | | | __/ _ ) |
| 13 |
// | \__/\ (_) | (_| | __/ |___| | || __/ |
| 14 |
// \____/\___/ \__,_|\___\_____/_|\__\___| |
| 15 |
// |
| 16 |
// F i l e |
| 17 |
// |
| 18 |
// This program is free software; you can redistribute it and/or modify |
| 19 |
// it under the terms of the GNU General Public License as published by |
| 20 |
// the Free Software Foundation; either version 2 of the License, or |
| 21 |
// (at your option) any later version. |
| 22 |
// |
| 23 |
////////////////////////////////////////////////////////////////////////////// |
| 24 |
////////////////////////////////////////////////////////////////////////////// |
| 25 |
|
| 26 |
#define __PERFORMANCE |
| 27 |
#include "performance.h" |
| 28 |
|
| 29 |
#ifdef __WXMSW__ |
| 30 |
|
| 31 |
#include "wx/msw/wrapwin.h" // includes windows.h |
| 32 |
#include <assert.h> |
| 33 |
#include <stdio.h> |
| 34 |
#include <string> |
| 35 |
#include <vector> |
| 36 |
|
| 37 |
#if 0 |
| 38 |
static FILE* dbgFile(NULL); |
| 39 |
static std::string output = ""; |
| 40 |
static std::vector<std::pair<DWORD, DWORD> > tickCounts; |
| 41 |
#endif |
| 42 |
void PERF_OUTPUT(const char* path) |
| 43 |
{ |
| 44 |
#if 0 |
| 45 |
output = path; |
| 46 |
#endif |
| 47 |
} |
| 48 |
|
| 49 |
void PERF_START(const char* func_name) |
| 50 |
{ |
| 51 |
#if 0 |
| 52 |
if(!dbgFile) { |
| 53 |
dbgFile = fopen(output.c_str(), "w+"); |
| 54 |
assert(dbgFile != 0); |
| 55 |
} |
| 56 |
fprintf(dbgFile, "%*c<block name=\"%s\">\n", 4 * tickCounts.size(), ' ', func_name); |
| 57 |
fflush(dbgFile); |
| 58 |
tickCounts.push_back(std::make_pair(DWORD(GetTickCount()), DWORD(0))); |
| 59 |
#endif |
| 60 |
} |
| 61 |
|
| 62 |
void PERF_END() |
| 63 |
{ |
| 64 |
#if 0 |
| 65 |
assert(dbgFile != 0); |
| 66 |
if(tickCounts.empty()) { return; } |
| 67 |
DWORD tickCount = GetTickCount(); |
| 68 |
DWORD elapsed = tickCount - tickCounts.back().first; |
| 69 |
DWORD unaccounted = elapsed - tickCounts.back().second; |
| 70 |
|
| 71 |
fprintf(dbgFile, "%*c<elapsed time=\"%ld\"", 4 * tickCounts.size(), ' ', elapsed); |
| 72 |
if(0 < unaccounted && unaccounted < elapsed) { fprintf(dbgFile, " unaccounted=\"%ld\"", unaccounted); } |
| 73 |
fprintf(dbgFile, "/>\n"); |
| 74 |
|
| 75 |
tickCounts.pop_back(); |
| 76 |
if(!tickCounts.empty()) { tickCounts.back().second += elapsed; } |
| 77 |
|
| 78 |
fprintf(dbgFile, "%*c</block>\n", 4 * tickCounts.size(), ' '); |
| 79 |
fflush(dbgFile); |
| 80 |
#endif |
| 81 |
} |
| 82 |
|
| 83 |
#endif |