detailed stracktrace only when option -d, second implemented in c++
This commit is contained in:
@@ -16,21 +16,32 @@ void MlPerfMon::turnOn() {
|
||||
start_time = std::chrono::high_resolution_clock::now();
|
||||
}
|
||||
|
||||
void MlPerfMon::debugOn() {
|
||||
debugStacktraceOn = true;
|
||||
}
|
||||
|
||||
void MlPerfMon::add_method_call(const MlValue &function, const std::vector<MlValue> &args) {
|
||||
// only main thread is logged, to prevent mixing from others threads so lock not needed
|
||||
if (main_thread_id != std::this_thread::get_id()) return;
|
||||
|
||||
std::string method = function.type == MlValue::LAMBDA ? "lambda" : function.str;
|
||||
|
||||
std::string args_string;
|
||||
for (size_t i = 0; i < args.size() && args_string.size() < 64; i++) {
|
||||
args_string.append(" ");
|
||||
args_string.append(args[i].display());
|
||||
}
|
||||
if (args_string.size() > 64)
|
||||
args_string = args_string.substr(0, 62) + ".."; // TODO introduce constant here
|
||||
if (debugStacktraceOn) {
|
||||
// call stack with more info
|
||||
std::string args_string;
|
||||
for (size_t i = 0; i < args.size() && args_string.size() < call_stack_args_str_len; i++) {
|
||||
args_string.append(" ");
|
||||
args_string.append(args[i].display());
|
||||
}
|
||||
if (args_string.size() > call_stack_args_str_len)
|
||||
args_string = args_string.substr(0, call_stack_args_str_len) + "..";
|
||||
else
|
||||
args_string.append(")");
|
||||
|
||||
call_stack.push_back("(" + method + args_string + ")");
|
||||
call_stack.push_back("(" + method + args_string);
|
||||
} else {
|
||||
call_stack.push_back(method);
|
||||
}
|
||||
|
||||
if (perfOn)
|
||||
calls_counter[method]++;
|
||||
@@ -57,7 +68,7 @@ std::string MlPerfMon::callstack() const {
|
||||
return cs.append("\n");
|
||||
}
|
||||
|
||||
size_t MlPerfMon::get_callstack_position() {
|
||||
size_t MlPerfMon::get_callstack_position() const {
|
||||
return call_stack.size();
|
||||
}
|
||||
|
||||
@@ -71,7 +82,7 @@ void MlPerfMon::clear_callstack() {
|
||||
call_stack.empty();
|
||||
}
|
||||
|
||||
void MlPerfMon::print_results() {
|
||||
void MlPerfMon::print_results() const {
|
||||
if (perfOn) {
|
||||
time_point<high_resolution_clock> end_time = high_resolution_clock::now();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user