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) {
return rtn;
}
void Stats::dump() {
void Stats::dump(bool includeZeros) {
if (!Stats::enabled)
return;
......@@ -65,7 +65,8 @@ void Stats::dump() {
std::sort(pairs.begin(), pairs.end());
for (int i = 0; i < pairs.size(); i++) {
printf("%s: %ld\n", pairs[i].first.c_str(), (*counts)[pairs[i].second]);
if (includeZeros || (*counts)[pairs[i].second] > 0)
printf("%s: %ld\n", pairs[i].first.c_str(), (*counts)[pairs[i].second]);
}
}
......
......@@ -41,7 +41,7 @@ public:
static void log(int id, int count = 1) { (*counts)[id] += count; }
static void clear() { std::fill(counts->begin(), counts->end(), 0); }
static void dump();
static void dump(bool includeZeros = true);
static void endOfInit();
};
......
......@@ -53,8 +53,11 @@ static Box* clearStats() {
return None;
}
static Box* dumpStats() {
Stats::dump();
static Box* dumpStats(Box* includeZeros) {
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;
}
......@@ -67,6 +70,7 @@ void setupPyston() {
pyston_module->giveAttr("clearStats",
new BoxedBuiltinFunctionOrMethod(boxRTFunction((void*)clearStats, NONE, 0), "clearStats"));
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