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_SIMPLE_TASK_STATISTICS_IMPL_H 17 #define PANDA_LIBPANDABASE_TASKMANAGER_TASK_STATISTICS_SIMPLE_TASK_STATISTICS_IMPL_H 18 19 #include "libpandabase/os/mutex.h" 20 #include "libpandabase/taskmanager/task_statistics/task_statistics.h" 21 #include <unordered_map> 22 23 namespace panda::taskmanager { 24 25 /// SimpleTaskStatisticsImpl use lock for every used status to protect counters 26 class SimpleTaskStatisticsImpl : public TaskStatistics { 27 using TaskPropertiesCounterMap = std::unordered_map<TaskProperties, size_t, TaskProperties::Hash>; 28 29 public: 30 SimpleTaskStatisticsImpl(); 31 ~SimpleTaskStatisticsImpl() override = default; 32 33 NO_COPY_SEMANTIC(SimpleTaskStatisticsImpl); 34 NO_MOVE_SEMANTIC(SimpleTaskStatisticsImpl); 35 36 void IncrementCount(TaskStatus status, TaskProperties properties, size_t count) override; 37 size_t GetCount(TaskStatus status, TaskProperties properties) const override; 38 39 size_t GetCountOfTaskInSystem() const override; 40 size_t GetCountOfTasksInSystemWithTaskProperties(TaskProperties properties) const override; 41 42 void ResetAllCounters() override; 43 void ResetCountersWithTaskProperties(TaskProperties properties) override; 44 45 private: 46 mutable std::unordered_map<TaskStatus, os::memory::Mutex> perStatusLock_; 47 std::unordered_map<TaskStatus, TaskPropertiesCounterMap> taskPropertiesCounterMap_; 48 }; 49 50 } // namespace panda::taskmanager 51 52 #endif // PANDA_LIBPANDABASE_TASKMANAGER_TASK_STATISTICS_SIMPLE_TASK_STATISTICS_IMPL_H 53