/* * Copyright (C) 2023 Huawei Device 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 CORE__PERF__PERFORMANCE_DATA_MANAGER_H #define CORE__PERF__PERFORMANCE_DATA_MANAGER_H #include #include #include #include #include #include #include #include #include #include CORE_BEGIN_NAMESPACE() // if CORE_DEV_ENABLED defined the manager methods are empty /** PerformanceDataManager. * Internally synchronized global singleton for timings. */ class PerformanceDataManager final : public IPerformanceDataManager { public: struct InternalData; using TypeDataSet = std::map, InternalData>; ~PerformanceDataManager(); explicit PerformanceDataManager(const BASE_NS::string_view category); PerformanceDataManager(const PerformanceDataManager&) = delete; PerformanceDataManager& operator=(const PerformanceDataManager&) = delete; BASE_NS::string_view GetCategory() const override; TimerHandle BeginTimer() override; int64_t EndTimer(TimerHandle handle) override; void UpdateData( const BASE_NS::string_view subCategory, const BASE_NS::string_view name, const int64_t microSeconds) override; void ResetData() override; BASE_NS::vector GetData() const override; void DumpToLog() const; void RemoveData(const BASE_NS::string_view subCategory) override; // IInterface const IInterface* GetInterface(const BASE_NS::Uid& uid) const override; IInterface* GetInterface(const BASE_NS::Uid& uid) override; void Ref() override; void Unref() override; private: const BASE_NS::string category_; #if (CORE_PERF_ENABLED == 1) mutable std::mutex dataMutex_; TypeDataSet data_; #endif }; class PerformanceDataManagerFactory final : public IPerformanceDataManagerFactory { public: IPerformanceDataManager* Get(const BASE_NS::string_view category) override; BASE_NS::vector GetAllCategories() const override; // IInterface const IInterface* GetInterface(const BASE_NS::Uid& uid) const override; IInterface* GetInterface(const BASE_NS::Uid& uid) override; void Ref() override; void Unref() override; private: #if (CORE_PERF_ENABLED == 1) mutable std::mutex mutex_; BASE_NS::unordered_map> managers_; #endif }; CORE_END_NAMESPACE() #endif // CORE__UTIL__PERFORMANCE_DATA_MANAGER_H