callstack added
This commit is contained in:
@@ -2,9 +2,10 @@
|
||||
#include "ml_profiler.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <algorithm>
|
||||
// for linux gcc
|
||||
#include <iomanip>
|
||||
#include <numeric>
|
||||
#include <algorithm>
|
||||
|
||||
|
||||
using namespace std::chrono;
|
||||
@@ -15,6 +16,8 @@ void MlPerfMon::turnOn() {
|
||||
}
|
||||
|
||||
void MlPerfMon::add_method_call(const std::string &method) {
|
||||
call_stack.push_back(method);
|
||||
|
||||
if (perfOn) {
|
||||
auto search = calls_counter.find(method);
|
||||
if (search != calls_counter.end()) {
|
||||
@@ -25,6 +28,25 @@ void MlPerfMon::add_method_call(const std::string &method) {
|
||||
}
|
||||
}
|
||||
|
||||
void MlPerfMon::end_method_call() {
|
||||
if (!call_stack.empty()){
|
||||
call_stack.pop_back();
|
||||
}
|
||||
}
|
||||
|
||||
std::string MlPerfMon::callstack() const {
|
||||
std::string cs {"call stack:\n"};
|
||||
|
||||
int cnt = 0;
|
||||
for (auto it = call_stack.rbegin(); it != call_stack.rend() && cnt < call_stack_max_methods; ++it, ++cnt)
|
||||
cs.append( std::string(*it) + "\n"); // << std::endl;
|
||||
|
||||
if (call_stack.size() > call_stack_max_methods)
|
||||
cs.append("next " + std::to_string(call_stack.size() - call_stack_max_methods) + " entries skipped..\n");
|
||||
|
||||
return cs.append("\n");
|
||||
}
|
||||
|
||||
void MlPerfMon::print_results() {
|
||||
if (perfOn) {
|
||||
std::chrono::time_point<std::chrono::high_resolution_clock> end_time = std::chrono::high_resolution_clock::now();
|
||||
|
||||
Reference in New Issue
Block a user