• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 OHOS_ROSEN_WM_UTILS_PERFORM_REPORTER_H
17 #define OHOS_ROSEN_WM_UTILS_PERFORM_REPORTER_H
18 
19 #include <atomic>
20 #include <chrono>
21 #include <string>
22 #include <vector>
23 #include <map>
24 
25 namespace OHOS {
26 namespace Rosen {
27 class PerformReporter {
28 public:
29     PerformReporter(const std::string& tag, const std::vector<int64_t>& timeSpiltsMs, uint32_t reportInterval = 50);
30     void start();
31     void end();
32 private:
33     void count(int64_t costTime);
34     bool report();
35     void clear();
36 
37     std::string tag_;
38     std::atomic<uint32_t> totalCount_;
39     std::map<int64_t, std::atomic<uint32_t>> timeSplitCount_;
40     std::chrono::steady_clock::time_point startTime_;
41     uint32_t reportInterval_;
42 
43     static constexpr auto BARRIER = std::numeric_limits<int64_t>::max();
44 };
45 }
46 }
47 #endif