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>()}
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));
113 for (nlohmann::json &durations_json :
jsonData_->durations) {
114 for (
auto &&el : durations_json.items()) {
115 if (el.key().find(
"eval_task") != std::string::npos &&
118 else if (el.key().find(
"eval_partition") != std::string::npos &&
122 else if (el.key().find(
"metadata") != std::string::npos) {
123 jsonData_->metadata = durations_json[el.key()];
128 for (nlohmann::json &durations_json :
jsonData_->durations) {
129 durations_json.erase(
"metadata");
145 int gradient_start_t =
jsonData_->gradients[
"master:gradient"][analyzed_gradient * 2 - 2];
146 int gradient_end_t =
jsonData_->gradients[
"master:gradient"][analyzed_gradient * 2 - 1];
152 for (nlohmann::json &durations_json :
jsonData_->durations) {
154 auto partial_matrix =
158 for (
auto &&el : durations_json.items()) {
160 std::upper_bound(durations_json[el.key()].begin(), durations_json[el.key()].end(), gradient_start_t);
162 std::upper_bound(durations_json[el.key()].begin(), durations_json[el.key()].end(), gradient_end_t);
163 durations_json[el.key()].erase(end_interval, durations_json[el.key()].end());
164 durations_json[el.key()].erase(durations_json[el.key()].begin(), beg_interval);
172 for (
size_t idx = 0; idx < durations_json[eval_partition_name].size(); idx += 2) {
173 if (durations_json[eval_partition_name][idx + 1] > gradient_end_t ||
174 durations_json[eval_partition_name][idx] < gradient_start_t)
176 std::string task_name = findTaskForDuration(durations_json, durations_json[eval_partition_name][idx],
177 durations_json[eval_partition_name][idx + 1]);
179 if (task_name.empty())
184 int eval_partitions_idx =
187 partial_matrix->SetBinContent(eval_partitions_idx, tasks_idx,
188 durations_json[eval_partition_name][idx + 1].get<int>() -
189 durations_json[eval_partition_name][idx].get<int>());
193 total_matrix->Add(partial_matrix.get());
197 total_matrix->SetStats(
false);
200 TAxis *
y = total_matrix->GetYaxis();
201 TAxis *
x = total_matrix->GetXaxis();
202 for (std::size_t i = 0; i !=
tasks_names_.size(); ++i) {
204 y->ChangeLabel(i + 1, 30, 0.01, -1, -1, -1,
"");
208 x->ChangeLabel(i + 1, 30, -1, -1, -1, -1,
"");
210 x->LabelsOption(
"v");
227 std::vector<std::string> out;
228 for (
auto const &item :
jsonData_->metadata[0]) {
229 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