summaryrefslogtreecommitdiff
path: root/src/utils/perfomance.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2014-05-31 19:49:21 +0300
committerAndrei Karas <akaras@inbox.ru>2014-05-31 19:49:21 +0300
commitcca552c123e6522541b15e7cf4f51f3ec0fcf564 (patch)
tree2efc351ab14d91722de0b7cd2d5932a42235989c /src/utils/perfomance.cpp
parent5d5f60a40dcd343ed34d4257b2383e9ed9091c3f (diff)
downloadmanaplus-cca552c123e6522541b15e7cf4f51f3ec0fcf564.tar.gz
manaplus-cca552c123e6522541b15e7cf4f51f3ec0fcf564.tar.bz2
manaplus-cca552c123e6522541b15e7cf4f51f3ec0fcf564.tar.xz
manaplus-cca552c123e6522541b15e7cf4f51f3ec0fcf564.zip
Improve profiler speed.
Diffstat (limited to 'src/utils/perfomance.cpp')
-rw-r--r--src/utils/perfomance.cpp21
1 files changed, 17 insertions, 4 deletions
diff --git a/src/utils/perfomance.cpp b/src/utils/perfomance.cpp
index 93d09cb40..d7ed52d4b 100644
--- a/src/utils/perfomance.cpp
+++ b/src/utils/perfomance.cpp
@@ -29,6 +29,7 @@
#include <algorithm>
#include <cstdarg>
#include <cstdio>
+#include <fcntl.h>
#include <fstream>
#include <iostream>
@@ -37,11 +38,12 @@
static const clockid_t clockType = CLOCK_MONOTONIC;
#define timeData ((static_cast<long long int>(time.tv_sec) * 1000000000LL \
- + static_cast<long long int>(time.tv_nsec)) / 1000)
+ + static_cast<long long int>(time.tv_nsec)) / 1)
namespace Perfomance
{
std::ofstream file;
+ std::string temp;
long long unsigned int startTime;
void init(const std::string &path)
@@ -49,6 +51,7 @@ namespace Perfomance
file.open(path.c_str(), std::ios_base::trunc);
timespec time;
clock_gettime(clockType, &time);
+ temp.reserve(10000000U);
startTime = timeData;
}
@@ -62,21 +65,31 @@ namespace Perfomance
{
timespec time;
clock_gettime(clockType, &time);
- file << (timeData - startTime) << " __init__" << std::endl;
+ temp.append(toString(timeData - startTime)).append(
+ " __init__\n");
}
void blockStart(const std::string &name)
{
timespec time;
clock_gettime(clockType, &time);
- file << (timeData - startTime) << " start: " << name << std::endl;
+ temp.append(toString(timeData - startTime)).append(
+ " start: ").append(name).append("\n");
}
void blockEnd(const std::string &name)
{
timespec time;
clock_gettime(clockType, &time);
- file << (timeData - startTime) << " end: " << name << std::endl;
+ temp.append(toString(timeData - startTime)).append(
+ " end: ").append(name).append("\n");
+ }
+
+ void flush()
+ {
+ file << temp;
+ temp.clear();
+// file.flush();
}
} // namespace Perfomance