diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/buildtool/execution_engine/executor/executor.hpp | 4 | ||||
-rw-r--r-- | src/buildtool/progress_reporting/TARGETS | 12 | ||||
-rw-r--r-- | src/buildtool/progress_reporting/base_progress_reporter.cpp | 3 | ||||
-rw-r--r-- | src/buildtool/progress_reporting/progress.hpp | 49 | ||||
-rw-r--r-- | src/buildtool/progress_reporting/task_tracker.hpp | 64 |
5 files changed, 87 insertions, 45 deletions
diff --git a/src/buildtool/execution_engine/executor/executor.hpp b/src/buildtool/execution_engine/executor/executor.hpp index cd9246ba..baf0be12 100644 --- a/src/buildtool/execution_engine/executor/executor.hpp +++ b/src/buildtool/execution_engine/executor/executor.hpp @@ -88,7 +88,7 @@ class ExecutorImpl { // do not count statistics for rebuilder fetching from cache if (cache_flag != IExecutionAction::CacheFlag::FromCacheOnly) { - Progress::Instance().Start(action->Content().Id()); + Progress::Instance().TaskTracker().Start(action->Content().Id()); Statistics::Instance().IncrementActionsQueuedCounter(); } @@ -459,7 +459,7 @@ class ExecutorImpl { else { Statistics::Instance().IncrementActionsExecutedCounter(); } - Progress::Instance().Stop(action->Content().Id()); + Progress::Instance().TaskTracker().Stop(action->Content().Id()); PrintInfo(logger, action->Command(), response); bool should_fail_outputs = false; diff --git a/src/buildtool/progress_reporting/TARGETS b/src/buildtool/progress_reporting/TARGETS index 803507fd..23f4bc37 100644 --- a/src/buildtool/progress_reporting/TARGETS +++ b/src/buildtool/progress_reporting/TARGETS @@ -4,11 +4,17 @@ , "hdrs": ["progress.hpp"] , "stage": ["src", "buildtool", "progress_reporting"] , "deps": - [ ["src/buildtool/build_engine/target_map", "configured_target"] - , ["src/buildtool/logging", "logging"] - , ["@", "fmt", "", "fmt"] + [ "task_tracker" + , ["src/buildtool/build_engine/target_map", "configured_target"] ] } +, "task_tracker": + { "type": ["@", "rules", "CC", "library"] + , "name": ["task_tracker"] + , "hdrs": ["task_tracker.hpp"] + , "stage": ["src", "buildtool", "progress_reporting"] + , "deps": [["src/buildtool/logging", "logging"]] + } , "base_progress_reporter": { "type": ["@", "rules", "CC", "library"] , "name": ["base_progress_reporter"] diff --git a/src/buildtool/progress_reporting/base_progress_reporter.cpp b/src/buildtool/progress_reporting/base_progress_reporter.cpp index d0ac1b85..6bc72d86 100644 --- a/src/buildtool/progress_reporting/base_progress_reporter.cpp +++ b/src/buildtool/progress_reporting/base_progress_reporter.cpp @@ -36,7 +36,8 @@ auto BaseProgressReporter::Reporter() -> GraphTraverser::progress_reporter_t { cv->wait_for(lock, std::chrono::milliseconds(delay)); if (not *done) { // Note: order matters; queued has to be queried last - std::string sample = Progress::Instance().Sample(); + std::string sample = + Progress::Instance().TaskTracker().Sample(); int cached = stats.ActionsCachedCounter(); int run = stats.ActionsExecutedCounter(); int queued = stats.ActionsQueuedCounter(); diff --git a/src/buildtool/progress_reporting/progress.hpp b/src/buildtool/progress_reporting/progress.hpp index 1e18a5ec..43cdc7cc 100644 --- a/src/buildtool/progress_reporting/progress.hpp +++ b/src/buildtool/progress_reporting/progress.hpp @@ -15,15 +15,14 @@ #ifndef INCLUDED_SRC_BUILDTOOL_PROGRESS_REPORTING_PROGRESS_HPP #define INCLUDED_SRC_BUILDTOOL_PROGRESS_REPORTING_PROGRESS_HPP -#include <cstdint> -#include <mutex> +#include <cstdlib> #include <string> #include <unordered_map> #include <utility> #include <vector> #include "src/buildtool/build_engine/target_map/configured_target.hpp" -#include "src/buildtool/logging/logger.hpp" +#include "src/buildtool/progress_reporting/task_tracker.hpp" class Progress { public: @@ -32,39 +31,13 @@ class Progress { return instance; } - void Start(const std::string& id) noexcept { - std::unique_lock lock(m_); - ++prio_; - try { - running_.emplace(id, prio_); - } catch (...) { - Logger::Log(LogLevel::Warning, - "Internal error in progress tracking; progress reports " - "might be incorrect."); - } - } - void Stop(const std::string& id) noexcept { - std::unique_lock lock(m_); - running_.erase(id); - } - - auto Sample() -> std::string { - std::unique_lock lock(m_); - std::string result; - uint64_t started = prio_ + 1; - for (auto const& it : running_) { - if (it.second < started) { - result = it.first; - started = it.second; - } - } - return result; + [[nodiscard]] auto TaskTracker() noexcept -> TaskTracker& { + return task_tracker_; } - // Return a reference to the origin map. It is the responsibility - // of the caller to ensure that access only happens in a - // single-threaded context. - auto OriginMap() -> std::unordered_map< + // Return a reference to the origin map. It is the responsibility of the + // caller to ensure that access only happens in a single-threaded context. + [[nodiscard]] auto OriginMap() noexcept -> std::unordered_map< std::string, std::vector< std::pair<BuildMaps::Target::ConfiguredTarget, std::size_t>>>& { @@ -72,14 +45,12 @@ class Progress { } private: - uint64_t prio_{}; - std::mutex m_{}; - std::unordered_map<std::string, uint64_t> running_{}; + ::TaskTracker task_tracker_{}; std::unordered_map< std::string, std::vector< std::pair<BuildMaps::Target::ConfiguredTarget, std::size_t>>> - origin_map_; + origin_map_{}; }; -#endif +#endif // INCLUDED_SRC_BUILDTOOL_PROGRESS_REPORTING_PROGRESS_HPP diff --git a/src/buildtool/progress_reporting/task_tracker.hpp b/src/buildtool/progress_reporting/task_tracker.hpp new file mode 100644 index 00000000..dc127190 --- /dev/null +++ b/src/buildtool/progress_reporting/task_tracker.hpp @@ -0,0 +1,64 @@ +// 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_BUILDTOOL_PROGRESS_REPORTING_TASK_TRACKER_HPP +#define INCLUDED_SRC_BUILDTOOL_PROGRESS_REPORTING_TASK_TRACKER_HPP + +#include <cstdint> +#include <mutex> +#include <string> +#include <unordered_map> + +#include "src/buildtool/logging/log_level.hpp" +#include "src/buildtool/logging/logger.hpp" + +class TaskTracker { + public: + auto Start(const std::string& id) noexcept -> void { + std::unique_lock lock(m_); + ++prio_; + try { + running_.emplace(id, prio_); + } catch (...) { + Logger::Log(LogLevel::Warning, + "Internal error in progress tracking; progress reports " + "might be incorrect."); + } + } + + auto Stop(const std::string& id) noexcept -> void { + std::unique_lock lock(m_); + running_.erase(id); + } + + [[nodiscard]] auto Sample() noexcept -> std::string { + std::unique_lock lock(m_); + std::string result{}; + uint64_t started = prio_ + 1; + for (auto const& it : running_) { + if (it.second < started) { + result = it.first; + started = it.second; + } + } + return result; + } + + private: + uint64_t prio_{}; + std::mutex m_{}; + std::unordered_map<std::string, uint64_t> running_{}; +}; + +#endif // INCLUDED_SRC_BUILDTOOL_PROGRESS_REPORTING_TASK_TRACKER_HPP |