summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSascha Roloff <sascha.roloff@huawei.com>2023-02-23 22:03:12 +0100
committerSascha Roloff <sascha.roloff@huawei.com>2023-02-27 17:13:13 +0100
commit84b4ddc20e130ce54899f5e7c7a633fd19ecd05c (patch)
treea2d1520fb3bcec83892aed06d9466aa5a27969f8
parent5af0daee9cc9327c818fdd4234f3af4eb109fa5f (diff)
downloadjustbuild-84b4ddc20e130ce54899f5e7c7a633fd19ecd05c.tar.gz
Progress reporting: Add progress reporter classes for just-mr
-rw-r--r--src/other_tools/just_mr/progress_reporting/TARGETS23
-rw-r--r--src/other_tools/just_mr/progress_reporting/progress.hpp49
-rw-r--r--src/other_tools/just_mr/progress_reporting/progress_reporter.cpp63
-rw-r--r--src/other_tools/just_mr/progress_reporting/progress_reporter.hpp25
4 files changed, 160 insertions, 0 deletions
diff --git a/src/other_tools/just_mr/progress_reporting/TARGETS b/src/other_tools/just_mr/progress_reporting/TARGETS
index b253d68d..b8dc61b7 100644
--- a/src/other_tools/just_mr/progress_reporting/TARGETS
+++ b/src/other_tools/just_mr/progress_reporting/TARGETS
@@ -4,4 +4,27 @@
, "hdrs": ["statistics.hpp"]
, "stage": ["src", "other_tools", "just_mr", "progress_reporting"]
}
+, "progress":
+ { "type": ["@", "rules", "CC", "library"]
+ , "name": ["progress"]
+ , "hdrs": ["progress.hpp"]
+ , "stage": ["src", "other_tools", "just_mr", "progress_reporting"]
+ , "deps": [["src/buildtool/progress_reporting", "task_tracker"]]
+ }
+, "progress_reporter":
+ { "type": ["@", "rules", "CC", "library"]
+ , "name": ["progress_reporter"]
+ , "hdrs": ["progress_reporter.hpp"]
+ , "srcs": ["progress_reporter.cpp"]
+ , "stage": ["src", "other_tools", "just_mr", "progress_reporting"]
+ , "deps": [["src/buildtool/progress_reporting", "base_progress_reporter"]]
+ , "private-deps":
+ [ "progress"
+ , "statistics"
+ , ["@", "fmt", "", "fmt"]
+ , ["@", "json", "", "json"]
+ , ["@", "gsl-lite", "", "gsl-lite"]
+ , ["src/buildtool/logging", "logging"]
+ ]
+ }
}
diff --git a/src/other_tools/just_mr/progress_reporting/progress.hpp b/src/other_tools/just_mr/progress_reporting/progress.hpp
new file mode 100644
index 00000000..5d641673
--- /dev/null
+++ b/src/other_tools/just_mr/progress_reporting/progress.hpp
@@ -0,0 +1,49 @@
+// Copyright 2022 Huawei Cloud Computing Technology Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#ifndef INCLUDED_SRC_OTHER_TOOLS_JUST_MR_PROGRESS_REPORTING_PROGRESS_HPP
+#define INCLUDED_SRC_OTHER_TOOLS_JUST_MR_PROGRESS_REPORTING_PROGRESS_HPP
+
+#include <cstdlib>
+#include <string>
+#include <unordered_set>
+#include <utility>
+#include <vector>
+
+#include "src/buildtool/progress_reporting/task_tracker.hpp"
+
+class JustMRProgress {
+ public:
+ [[nodiscard]] static auto Instance() noexcept -> JustMRProgress& {
+ static JustMRProgress instance{};
+ return instance;
+ }
+
+ [[nodiscard]] auto TaskTracker() noexcept -> TaskTracker& {
+ return task_tracker_;
+ }
+
+ // Return a reference to the repository set. It is the responsibility of the
+ // caller to ensure that access only happens in a single-threaded context.
+ [[nodiscard]] auto RepositorySet() noexcept
+ -> std::unordered_set<std::string>& {
+ return repo_set_;
+ }
+
+ private:
+ ::TaskTracker task_tracker_{};
+ std::unordered_set<std::string> repo_set_{};
+};
+
+#endif // INCLUDED_SRC_OTHER_TOOLS_JUST_MR_PROGRESS_REPORTING_PROGRESS_HPP
diff --git a/src/other_tools/just_mr/progress_reporting/progress_reporter.cpp b/src/other_tools/just_mr/progress_reporting/progress_reporter.cpp
new file mode 100644
index 00000000..8f313714
--- /dev/null
+++ b/src/other_tools/just_mr/progress_reporting/progress_reporter.cpp
@@ -0,0 +1,63 @@
+// Copyright 2023 Huawei Cloud Computing Technology Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#include "src/other_tools/just_mr/progress_reporting/progress_reporter.hpp"
+
+#include <optional>
+#include <string>
+
+#include "fmt/core.h"
+#include "gsl-lite/gsl-lite.hpp"
+#include "nlohmann/json.hpp"
+#include "src/buildtool/logging/log_level.hpp"
+#include "src/buildtool/logging/logger.hpp"
+#include "src/other_tools/just_mr/progress_reporting/progress.hpp"
+#include "src/other_tools/just_mr/progress_reporting/statistics.hpp"
+
+auto JustMRProgressReporter::Reporter() noexcept -> progress_reporter_t {
+ return BaseProgressReporter::Reporter([]() {
+ int total =
+ gsl::narrow<int>(JustMRProgress::Instance().RepositorySet().size());
+ // Note: order of stats queries matters!
+ auto const& sample = JustMRProgress::Instance().TaskTracker().Sample();
+ auto const& stats = JustMRStatistics::Instance();
+ int local = stats.LocalPathsCounter();
+ int cached = stats.CacheHitsCounter();
+ int run = stats.ExecutedCounter();
+ int queued = stats.QueuedCounter();
+ int active = queued - run;
+ std::string msg;
+ if (active > 0 and !sample.empty()) {
+ auto const& repo_set = JustMRProgress::Instance().RepositorySet();
+ if (repo_set.find(sample) != repo_set.end()) {
+ msg = fmt::format(
+ "{} local roots, {} cached, {} run, {} processing "
+ "({}{})",
+ local,
+ cached,
+ run,
+ active,
+ nlohmann::json(sample).dump(),
+ active > 1 ? ", ..." : "");
+ }
+ }
+ constexpr int kOneHundred{100};
+ int total_work = total - cached - local;
+ int progress = kOneHundred; // default if no work has to be done
+ if (total_work > 0) {
+ progress = run * kOneHundred / total_work;
+ }
+ Logger::Log(LogLevel::Progress, "[{:3}%] {}", progress, msg);
+ });
+}
diff --git a/src/other_tools/just_mr/progress_reporting/progress_reporter.hpp b/src/other_tools/just_mr/progress_reporting/progress_reporter.hpp
new file mode 100644
index 00000000..e70b9b33
--- /dev/null
+++ b/src/other_tools/just_mr/progress_reporting/progress_reporter.hpp
@@ -0,0 +1,25 @@
+// Copyright 2023 Huawei Cloud Computing Technology Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#ifndef INCLUDED_SRC_OTHER_TOOLS_JUST_MR_PROGRESS_REPORTING_PROGRESS_REPORTER_HPP
+#define INCLUDED_SRC_OTHER_TOOLS_JUST_MR_PROGRESS_REPORTING_PROGRESS_REPORTER_HPP
+
+#include "src/buildtool/progress_reporting/base_progress_reporter.hpp"
+
+class JustMRProgressReporter {
+ public:
+ [[nodiscard]] static auto Reporter() noexcept -> progress_reporter_t;
+};
+
+#endif // INCLUDED_SRC_OTHER_TOOLS_JUST_MR_PROGRESS_REPORTING_PROGRESS_REPORTER_HPP