Working working working on adding profiling, also switched to multi-threaded profiler (slower but need it).

This commit is contained in:
KimLS
2015-01-31 19:06:14 -08:00
parent 2acf84ce4a
commit 444b652c4f
31 changed files with 409 additions and 392 deletions
+17 -4
View File
@@ -67,7 +67,7 @@ void EQP::CPU::ST::Profiler::Clear() {
current_ = root_;
}
void EQP::CPU::ST::Profiler::Dump(std::ostream &stream) {
void EQP::CPU::ST::Profiler::Dump(std::ostream &stream, int num) {
uint64_t total = 0;
std::vector<ProfilerNodeDump> sorted_vec;
sorted_vec.reserve(root_->GetNodes().size() + 1);
@@ -77,14 +77,21 @@ void EQP::CPU::ST::Profiler::Dump(std::ostream &stream) {
n.name = iter.first;
n.node = iter.second;
sorted_vec.push_back(n);
total += iter.second->GetTime();
}
std::sort(sorted_vec.begin(), sorted_vec.end(),
[](const ProfilerNodeDump& a, const ProfilerNodeDump& b) { return a.node->GetTime() > b.node->GetTime(); });
int i = 0;
for(auto &iter : sorted_vec) {
iter.node->Dump(stream, iter.name, total, 0);
if(num > 0 && i >= num) {
break;
}
iter.node->Dump(stream, iter.name, total, 0, num);
++i;
}
}
@@ -164,7 +171,7 @@ void EQP::CPU::MT::Profiler::Clear() {
imp_->lock_.unlock();
}
void EQP::CPU::MT::Profiler::Dump(std::ostream &stream) {
void EQP::CPU::MT::Profiler::Dump(std::ostream &stream, int num) {
imp_->lock_.lock();
for(auto &iter : imp_->nodes_) {
stream << "Thread: " << iter.first << std::endl;
@@ -177,14 +184,20 @@ void EQP::CPU::MT::Profiler::Dump(std::ostream &stream) {
n.name = t_iter.first;
n.node = t_iter.second;
sorted_vec.push_back(n);
total += t_iter.second->GetTime();
}
std::sort(sorted_vec.begin(), sorted_vec.end(),
[](const ProfilerNodeDump& a, const ProfilerNodeDump& b) { return a.node->GetTime() > b.node->GetTime(); });
int i = 0;
for(auto &t_iter : sorted_vec) {
t_iter.node->Dump(stream, t_iter.name, total, 1);
if(num > 0 && i >= num) {
break;
}
t_iter.node->Dump(stream, t_iter.name, total, 1, num);
++i;
}
stream << std::endl;
+2 -2
View File
@@ -29,7 +29,7 @@ namespace EQP
void EventStarted(const char *func, const char *name);
void EventFinished(uint64_t time);
void Clear();
void Dump(std::ostream &stream);
void Dump(std::ostream &stream, int num = 0);
private:
Node *root_;
Node *current_;
@@ -57,7 +57,7 @@ namespace EQP
void EventStarted(const char *func, const char *name);
void EventFinished(uint64_t time);
void Clear();
void Dump(std::ostream &stream);
void Dump(std::ostream &stream, int num = 0);
private:
struct impl;
impl *imp_;
+7 -2
View File
@@ -15,7 +15,7 @@ EQP::CPU::ProfilerNode::~ProfilerNode() {
}
}
void EQP::CPU::ProfilerNode::Dump(std::ostream &stream, const std::string &func, uint64_t total_time, int node_level) {
void EQP::CPU::ProfilerNode::Dump(std::ostream &stream, const std::string &func, uint64_t total_time, int node_level, int num) {
if(node_level >= 1) {
stream << std::setw(node_level * 2) << " ";
@@ -48,7 +48,12 @@ void EQP::CPU::ProfilerNode::Dump(std::ostream &stream, const std::string &func,
std::sort(sorted_vec.begin(), sorted_vec.end(),
[](const ProfilerNodeDump& a, const ProfilerNodeDump& b) { return a.node->GetTime() > b.node->GetTime(); });
int i = 0;
for(auto &iter : sorted_vec) {
iter.node->Dump(stream, iter.name, total_time, node_level + 1);
if(num > 0 && i >= num) {
break;
}
iter.node->Dump(stream, iter.name, total_time, node_level + 1, num);
++i;
}
}
+1 -1
View File
@@ -25,7 +25,7 @@ namespace EQP
inline std::unordered_map<std::string, ProfilerNode*>& GetNodes() { return nodes_; }
void Dump(std::ostream &stream, const std::string &func, uint64_t total_time, int node_level);
void Dump(std::ostream &stream, const std::string &func, uint64_t total_time, int node_level, int num);
private:
uint64_t count_;
uint64_t time_;