Skip to content

Commit

Permalink
Adding task tree ASCII output, for issue #150
Browse files Browse the repository at this point in the history
  • Loading branch information
khuck committed May 12, 2021
1 parent 8498e6a commit 471e1b4
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/apex/dependency_tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#include "dependency_tree.hpp"
#include "utils.hpp"
#include <iomanip>
#include <sstream>
#include <math.h>

namespace apex {

Expand Down Expand Up @@ -90,11 +92,47 @@ void Node::writeNode(std::ofstream& outfile, double total) {
}
}

void Node::writeNodeASCII(double total, size_t indent) {
for (size_t i = 0 ; i < indent ; i++) {
std::cout << "| ";
}
indent++;
// Write out the name
std::cout << data->get_short_name() << ": ";
// write out the inclusive and percent of total
const std::string apex_main_str("APEX MAIN");
double acc = (data == task_identifier::get_task_id(apex_main_str)) ?
total : accumulated;
double percentage = (accumulated / total) * 100.0;
std::cout << std::setprecision(5) << acc << " - "
<< std::setprecision(4) << percentage << "% [";
// write the number of calls
double ncalls = (calls == 0) ? 1 : calls;
std::cout << ncalls << "]";
// write other stats - min, max, stddev
double mean = acc / ncalls;
double variance = ((sumsqr / ncalls) - (mean * mean));
double stddev = sqrt(variance);
std::cout << " {min=" << std::setprecision(4) << min << ", max=" << max
<< ", mean=" << mean << ", var=" << variance
<< ", std dev=" << stddev << "}";
// end the line
std::cout << std::endl;

// do all the children
for (auto c : children) {
c.second->writeNodeASCII(acc, indent);
}
}

void Node::addAccumulated(double value, bool is_resume) {
static std::mutex m;
m.lock();
if (!is_resume) { calls+=1; }
accumulated = accumulated + value;
if (min == 0.0 || value < min) { min = value; }
if (value > max) { max = value; }
sumsqr = sumsqr + (value*value);
m.unlock();
}

Expand Down
4 changes: 4 additions & 0 deletions src/apex/dependency_tree.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ class Node {
size_t count;
double calls;
double accumulated;
double min;
double max;
double sumsqr;
size_t index;
std::unordered_map<task_identifier, Node*> children;
static std::mutex treeMutex;
Expand All @@ -48,6 +51,7 @@ class Node {
void addAccumulated(double value, bool is_resume);
size_t getIndex() { return index; };
void writeNode(std::ofstream& outfile, double total);
void writeNodeASCII(double total, size_t indent);
};

} // dependency_tree
Expand Down
4 changes: 4 additions & 0 deletions src/apex/profiler_listener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1012,6 +1012,10 @@ std::unordered_set<profile*> free_profiles;
root->tree_node->writeNode(myfile, wall_clock_main);
myfile << "}\n";
myfile.close();
// dump the tree to the screen, for now
std::cout << std::endl;
root->tree_node->writeNodeASCII(wall_clock_main, 0);
std::cout << std::endl;
}

/* Write TAU profiles from the collected data. */
Expand Down
19 changes: 19 additions & 0 deletions src/apex/task_identifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,25 @@ std::mutex bfd_mutex;
the program exits and the pointers aren't needed any more. */
}

std::string task_identifier::get_short_name() {
std::string shorter(get_name(true));
size_t trim_at = shorter.find("(");
if (trim_at != std::string::npos) {
shorter = shorter.substr(0, trim_at);
}
trim_at = shorter.find("<");
if (trim_at != std::string::npos) {
shorter = shorter.substr(0, trim_at);
}
size_t maxlength = 50;
// to keep formatting pretty, trim any long timer names
if (shorter.size() > maxlength) {
shorter.resize(maxlength-3);
shorter.resize(maxlength, '.');
}
return shorter;
}

std::string task_identifier::get_name(bool resolve) {
if (!has_name && resolve) {
if (_resolved_name == "" && address != APEX_NULL_FUNCTION_ADDRESS) {
Expand Down
1 change: 1 addition & 0 deletions src/apex/task_identifier.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class task_identifier {
static task_identifier * get_task_id (apex_function_address a);
static task_identifier * get_task_id (const std::string& n);
std::string get_name(bool resolve = true);
std::string get_short_name();
~task_identifier() { }
// requried for using this class as a key in an unordered map.
// the hash function is defined below.
Expand Down

0 comments on commit 471e1b4

Please sign in to comment.