Commit 71e29790 authored by Kevin Modzelewski's avatar Kevin Modzelewski

Merge pull request #498 from toshok/stat-timers2

put back in the Timer-based stats I removed in the stats-timer branch…
parents 600208d0 d5742671
...@@ -983,6 +983,7 @@ AST_Module* parse_string(const char* code) { ...@@ -983,6 +983,7 @@ AST_Module* parse_string(const char* code) {
AST_Module* parse_file(const char* fn) { AST_Module* parse_file(const char* fn) {
STAT_TIMER(t0, "us_timer_cpyton_parsing"); STAT_TIMER(t0, "us_timer_cpyton_parsing");
Timer _t("parsing");
if (ENABLE_PYPA_PARSER) { if (ENABLE_PYPA_PARSER) {
AST_Module* rtn = pypa_parse(fn); AST_Module* rtn = pypa_parse(fn);
...@@ -1003,6 +1004,10 @@ AST_Module* parse_file(const char* fn) { ...@@ -1003,6 +1004,10 @@ AST_Module* parse_file(const char* fn) {
assert(rtn->type == AST_TYPE::Module); assert(rtn->type == AST_TYPE::Module);
long us = _t.end();
static StatCounter us_parsing("us_parsing");
us_parsing.log(us);
return ast_cast<AST_Module>(rtn); return ast_cast<AST_Module>(rtn);
} }
...@@ -1068,6 +1073,9 @@ static ParseResult _reparse(const char* fn, const std::string& cache_fn, AST_Mod ...@@ -1068,6 +1073,9 @@ static ParseResult _reparse(const char* fn, const std::string& cache_fn, AST_Mod
// on the startup time (40ms -> 10ms). // on the startup time (40ms -> 10ms).
AST_Module* caching_parse_file(const char* fn) { AST_Module* caching_parse_file(const char* fn) {
STAT_TIMER(t0, "us_timer_caching_parse_file"); STAT_TIMER(t0, "us_timer_caching_parse_file");
static StatCounter us_parsing("us_parsing");
Timer _t("parsing");
_t.setExitCallback([](uint64_t t) { us_parsing.log(t); });
int code; int code;
std::string cache_fn = std::string(fn) + "c"; std::string cache_fn = std::string(fn) + "c";
......
...@@ -513,6 +513,7 @@ static const LineInfo* lineInfoForFrame(PythonFrameIteratorImpl& frame_it) { ...@@ -513,6 +513,7 @@ static const LineInfo* lineInfoForFrame(PythonFrameIteratorImpl& frame_it) {
return new LineInfo(current_stmt->lineno, current_stmt->col_offset, source->fn, source->getName()); return new LineInfo(current_stmt->lineno, current_stmt->col_offset, source->fn, source->getName());
} }
static StatCounter us_gettraceback("us_gettraceback");
BoxedTraceback* getTraceback() { BoxedTraceback* getTraceback() {
STAT_TIMER(t0, "us_timer_gettraceback"); STAT_TIMER(t0, "us_timer_gettraceback");
if (!ENABLE_FRAME_INTROSPECTION) { if (!ENABLE_FRAME_INTROSPECTION) {
...@@ -533,6 +534,8 @@ BoxedTraceback* getTraceback() { ...@@ -533,6 +534,8 @@ BoxedTraceback* getTraceback() {
return new BoxedTraceback(); return new BoxedTraceback();
} }
Timer _t("getTraceback", 1000);
std::vector<const LineInfo*> entries; std::vector<const LineInfo*> entries;
unwindPythonStack([&](std::unique_ptr<PythonFrameIteratorImpl> frame_iter) { unwindPythonStack([&](std::unique_ptr<PythonFrameIteratorImpl> frame_iter) {
const LineInfo* line_info = lineInfoForFrame(*frame_iter.get()); const LineInfo* line_info = lineInfoForFrame(*frame_iter.get());
...@@ -543,6 +546,9 @@ BoxedTraceback* getTraceback() { ...@@ -543,6 +546,9 @@ BoxedTraceback* getTraceback() {
std::reverse(entries.begin(), entries.end()); std::reverse(entries.begin(), entries.end());
long us = _t.end();
us_gettraceback.log(us);
return new BoxedTraceback(std::move(entries)); return new BoxedTraceback(std::move(entries));
} }
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
namespace pyston { namespace pyston {
#if !DISABLE_STATS #if !DISABLE_STATS
#if STAT_TIMERS
extern "C" const char* getStatTimerNameById(int id) { extern "C" const char* getStatTimerNameById(int id) {
return Stats::getStatName(id).c_str(); return Stats::getStatName(id).c_str();
} }
...@@ -116,6 +117,7 @@ StatTimer* StatTimer::swapStack(StatTimer* s, uint64_t at_time) { ...@@ -116,6 +117,7 @@ StatTimer* StatTimer::swapStack(StatTimer* s, uint64_t at_time) {
} }
return prev_stack; return prev_stack;
} }
#endif
std::vector<uint64_t>* Stats::counts; std::vector<uint64_t>* Stats::counts;
std::unordered_map<int, std::string>* Stats::names; std::unordered_map<int, std::string>* Stats::names;
......
...@@ -26,12 +26,12 @@ ...@@ -26,12 +26,12 @@
namespace pyston { namespace pyston {
#define STAT_ALLOCATIONS 0
#define DISABLE_STATS 0 #define DISABLE_STATS 0
#if !DISABLE_STATS #define STAT_ALLOCATIONS 0 && !DISABLE_STATS
#define STAT_TIMERS 0 && !DISABLE_STATS
#if STAT_TIMERS
#define STAT_TIMER(id, name) \ #define STAT_TIMER(id, name) \
static int _stid##id = Stats::getStatId(name); \ static int _stid##id = Stats::getStatId(name); \
StatTimer _st##id(_stid##id) StatTimer _st##id(_stid##id)
...@@ -80,6 +80,38 @@ public: ...@@ -80,6 +80,38 @@ public:
void log(uint64_t count = 1) { Stats::log(id, count); } void log(uint64_t count = 1) { Stats::log(id, count); }
}; };
struct StatPerThreadCounter {
private:
int id = 0;
public:
StatPerThreadCounter(const std::string& name);
void log(uint64_t count = 1) { Stats::log(id, count); }
};
#else
struct Stats {
static void startEstimatingCPUFreq() {}
static double estimateCPUFreq() { return 0; }
static void setEnabled(bool enabled) {}
static void dump(bool includeZeros = true) { printf("(Stats disabled)\n"); }
static void clear() {}
static void log(int id, int count = 1) {}
static int getStatId(const std::string& name) { return 0; }
static void endOfInit() {}
};
struct StatCounter {
StatCounter(const char* name) {}
void log(uint64_t count = 1){};
};
struct StatPerThreadCounter {
StatPerThreadCounter(const char* name) {}
void log(uint64_t count = 1){};
};
#endif
#if STAT_TIMERS
class StatTimer { class StatTimer {
private: private:
static __thread StatTimer* stack; static __thread StatTimer* stack;
...@@ -113,32 +145,7 @@ public: ...@@ -113,32 +145,7 @@ public:
static void assertActive() { RELEASE_ASSERT(stack && !stack->isPaused(), ""); } static void assertActive() { RELEASE_ASSERT(stack && !stack->isPaused(), ""); }
}; };
struct StatPerThreadCounter {
private:
int id = 0;
public:
StatPerThreadCounter(const std::string& name);
void log(uint64_t count = 1) { Stats::log(id, count); }
};
#else #else
struct Stats {
static void startEstimatingCPUFreq() {}
static double estimateCPUFreq() { return 0; }
static void setEnabled(bool enabled) {}
static void dump(bool includeZeros = true) { printf("(Stats disabled)\n"); }
static void clear() {}
static void log(int id, int count = 1) {}
static int getStatId(const std::string& name) { return 0; }
static void endOfInit() {}
};
struct StatCounter {
StatCounter(const char* name) {}
void log(uint64_t count = 1){};
};
struct StatTimer { struct StatTimer {
StatTimer(int statid, bool push = true) {} StatTimer(int statid, bool push = true) {}
StatTimer(int statid, uint64_t at_time) {} StatTimer(int statid, uint64_t at_time) {}
...@@ -152,10 +159,6 @@ struct StatTimer { ...@@ -152,10 +159,6 @@ struct StatTimer {
static StatTimer* swapStack(StatTimer* s, uint64_t at_time) { return NULL; } static StatTimer* swapStack(StatTimer* s, uint64_t at_time) { return NULL; }
static void assertActive() {} static void assertActive() {}
}; };
struct StatPerThreadCounter {
StatPerThreadCounter(const char* name) {}
void log(uint64_t count = 1){};
};
#endif #endif
} }
......
...@@ -346,6 +346,8 @@ void runCollection() { ...@@ -346,6 +346,8 @@ void runCollection() {
if (VERBOSITY("gc") >= 2) if (VERBOSITY("gc") >= 2)
printf("Collection #%d\n", ncollections); printf("Collection #%d\n", ncollections);
Timer _t("collecting", /*min_usec=*/10000);
markPhase(); markPhase();
std::list<Box*, StlCompatAllocator<Box*>> weakly_referenced; std::list<Box*, StlCompatAllocator<Box*>> weakly_referenced;
sweepPhase(weakly_referenced); sweepPhase(weakly_referenced);
...@@ -369,6 +371,10 @@ void runCollection() { ...@@ -369,6 +371,10 @@ void runCollection() {
if (VERBOSITY("gc") >= 2) if (VERBOSITY("gc") >= 2)
printf("Collection #%d done\n\n", ncollections); printf("Collection #%d done\n\n", ncollections);
long us = _t.end();
static StatCounter sc_us("gc_collections_us");
sc_us.log(us);
// dumpHeapStatistics(); // dumpHeapStatistics();
} }
......
...@@ -369,7 +369,7 @@ static int main(int argc, char** argv) { ...@@ -369,7 +369,7 @@ static int main(int argc, char** argv) {
uint64_t main_time_duration = main_time.end(&main_time_ended_at); uint64_t main_time_duration = main_time.end(&main_time_ended_at);
static StatCounter mt("ticks_in_main"); static StatCounter mt("ticks_in_main");
mt.log(main_time_duration); mt.log(main_time_duration);
_stt0.pause(main_time_ended_at); STAT_TIMER_NAME(t0).pause(main_time_ended_at);
} }
Stats::dump(true); Stats::dump(true);
......
...@@ -111,7 +111,7 @@ void generatorEntry(BoxedGenerator* g) { ...@@ -111,7 +111,7 @@ void generatorEntry(BoxedGenerator* g) {
g->entryExited = true; g->entryExited = true;
threading::popGenerator(); threading::popGenerator();
#if !DISABLE_STATS #if STAT_TIMERS
g->timer_time = getCPUTicks(); // store off the timer that our caller (in g->returnContext) will resume at g->timer_time = getCPUTicks(); // store off the timer that our caller (in g->returnContext) will resume at
STAT_TIMER_NAME(t0).pause(g->timer_time); STAT_TIMER_NAME(t0).pause(g->timer_time);
#endif #endif
...@@ -139,7 +139,7 @@ Box* generatorSend(Box* s, Box* v) { ...@@ -139,7 +139,7 @@ Box* generatorSend(Box* s, Box* v) {
self->returnValue = v; self->returnValue = v;
self->running = true; self->running = true;
#if !DISABLE_STATS #if STAT_TIMERS
// store off the time that the generator will use to initialize its toplevel timer // store off the time that the generator will use to initialize its toplevel timer
self->timer_time = getCPUTicks(); self->timer_time = getCPUTicks();
StatTimer* current_timers = StatTimer::swapStack(self->statTimers, self->timer_time); StatTimer* current_timers = StatTimer::swapStack(self->statTimers, self->timer_time);
...@@ -147,7 +147,7 @@ Box* generatorSend(Box* s, Box* v) { ...@@ -147,7 +147,7 @@ Box* generatorSend(Box* s, Box* v) {
swapContext(&self->returnContext, self->context, (intptr_t)self); swapContext(&self->returnContext, self->context, (intptr_t)self);
#if !DISABLE_STATS #if STAT_TIMERS
// if the generator exited we use the time that generatorEntry stored in self->timer_time (the same time it paused // if the generator exited we use the time that generatorEntry stored in self->timer_time (the same time it paused
// its timer at). // its timer at).
self->statTimers = StatTimer::swapStack(current_timers, self->entryExited ? self->timer_time : getCPUTicks()); self->statTimers = StatTimer::swapStack(current_timers, self->entryExited ? self->timer_time : getCPUTicks());
......
...@@ -2735,7 +2735,7 @@ static StatCounter slowpath_callfunc_slowpath("slowpath_callfunc_slowpath"); ...@@ -2735,7 +2735,7 @@ static StatCounter slowpath_callfunc_slowpath("slowpath_callfunc_slowpath");
Box* callFunc(BoxedFunctionBase* func, CallRewriteArgs* rewrite_args, ArgPassSpec argspec, Box* arg1, Box* arg2, Box* callFunc(BoxedFunctionBase* func, CallRewriteArgs* rewrite_args, ArgPassSpec argspec, Box* arg1, Box* arg2,
Box* arg3, Box** args, const std::vector<const std::string*>* keyword_names) { Box* arg3, Box** args, const std::vector<const std::string*>* keyword_names) {
#if !DISABLE_STATS #if STAT_TIMERS
StatTimer::assertActive(); StatTimer::assertActive();
#endif #endif
/* /*
......
...@@ -873,7 +873,7 @@ public: ...@@ -873,7 +873,7 @@ public:
struct Context* context, *returnContext; struct Context* context, *returnContext;
void* stack_begin; void* stack_begin;
#if !DISABLE_STATS #if STAT_TIMERS
StatTimer* statTimers; StatTimer* statTimers;
uint64_t timer_time; uint64_t timer_time;
#endif #endif
......
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