stack trace at this moment only for main thread
This commit is contained in:
parent
0829f965be
commit
c17d43724a
|
|
@ -10,12 +10,18 @@
|
||||||
|
|
||||||
using namespace std::chrono;
|
using namespace std::chrono;
|
||||||
|
|
||||||
|
|
||||||
void MlPerfMon::turnOn() {
|
void MlPerfMon::turnOn() {
|
||||||
perfOn = true;
|
perfOn = true;
|
||||||
start_time = std::chrono::high_resolution_clock::now();
|
start_time = std::chrono::high_resolution_clock::now();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MlPerfMon::add_method_call(const std::string &method) {
|
void MlPerfMon::add_method_call(const std::string &method) {
|
||||||
|
std::thread::id this_id = std::this_thread::get_id();
|
||||||
|
// only main thread is logged, to prevent mixing from others threads so lock not needed
|
||||||
|
if (main_thread_id != this_id)
|
||||||
|
return;
|
||||||
|
|
||||||
call_stack.push_back(method);
|
call_stack.push_back(method);
|
||||||
|
|
||||||
if (perfOn) {
|
if (perfOn) {
|
||||||
|
|
@ -29,6 +35,11 @@ void MlPerfMon::add_method_call(const std::string &method) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void MlPerfMon::end_method_call() {
|
void MlPerfMon::end_method_call() {
|
||||||
|
std::thread::id this_id = std::this_thread::get_id();
|
||||||
|
// only main thread is looged, to prevent mixing from others threads so lock not needed
|
||||||
|
if (main_thread_id != this_id)
|
||||||
|
return;
|
||||||
|
|
||||||
if (!call_stack.empty()){
|
if (!call_stack.empty()){
|
||||||
call_stack.pop_back();
|
call_stack.pop_back();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,9 @@
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <deque>
|
#include <deque>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
|
#include <thread>
|
||||||
|
#include <mutex>
|
||||||
|
|
||||||
|
|
||||||
static const int method_name_print_len = 15;
|
static const int method_name_print_len = 15;
|
||||||
static const int print_top_methods = 15;
|
static const int print_top_methods = 15;
|
||||||
|
|
@ -13,7 +16,9 @@ static const int call_stack_max_methods = 10;
|
||||||
class MlPerfMon {
|
class MlPerfMon {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
MlPerfMon() : perfOn(false) {};
|
MlPerfMon() : perfOn(false) {
|
||||||
|
main_thread_id = std::this_thread::get_id();
|
||||||
|
};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
|
@ -36,4 +41,5 @@ private:
|
||||||
std::unordered_map<std::string, long> calls_counter;
|
std::unordered_map<std::string, long> calls_counter;
|
||||||
std::chrono::time_point<std::chrono::high_resolution_clock> start_time;
|
std::chrono::time_point<std::chrono::high_resolution_clock> start_time;
|
||||||
std::deque<std::string> call_stack;
|
std::deque<std::string> call_stack;
|
||||||
|
std::thread::id main_thread_id;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue