added runtime in ms to -p option
This commit is contained in:
@@ -3,10 +3,14 @@
|
||||
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#include <numeric>
|
||||
|
||||
|
||||
using namespace std::chrono;
|
||||
|
||||
void MlPerfMon::turnOn() {
|
||||
perfOn = true;
|
||||
|
||||
start_time = std::chrono::high_resolution_clock::now();
|
||||
}
|
||||
|
||||
void MlPerfMon::add_method_call(const std::string &method) {
|
||||
@@ -22,21 +26,32 @@ void MlPerfMon::add_method_call(const std::string &method) {
|
||||
|
||||
void MlPerfMon::print_results() {
|
||||
if (perfOn) {
|
||||
std::cerr << std::endl << std::endl << "Call Frequency" << std::endl;
|
||||
std::chrono::time_point<std::chrono::high_resolution_clock> end_time = std::chrono::high_resolution_clock::now();
|
||||
|
||||
using callcount = std::pair<std::string, long>;
|
||||
|
||||
std::vector<callcount> v(begin(calls_counter), end(calls_counter));
|
||||
std::sort(std::begin(v), std::end(v), [](const callcount& a, const callcount& b) { return a.second > b.second; });
|
||||
long total_calls = 0;
|
||||
for(auto const& c : v) { total_calls += c.second; }
|
||||
|
||||
std::cerr << std::endl << std::endl;
|
||||
std::cerr << "perf stats" << std::endl;
|
||||
std::cerr << "run time : " << duration_cast<milliseconds>(end_time - start_time).count() << " ms " << std::endl;
|
||||
std::cerr << "total calls : " << total_calls << std::endl;
|
||||
std::cerr << "methods called : " << calls_counter.size() << std::endl;
|
||||
std::cerr << std::endl;
|
||||
|
||||
int i {0};
|
||||
for(auto &p : v) {
|
||||
// TODO when method name longer than 15 chars, here it crashes
|
||||
p.first.insert(p.first.end(), 15 - p.first.size(), ' ');
|
||||
if (p.first.size() >= method_name_print_len)
|
||||
p.first.erase(method_name_print_len, std::string::npos);
|
||||
else
|
||||
p.first.insert(p.first.end(), method_name_print_len - p.first.size(), ' ');
|
||||
|
||||
std::cerr << p.first << " " << p.second << std::endl;
|
||||
|
||||
i++;
|
||||
if (i > 10) break;
|
||||
if (i > print_top_methods) break;
|
||||
}
|
||||
|
||||
std::cerr << std::endl;
|
||||
|
||||
Reference in New Issue
Block a user