diff options
author | Paul Cristian Sarbu <paul.cristian.sarbu@huawei.com> | 2022-12-19 16:28:44 +0100 |
---|---|---|
committer | Sascha Roloff <sascha.roloff@huawei.com> | 2023-02-27 13:27:57 +0100 |
commit | 5af0daee9cc9327c818fdd4234f3af4eb109fa5f (patch) | |
tree | b071ae370f27f6c21913f761890a3112a4ed2ca4 /src | |
parent | 1d161c56520ba66d7467ad6ef909cc88bdefb8fd (diff) | |
download | justbuild-5af0daee9cc9327c818fdd4234f3af4eb109fa5f.tar.gz |
Progress reporting: Add statistics class for just-mr
Diffstat (limited to 'src')
-rw-r--r-- | src/other_tools/just_mr/progress_reporting/TARGETS | 7 | ||||
-rw-r--r-- | src/other_tools/just_mr/progress_reporting/statistics.hpp | 58 |
2 files changed, 65 insertions, 0 deletions
diff --git a/src/other_tools/just_mr/progress_reporting/TARGETS b/src/other_tools/just_mr/progress_reporting/TARGETS new file mode 100644 index 00000000..b253d68d --- /dev/null +++ b/src/other_tools/just_mr/progress_reporting/TARGETS @@ -0,0 +1,7 @@ +{ "statistics": + { "type": ["@", "rules", "CC", "library"] + , "name": ["statistics"] + , "hdrs": ["statistics.hpp"] + , "stage": ["src", "other_tools", "just_mr", "progress_reporting"] + } +} diff --git a/src/other_tools/just_mr/progress_reporting/statistics.hpp b/src/other_tools/just_mr/progress_reporting/statistics.hpp new file mode 100644 index 00000000..efdce7f5 --- /dev/null +++ b/src/other_tools/just_mr/progress_reporting/statistics.hpp @@ -0,0 +1,58 @@ +// 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_STATISTICS_HPP +#define INCLUDED_SRC_OTHER_TOOLS_JUST_MR_PROGRESS_REPORTING_STATISTICS_HPP + +#include <atomic> + +class JustMRStatistics { + public: + [[nodiscard]] static auto Instance() noexcept -> JustMRStatistics& { + static JustMRStatistics instance{}; + return instance; + } + + void Reset() noexcept { + num_local_paths_ = 0; + num_cache_hits_ = 0; + num_queued_ = 0; + num_executed_ = 0; + } + void IncrementLocalPathsCounter() noexcept { ++num_local_paths_; } + void IncrementCacheHitsCounter() noexcept { ++num_cache_hits_; } + void IncrementQueuedCounter() noexcept { ++num_queued_; } + void IncrementExecutedCounter() noexcept { ++num_executed_; } + + [[nodiscard]] auto LocalPathsCounter() const noexcept -> int { + return num_local_paths_; + } + [[nodiscard]] auto CacheHitsCounter() const noexcept -> int { + return num_cache_hits_; + } + [[nodiscard]] auto QueuedCounter() const noexcept -> int { + return num_queued_; + } + [[nodiscard]] auto ExecutedCounter() const noexcept -> int { + return num_executed_; + } + + private: + std::atomic<int> num_local_paths_{}; // roots that are actual paths + std::atomic<int> num_cache_hits_{}; // no-ops + std::atomic<int> num_queued_{}; // actual work queued + std::atomic<int> num_executed_{}; // actual work done +}; + +#endif // INCLUDED_SRC_OTHER_TOOLS_JUST_MR_PROGRESS_REPORTING_STATISTICS_HPP |