dag_node.cpp 2.36 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
#include "pls/internal/profiling/dag_node.h"

#include <algorithm>

namespace pls::internal::profiling {

void dag_node::dag_compact() {
  while (next_node_ && next_node_->child_nodes_.empty()) {
    max_memory_ = std::max(max_memory_, next_node_->max_memory_);
    total_runtime_ += next_node_->total_runtime_;
    next_node_ = std::move(next_node_->next_node_);
  }
  if (next_node_) {
    next_node_->dag_compact();
  }

  for (auto &child : child_nodes_) {
    child.dag_compact();
  }
}

void dag_node::dag_print(std::ostream &stream, unsigned rank) {
FritzFlorian committed
23 24 25 26 27
  stream << node_print_id()
         << " [label=\"" << spawning_thread_id_ << "\n"
         << max_memory_ << " bytes\n"
         << m_to_d(total_runtime_) << " us\""
         << " ,rank=" << rank << "];" << std::endl;
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
  for (auto &child : child_nodes_) {
    child.dag_print(stream, rank + 1);
    stream << node_print_id() << " -> " << child.node_print_id() << ";" << std::endl;
  }
  if (next_node_) {
    next_node_->dag_print(stream, rank);
    stream << node_print_id() << " -> " << next_node_->node_print_id() << ";" << std::endl;
  }
}

unsigned dag_node::dag_max_memory() {
  unsigned max = max_memory_;
  if (next_node_) {
    max = std::max(max, next_node_->dag_max_memory());
  }
  for (auto &child : child_nodes_) {
    max = std::max(max, child.dag_max_memory());
  }
  return max;
}

unsigned long dag_node::dag_total_user_time() {
  unsigned long total_user_time = total_runtime_;
  if (next_node_) {
    total_user_time += next_node_->dag_total_user_time();
  }
  for (auto &child : child_nodes_) {
    total_user_time += child.dag_total_user_time();
  }
  return total_user_time;
}

unsigned long dag_node::dag_critical_path() {
  unsigned long critical_path = total_runtime_;
  if (next_node_) {
    critical_path += next_node_->dag_critical_path();
  }

  unsigned long slowest_child = 0;
  for (auto &child : child_nodes_) {
    slowest_child = std::max(slowest_child, child.dag_critical_path());
  }
  critical_path += slowest_child;

  return critical_path;
}

FritzFlorian committed
75 76 77 78 79 80 81 82 83 84 85 86 87 88
unsigned long dag_node::dag_depth() {
  unsigned long deepest_at_level = 1;
  if (next_node_) {
    deepest_at_level = std::max(deepest_at_level, next_node_->dag_depth());
  }

  unsigned long deepest_child = 0;
  for (auto &child : child_nodes_) {
    deepest_child = std::max(deepest_child, child.dag_depth());
  }

  return std::max(deepest_child + 1, deepest_at_level);
}

89
}