Skip to content

Commit

Permalink
More advanced statistics for MPI bytes in the tasktree data, includin…
Browse files Browse the repository at this point in the history
…g min, max, mode, median, stddev
  • Loading branch information
khuck committed Feb 3, 2023
1 parent f530fb3 commit b23673c
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 12 deletions.
48 changes: 41 additions & 7 deletions src/apex/dependency_tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -360,9 +360,39 @@ double Node::writeNodeCSV(std::stringstream& outfile, double total, int node_id)
// write any available metrics
for (auto& x : known_metrics) {
if (metric_map.find(x) == metric_map.end()) {
outfile << ",0";
outfile << ",,,,,,,";
} else {
outfile << "," << metric_map[x];
const auto& value = metric_map.find(x);
const auto& p = value->second.prof;
outfile << "," << p.accumulated;
outfile << "," << p.minimum;
double mean = p.accumulated/ncalls;
outfile << "," << mean;
outfile << "," << p.maximum;
// compute the standard deviation
double t1 = p.sum_squares / ncalls;
double t2 = mean * mean;
double t3 = t1 - t2;
variance = std::max(0.0,(t3));
stddev = sqrt(variance);
outfile << "," << stddev;
// find the median
auto& d = value->second.distribution;
// how many do we have?
size_t total = 0;
double mode = 0;
double median = 0;
size_t half = (size_t)(ncalls/2.0);
size_t most = 0;
for (auto& node : d) {
total += node.second;
if (total >= half) { median = node.first; break; }
}
for (auto& node : d) {
if (node.second > most) { mode = node.first; }
}
outfile << "," << median;
outfile << "," << mode;
}
}
// end the line
Expand All @@ -389,16 +419,20 @@ double Node::writeNodeCSV(std::stringstream& outfile, double total, int node_id)
void Node::addMetrics(std::map<std::string, double>& _metric_map) {
static std::mutex m;
for (auto& x: _metric_map) {
if (known_metrics.find(x.first) == known_metrics.end()) {
std::string name{x.first};
double value{x.second};
if (known_metrics.find(name) == known_metrics.end()) {
m.lock();
known_metrics.insert(x.first);
known_metrics.insert(name);
m.unlock();
}
m.lock();
if (metric_map.find(x.first) == metric_map.end()) {
metric_map[x.first] = x.second;
if (metric_map.find(name) == metric_map.end()) {
metricStorage newval(value);
metric_map.emplace(name, std::move(newval));
} else {
metric_map[x.first] += x.second;
auto element = metric_map.find(name);
element->second.increment(value);
}
m.unlock();
}
Expand Down
26 changes: 25 additions & 1 deletion src/apex/dependency_tree.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,30 @@ namespace apex {

namespace dependency {

class metricStorage {
public:
apex_profile prof;
std::map<double, size_t> distribution;
metricStorage(double value) {
prof.accumulated = value;
prof.maximum = value;
prof.minimum = value;
prof.sum_squares = value*value;
distribution[value] = 1;
}
void increment(double value) {
prof.accumulated += value;
prof.maximum = std::max<double>(prof.maximum, value);
prof.minimum = std::min<double>(prof.minimum, value);
prof.sum_squares += value*value;
if (distribution.find(value) == distribution.end()) {
distribution[value] = 1;
} else {
distribution[value] += 1;
}
}
};

class Node {
private:
task_identifier* data;
Expand All @@ -37,7 +61,7 @@ class Node {
std::set<uint64_t> thread_ids;
std::unordered_map<task_identifier, Node*> children;
// map for arbitrary metrics
std::map<std::string, double> metric_map;
std::map<std::string, metricStorage> metric_map;
static std::mutex treeMutex;
static std::atomic<size_t> nodeCount;
static std::set<std::string> known_metrics;
Expand Down
14 changes: 10 additions & 4 deletions src/apex/profiler_listener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1175,11 +1175,17 @@ std::unordered_set<profile*> free_profiles;
stringstream tree_stream;
if (node_id == 0) {
tree_stream << "\"process rank\",\"node index\",\"parent index\",\"depth\",";
tree_stream << "\"name\",\"calls\",\"threads\",\"accumulated\",";
tree_stream << "\"minimum\",\"mean\",\"maximum\",";
tree_stream << "\"sumsqr\"";
tree_stream << "\"name\",\"calls\",\"threads\",\"total time(ns)\",";
tree_stream << "\"minimum time(ns)\",\"mean time(ns)\",\"maximum time(ns)\",";
tree_stream << "\"stddev time(ns)\"";
for (auto& x : dependency::Node::getKnownMetrics()) {
tree_stream << ",\"" << x << "\"";
tree_stream << ",\"total " << x << "\"";
tree_stream << ",\"minimum " << x << "\"";
tree_stream << ",\"mean " << x << "\"";
tree_stream << ",\"maximum " << x << "\"";
tree_stream << ",\"stddev " << x << "\"";
tree_stream << ",\"median " << x << "\"";
tree_stream << ",\"mode " << x << "\"";
}
tree_stream << "\n";
}
Expand Down

0 comments on commit b23673c

Please sign in to comment.