18#include <nlohmann/json.hpp>
23namespace MultiProcess {
37void sortTaskNames(std::vector<std::string> &task_names)
39 char const *digits =
"0123456789";
40 std::vector<int> digit_vec;
41 std::vector<std::pair<int, std::string>> pair_vec;
42 for (
auto &&el : task_names) {
43 std::size_t
const n = el.find_first_of(digits);
44 pair_vec.push_back(std::make_pair(stoi(el.substr(
n)), el));
47 std::sort(pair_vec.begin(), pair_vec.end());
49 for (
size_t i = 0; i < task_names.size(); i++) {
50 task_names[i] = pair_vec[i].second;
54std::string findTaskForDuration(nlohmann::json durations,
int start_t,
int end_t)
56 for (
auto &&el : durations.items()) {
57 if (el.key().find(
"eval_partition") != std::string::npos)
60 for (
size_t idx = 0; idx < durations[el.key()].
size(); idx += 2) {
61 if (durations[el.key()][idx] <= start_t && durations[el.key()][idx + 1] >= end_t) {
96 : jsonData_{std::make_unique<Detail::HeatmapAnalyzerJsonData>()}
101 for (
TObject *file : *durationFiles) {
102 if (std::string(file->GetName()).find(
"p_") == std::string::npos)
105 std::ifstream
f(logs_dir +
"/" + std::string(file->GetName()));
107 if (std::string(file->GetName()).find(
"999") != std::string::npos) {
108 jsonData_->gradients = nlohmann::json::parse(
f);
110 jsonData_->durations.push_back(nlohmann::json::parse(
f));
114 for (nlohmann::json &durations_json :
jsonData_->durations) {
115 for (
auto &&el : durations_json.items()) {
116 if (el.key().find(
"eval_task") != std::string::npos &&
119 }
else if (el.key().find(
"eval_partition") != std::string::npos &&
123 }
else if (el.key().find(
"metadata") != std::string::npos) {
124 jsonData_->metadata = durations_json[el.key()];
129 for (nlohmann::json &durations_json :
jsonData_->durations) {
130 durations_json.erase(
"metadata");
146 int gradient_start_t =
jsonData_->gradients[
"master:gradient"][analyzed_gradient * 2 - 2];
147 int gradient_end_t =
jsonData_->gradients[
"master:gradient"][analyzed_gradient * 2 - 1];
153 for (nlohmann::json &durations_json :
jsonData_->durations) {
155 auto partial_matrix =
159 for (
auto &&el : durations_json.items()) {
161 std::upper_bound(durations_json[el.key()].begin(), durations_json[el.key()].end(), gradient_start_t);
163 std::upper_bound(durations_json[el.key()].begin(), durations_json[el.key()].end(), gradient_end_t);
164 durations_json[el.key()].erase(end_interval, durations_json[el.key()].end());
165 durations_json[el.key()].erase(durations_json[el.key()].begin(), beg_interval);
173 for (
size_t idx = 0; idx < durations_json[eval_partition_name].size(); idx += 2) {
174 if (durations_json[eval_partition_name][idx + 1] > gradient_end_t ||
175 durations_json[eval_partition_name][idx] < gradient_start_t)
177 std::string task_name = findTaskForDuration(durations_json, durations_json[eval_partition_name][idx],
178 durations_json[eval_partition_name][idx + 1]);
180 if (task_name.empty())
185 int eval_partitions_idx =
188 partial_matrix->SetBinContent(eval_partitions_idx, tasks_idx,
189 durations_json[eval_partition_name][idx + 1].get<int>() -
190 durations_json[eval_partition_name][idx].get<int>());
194 total_matrix->Add(partial_matrix.get());
198 total_matrix->SetStats(
false);
201 TAxis *
y = total_matrix->GetYaxis();
202 TAxis *
x = total_matrix->GetXaxis();
203 for (std::size_t i = 0; i !=
tasks_names_.size(); ++i) {
205 y->ChangeLabel(i + 1, 30, 0.01, -1, -1, -1,
"");
209 x->ChangeLabel(i + 1, 30, -1, -1, -1, -1,
"");
211 x->LabelsOption(
"v");
228 std::vector<std::string> out;
229 for (
auto const &item :
jsonData_->metadata[0]) {
230 out.emplace_back(item.get<std::string>());
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
std::unique_ptr< TH2I > analyze(int analyzed_gradient)
This method is the main functionality in this class.
std::vector< std::string > const getMetadata()
std::vector< std::string > const getPartitionNames()
std::vector< std::string > const getTaskNames()
HeatmapAnalyzer(std::string const &logs_dir)
HeatmapAnalyzer Constructor.
std::vector< std::string > tasks_names_
std::unique_ptr< Detail::HeatmapAnalyzerJsonData > jsonData_
std::vector< std::string > eval_partitions_names_
Class to manage histogram axis.
virtual void SetBinLabel(Int_t bin, const char *label)
Set label for bin.
Mother of all ROOT objects.
Describes an Operating System directory for the browser.
virtual TList * GetListOfFiles() const
Returns a TList of TSystemFile objects representing the contents of the directory.
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
std::vector< nlohmann::json > durations