diff options
author | Yabin Cui <yabinc@google.com> | 2015-08-21 14:23:43 -0700 |
---|---|---|
committer | Yabin Cui <yabinc@google.com> | 2015-08-21 16:15:58 -0700 |
commit | cc2e59e2478d330c89eaceda0dcc1f05ee32fbf8 (patch) | |
tree | 2c84c4b8fa8f8ffd1f6d60f520a28213ef9ad585 /simpleperf/utils.cpp | |
parent | bb86cc8c6ac869044c3811c59616e01255c983d3 (diff) | |
download | extras-cc2e59e2478d330c89eaceda0dcc1f05ee32fbf8.tar.gz |
Simpleperf: use OneTimeFreeAllocator to allocate symbol names.
simpleperf report takes a lot of time mallocing and freeing memory.
This change reduces the time to free memory.
Before this change:
$sudo simpleperf stat simpleperf report
Performance counter statistics:
3,258,481,203 cpu-cycles # 2.290946 GHz (80%)
4,147,660,154 instructions # 0.785619 cycles per instruction (79%)
Total test time: 1.422330 seconds.
After this change:
$sudo simpleperf stat simpleperf report
Performance counter statistics:
1,699,221,386 cpu-cycles # 2.994754 GHz (79%)
2,739,945,156 instructions # 0.620166 cycles per instruction (81%)
Total test time: 0.567399 seconds.
This change also fix a bug in record_file_test.cpp.
Bug: 23387541
Change-Id: I59fc86ca54a6c09bd08eec8ada931ccff88d3102
Diffstat (limited to 'simpleperf/utils.cpp')
-rw-r--r-- | simpleperf/utils.cpp | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/simpleperf/utils.cpp b/simpleperf/utils.cpp index bca02bdc..ee95b091 100644 --- a/simpleperf/utils.cpp +++ b/simpleperf/utils.cpp @@ -23,8 +23,35 @@ #include <sys/stat.h> #include <unistd.h> +#include <algorithm> +#include <string> + #include <base/logging.h> +void OneTimeFreeAllocator::Clear() { + for (auto& p : v_) { + delete[] p; + } + v_.clear(); + cur_ = nullptr; + end_ = nullptr; +} + +const char* OneTimeFreeAllocator::AllocateString(const std::string& s) { + size_t size = s.size() + 1; + if (cur_ + size > end_) { + size_t alloc_size = std::max(size, unit_size_); + char* p = new char[alloc_size]; + v_.push_back(p); + cur_ = p; + end_ = p + alloc_size; + } + strcpy(cur_, s.c_str()); + const char* result = cur_; + cur_ += size; + return result; +} + void PrintIndented(size_t indent, const char* fmt, ...) { va_list ap; va_start(ap, fmt); |