• 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 ROSEN_JANK_STATS_H
17 #define ROSEN_JANK_STATS_H
18 
19 #include <cstdint>
20 #include <mutex>
21 #include <string>
22 #include <vector>
23 
24 #include "transaction/rs_render_service_client.h"
25 
26 namespace OHOS {
27 
28 namespace {
29 using UniqueId = int64_t;
30 using TraceId = int32_t;
31 struct JankFrames {
32     bool isSetReportEventResponse_ = false;
33     bool isSetReportEventComplete_ = false;
34     bool isSetReportEventJankFrame_ = false;
35     bool isReportEventResponse_ = false;
36     bool isReportEventComplete_ = false;
37     bool isReportEventJankFrame_ = false;
38     int64_t setTime_ = 0;
39     int32_t seqMissedFrames_ = 0;
40     int32_t totalFrames_ = 0;
41     int32_t totalMissedFrames_ = 0;
42     int64_t maxFrameTime_ = 0;
43     int32_t maxSeqMissedFrames_ = 0;
44     int64_t totalFrameTime_ = 0;
45     Rosen::DataBaseRs info_;
46 };
47 struct TraceStats {
48     std::string traceName_;
49     int64_t createTime_ = 0;
50 };
51 } // namespace
52 
53 namespace Rosen {
54 class RSJankStats {
55 public:
56     static RSJankStats& GetInstance();
57     void SetStartTime();
58     void SetEndTime();
59     void ReportJankStats();
60     void SetReportEventResponse(DataBaseRs info);
61     void SetReportEventComplete(DataBaseRs info);
62     void SetReportEventJankFrame(DataBaseRs info);
63     void SetFirstFrame();
64     void SetPid(pid_t pid);
65 
66 private:
RSJankStats()67     RSJankStats() {};
~RSJankStats()68     ~RSJankStats() {};
69     RSJankStats(const RSJankStats&) = delete;
70     RSJankStats(const RSJankStats&&) = delete;
71     void operator=(const RSJankStats&) = delete;
72     void operator=(const RSJankStats&&) = delete;
73 
74     void SetRSJankStats(int32_t times);
75     void UpdateJankFrame(int64_t duration, JankFrames& jankFrames);
76     void ReportEventResponse(const JankFrames& jankFrames, const TraceId traceId);
77     void ReportEventComplete(const JankFrames& jankFrames, const TraceId traceId);
78     void ReportEventJankFrame(const JankFrames& jankFrames) const;
79     void ReportEventFirstFrame();
80     int64_t ConvertTimeToSystime(int64_t time) const;
81     int64_t GetCurrentSystimeMs() const;
82 
83     constexpr static size_t JANK_STATS_SIZE = 8;
84     constexpr static uint16_t TRACE_CHECK_FREQ = 20;
85     bool isfirstSetStart_ = true;
86     bool isNeedReport_ = false;
87     bool isFirstFrame_ = false;
88     int64_t startTime_ = 0;
89     int64_t endTime_ = 0;
90     int64_t lastReportTime_ = 0;
91     int32_t appPid_ = 0;
92     uint16_t traceCheckCnt_ = 0;
93     std::vector<uint16_t> rsJankStats_ = std::vector<uint16_t>(JANK_STATS_SIZE, 0);
94     std::map<TraceId, TraceStats> aSyncTraces_;
95     std::map<UniqueId, JankFrames> animateJankFrames_;
96     std::mutex animateJankFramesMutex_;
97 
98     enum JankRangeType : size_t {
99         JANK_FRAME_6_FREQ = 0,
100         JANK_FRAME_15_FREQ,
101         JANK_FRAME_20_FREQ,
102         JANK_FRAME_36_FREQ,
103         JANK_FRAME_48_FREQ,
104         JANK_FRAME_60_FREQ,
105         JANK_FRAME_120_FREQ,
106         JANK_FRAME_180_FREQ,
107         JANK_FRAME_INVALID,
108     };
109 };
110 
111 } // namespace Rosen
112 } // namespace OHOS
113 #endif