Commit d30281e3 authored by Chris Toshok's avatar Chris Toshok

add an option for not including stats with 0 counters (useful for when we're clearing stats)

parent bdaaf6b6
...@@ -51,7 +51,7 @@ int Stats::getStatId(const std::string& name) { ...@@ -51,7 +51,7 @@ int Stats::getStatId(const std::string& name) {
return rtn; return rtn;
} }
void Stats::dump() { void Stats::dump(bool includeZeros) {
if (!Stats::enabled) if (!Stats::enabled)
return; return;
...@@ -65,6 +65,7 @@ void Stats::dump() { ...@@ -65,6 +65,7 @@ void Stats::dump() {
std::sort(pairs.begin(), pairs.end()); std::sort(pairs.begin(), pairs.end());
for (int i = 0; i < pairs.size(); i++) { for (int i = 0; i < pairs.size(); i++) {
if (includeZeros || (*counts)[pairs[i].second] > 0)
printf("%s: %ld\n", pairs[i].first.c_str(), (*counts)[pairs[i].second]); printf("%s: %ld\n", pairs[i].first.c_str(), (*counts)[pairs[i].second]);
} }
} }
......
...@@ -41,7 +41,7 @@ public: ...@@ -41,7 +41,7 @@ public:
static void log(int id, int count = 1) { (*counts)[id] += count; } static void log(int id, int count = 1) { (*counts)[id] += count; }
static void clear() { std::fill(counts->begin(), counts->end(), 0); } static void clear() { std::fill(counts->begin(), counts->end(), 0); }
static void dump(); static void dump(bool includeZeros = true);
static void endOfInit(); static void endOfInit();
}; };
......
...@@ -53,8 +53,11 @@ static Box* clearStats() { ...@@ -53,8 +53,11 @@ static Box* clearStats() {
return None; return None;
} }
static Box* dumpStats() { static Box* dumpStats(Box* includeZeros) {
Stats::dump(); if (includeZeros->cls != bool_cls)
raiseExcHelper(TypeError, "includeZeros must be a 'bool' object but received a '%s'",
getTypeName(includeZeros));
Stats::dump(((BoxedBool*)includeZeros)->n != 0);
return None; return None;
} }
...@@ -67,6 +70,7 @@ void setupPyston() { ...@@ -67,6 +70,7 @@ void setupPyston() {
pyston_module->giveAttr("clearStats", pyston_module->giveAttr("clearStats",
new BoxedBuiltinFunctionOrMethod(boxRTFunction((void*)clearStats, NONE, 0), "clearStats")); new BoxedBuiltinFunctionOrMethod(boxRTFunction((void*)clearStats, NONE, 0), "clearStats"));
pyston_module->giveAttr("dumpStats", pyston_module->giveAttr("dumpStats",
new BoxedBuiltinFunctionOrMethod(boxRTFunction((void*)dumpStats, NONE, 0), "dumpStats")); new BoxedBuiltinFunctionOrMethod(boxRTFunction((void*)dumpStats, NONE, 1, 1, false, false),
"dumpStats", { False }));
} }
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment