• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef PANDA_LIBPANDABASE_TASKMANAGER_TASK_STATISTICS_LOCK_FREE_TASK_STATISTICS_IMPL_H
17 #define PANDA_LIBPANDABASE_TASKMANAGER_TASK_STATISTICS_LOCK_FREE_TASK_STATISTICS_IMPL_H
18 
19 #include "libpandabase/taskmanager/task_statistics/task_statistics.h"
20 #include <unordered_map>
21 #include <atomic>
22 
23 namespace panda::taskmanager {
24 
25 class LockFreeTaskStatisticsImpl : public TaskStatistics {
26     using TaskPropertiesAtomicCounterMap = std::unordered_map<TaskProperties, std::atomic_size_t, TaskProperties::Hash>;
27 
28 public:
29     LockFreeTaskStatisticsImpl();
30     ~LockFreeTaskStatisticsImpl() override = default;
31 
32     NO_COPY_SEMANTIC(LockFreeTaskStatisticsImpl);
33     NO_MOVE_SEMANTIC(LockFreeTaskStatisticsImpl);
34 
35     void IncrementCount(TaskStatus status, TaskProperties properties, size_t count) override;
36     size_t GetCount(TaskStatus status, TaskProperties properties) const override;
37 
38     size_t GetCountOfTaskInSystem() const override;
39     size_t GetCountOfTasksInSystemWithTaskProperties(TaskProperties properties) const override;
40 
41     void ResetAllCounters() override;
42     void ResetCountersWithTaskProperties(TaskProperties properties) override;
43 
44 private:
45     TaskPropertiesAtomicCounterMap taskInSystemCounterMap_;
46     std::unordered_map<TaskStatus, TaskPropertiesAtomicCounterMap> taskPropertiesCounterMap_;
47 };
48 
49 }  // namespace panda::taskmanager
50 
51 #endif  // PANDA_LIBPANDABASE_TASKMANAGER_TASK_STATISTICS_LOCK_FREE_TASK_STATISTICS_IMPL_H
52