1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
|
/*
Copyright 2009 - 2010 Sun Microsystems, Inc. All rights reserved.
The MySQL Connector/C++ is licensed under the terms of the GPL
<http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>, like most
MySQL Connectors. There are special exceptions to the terms and
conditions of the GPL as it is applied to this software, see the
FLOSS License Exception
<http://www.mysql.com/about/legal/licensing/foss-exception.html>.
*/
#ifndef __TEST_TIMER_H_
#define __TEST_TIMER_H_
#include <time.h>
#include "../common/ccppTypes.h"
#include "../common/singleton.h"
namespace testsuite
{
struct timer
{
clock_t start;
clock_t total_cpu;
bool stopped;
String file;
unsigned int line;
timer(clock_t _start, clock_t _total_cpu, bool _stopped) :
start(_start),
total_cpu(_total_cpu),
stopped(_stopped),
file(""),
line(0)
{
}
timer(clock_t _start) :
start(_start),
total_cpu(static_cast<clock_t> (0)),
stopped(false),
file(""),
line(0)
{
}
timer(clock_t _start, String _file, unsigned int _line) :
start(_start),
total_cpu(static_cast<clock_t> (0)),
stopped(false),
file(_file),
line(_line)
{
}
timer() :
start(static_cast<clock_t> (0)),
total_cpu(static_cast<clock_t> (0)),
stopped(false),
file(""),
line(0)
{
this->start=clock();
}
timer(const timer & rhs) :
start(rhs.start),
total_cpu(rhs.total_cpu),
stopped(rhs.stopped),
file(rhs.file),
line(rhs.line)
{
}
};
struct test_timer
{
clock_t cpu;
std::map<String, timer> timers;
test_timer()
{
this->cpu=clock();
}
test_timer(const test_timer & rhs) :
cpu(rhs.cpu),
timers(rhs.timers)
{
}
};
class Timer : public policies::Singleton<Timer>
{
CCPP_SINGLETON(Timer);
std::map<String, test_timer> timeRecorder;
String currentTest;
public:
static clock_t startTest(const String & test);
static clock_t stopTest(const String & test);
static clock_t startTimer(const String & test, const String & name, const String & file, const unsigned int line);
static clock_t startTimer(const String & name, const String & file, const unsigned int line);
static clock_t stopTimer(const String & test, const String & name);
static clock_t stopTimer(const String & name);
static const List & getNames();
static const List & getNames(const String & test);
static clock_t getTime(const String & test, const String & name);
static clock_t getTime(const String & test);
static float getSeconds(const String & test, const String & name);
static float getSeconds(const String & test);
static unsigned int getLine(const String & test, const String & name);
static unsigned int getLine(const String & test);
static const String getFile(const String & test, const String & name);
static const String getFile(const String & test);
static float translate2seconds(clock_t);
};
}
#define TIMER_START(label) Timer::startTimer(#label, __FILE__, __LINE__);
#define TIMER_STOP(label) Timer::stopTimer(#label);
#endif // ifndef __TEST_TIMER_H_
|