aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Willemsen <dwillemsen@google.com>2019-08-12 17:55:43 -0700
committerDan Willemsen <dwillemsen@google.com>2019-08-13 14:52:10 -0700
commit1d81ca168fee175d57cb0910267205013098eac9 (patch)
tree0411c47560b422d8a3ed91b3ea484d67b8cd2a7b
parentadfbd370c710485d5dc21617048fbde5f07767a1 (diff)
downloadplatform_build_kati-1d81ca168fee175d57cb0910267205013098eac9.tar.gz
platform_build_kati-1d81ca168fee175d57cb0910267205013098eac9.tar.bz2
platform_build_kati-1d81ca168fee175d57cb0910267205013098eac9.zip
When printing top stats, include count
Instead of just accumulating the time for each instance under a statistics call, also keep track of how many times it was called: *kati*: func shell time: 0.822685 / 148 (114 unique) *kati*: 0.019 / 3 cd foo; find -L ../src -name "*.java" -and -not -name ".*" ... Due to line length concerns, I didn't put the average (elapsed/count), but that's fairly easy to calculate by hand. I also added the '(X unique)' to understand how unique the calls are. If it becomes useful in the future, this would be extensible to support bucketed count -- allowing generation of histograms. I don't expect enough variation to need that with any stats uses today. Update to c++17 (the default in Android) to support decomposition declarations. Change-Id: I357fb4fdc155dc0be5103f4f3a268f2cdaa4201a
-rw-r--r--Makefile.ckati6
-rw-r--r--stats.cc35
-rw-r--r--stats.h7
3 files changed, 35 insertions, 13 deletions
diff --git a/Makefile.ckati b/Makefile.ckati
index e4067bb..6337590 100644
--- a/Makefile.ckati
+++ b/Makefile.ckati
@@ -82,17 +82,17 @@ endif
# Rule to build ckati into KATI_BIN_PATH
$(KATI_BIN_PATH)/ckati: $(KATI_CXX_OBJS) $(KATI_CXX_GENERATED_OBJS)
@mkdir -p $(dir $@)
- $(KATI_LD) -std=c++11 $(KATI_CXXFLAGS) -o $@ $^ $(KATI_LIBS)
+ $(KATI_LD) -std=c++17 $(KATI_CXXFLAGS) -o $@ $^ $(KATI_LIBS)
# Rule to build normal source files into object files in KATI_INTERMEDIATES_PATH
$(KATI_CXX_OBJS) $(KATI_CXX_TEST_OBJS): $(KATI_INTERMEDIATES_PATH)/%.o: $(KATI_SRC_PATH)/%.cc
@mkdir -p $(dir $@)
- $(KATI_CXX) -c -std=c++11 $(KATI_CXXFLAGS) -o $@ $<
+ $(KATI_CXX) -c -std=c++17 $(KATI_CXXFLAGS) -o $@ $<
# Rule to build generated source files into object files in KATI_INTERMEDIATES_PATH
$(KATI_CXX_GENERATED_OBJS): $(KATI_INTERMEDIATES_PATH)/%.o: $(KATI_INTERMEDIATES_PATH)/%.cc
@mkdir -p $(dir $@)
- $(KATI_CXX) -c -std=c++11 $(KATI_CXXFLAGS) -o $@ $<
+ $(KATI_CXX) -c -std=c++17 $(KATI_CXXFLAGS) -o $@ $<
ckati_tests: $(KATI_CXX_TEST_EXES)
diff --git a/stats.cc b/stats.cc
index c6687c4..eba36a1 100644
--- a/stats.cc
+++ b/stats.cc
@@ -42,20 +42,35 @@ Stats::Stats(const char* name) : name_(name), elapsed_(0), cnt_(0) {
void Stats::DumpTop() const {
unique_lock<mutex> lock(mu_);
if (detailed_.size() > 0) {
- vector<pair<string, double>> v(detailed_.begin(), detailed_.end());
- sort(
- v.begin(), v.end(),
- [](const pair<string, double> a, const pair<string, double> b) -> bool {
- return a.second > b.second;
- });
- for (unsigned int i = 0; i < 10 && i < v.size(); i++) {
- LOG_STAT(" %5.3f %s", v[i].first.c_str(), v[i].second);
+ vector<pair<string, StatsDetails>> details(detailed_.begin(),
+ detailed_.end());
+ sort(details.begin(), details.end(),
+ [](const pair<string, StatsDetails> a,
+ const pair<string, StatsDetails> b) -> bool {
+ return a.second.elapsed_ > b.second.elapsed_;
+ });
+
+ // Only print the top 10
+ details.resize(min(details.size(), 10LU));
+
+ int max_cnt_len = 1;
+ for (auto& [name, detail] : details) {
+ max_cnt_len =
+ max(max_cnt_len, static_cast<int>(to_string(detail.cnt_).length()));
+ }
+
+ for (auto& [name, detail] : details) {
+ LOG_STAT(" %6.3f / %*d %s", detail.elapsed_, max_cnt_len, detail.cnt_,
+ name.c_str());
}
}
}
string Stats::String() const {
unique_lock<mutex> lock(mu_);
+ if (!detailed_.empty())
+ return StringPrintf("%s: %f / %d (%d unique)", name_, elapsed_, cnt_,
+ detailed_.size());
return StringPrintf("%s: %f / %d", name_, elapsed_, cnt_);
}
@@ -71,7 +86,9 @@ double Stats::End(double start, const char* msg) {
unique_lock<mutex> lock(mu_);
elapsed_ += e;
if (msg != 0) {
- detailed_[string(msg)] += e;
+ StatsDetails& details = detailed_[string(msg)];
+ details.elapsed_ += e;
+ details.cnt_++;
}
return e;
}
diff --git a/stats.h b/stats.h
index 6480d5f..d9fd675 100644
--- a/stats.h
+++ b/stats.h
@@ -21,6 +21,11 @@
using namespace std;
+struct StatsDetails {
+ int cnt_ = 0;
+ double elapsed_ = 0;
+};
+
class Stats {
public:
explicit Stats(const char* name);
@@ -38,7 +43,7 @@ class Stats {
double elapsed_;
int cnt_;
mutable mutex mu_;
- unordered_map<string, double> detailed_;
+ unordered_map<string, StatsDetails> detailed_;
};
class ScopedStatsRecorder {