detailed stracktrace only when option -d, second implemented in c++

This commit is contained in:
2021-10-11 12:04:49 +02:00
parent b68987fdd7
commit ecbc3af789
6 changed files with 38 additions and 47 deletions

View File

@@ -12,37 +12,40 @@
static const int method_name_print_len = 15;
static const int print_top_methods = 15;
static const int call_stack_max_methods = 10;
static const int call_stack_args_str_len = 64;
class MlPerfMon {
private:
MlPerfMon() : perfOn(false) {
MlPerfMon() : perfOn(false), debugStacktraceOn(false) {
main_thread_id = std::this_thread::get_id();
};
public:
// https://stackoverflow.com/questions/43523509/simple-singleton-example-in-c
static MlPerfMon& instance(){
static MlPerfMon& instance() {
static MlPerfMon instance;
return instance;
}
void turnOn();
void debugOn();
void add_method_call(const MlValue &function, const std::vector<MlValue> &args);
void end_method_call();
std::string callstack() const;
size_t get_callstack_position();
size_t get_callstack_position() const;
void restore_callstack_position(size_t to_position);
void clear_callstack();
void print_results();
void print_results() const;
private:
bool perfOn;
bool debugStacktraceOn;
std::unordered_map<std::string, long> calls_counter;
std::chrono::time_point<std::chrono::high_resolution_clock> start_time;
std::deque<std::string> call_stack;