• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 RENDER_SERVICE_BASE_PIPELINE_RS_EXCEPTION_CHECK_H
17 #define RENDER_SERVICE_BASE_PIPELINE_RS_EXCEPTION_CHECK_H
18 
19 #include "platform/common/rs_log.h"
20 namespace OHOS {
21 namespace Rosen {
22 
23 class RSB_EXPORT RSTimer {
24 public:
GetNanoSeconds()25     static inline int64_t GetNanoSeconds()
26     {
27         struct timespec ts;
28         (void)clock_gettime(CLOCK_MONOTONIC, &ts);
29         return ts.tv_sec * NANO + ts.tv_nsec;
30     }
31 
GetSeconds()32     static inline int64_t GetSeconds()
33     {
34         struct timespec ts;
35         (void)clock_gettime(CLOCK_REALTIME, &ts);
36         return ts.tv_sec;
37     }
38 
RSTimer(const char * tag,const int64_t threshold)39     explicit RSTimer(const char* tag, const int64_t threshold): tag_(tag),
40         timestamp_(GetNanoSeconds()), threshold_(threshold) {}
41 
~RSTimer()42     ~RSTimer()
43     {
44         int64_t durationMs = GetDuration();
45         if (durationMs > threshold_) {
46             RS_LOGE("%{public}s task too long: %{public}" PRIu64 " ms", tag_, durationMs);
47         }
48     }
49 
50     int64_t GetDuration();
51 
52 private:
53     const char* tag_;
54     const int64_t timestamp_;
55     const int64_t threshold_;
56     static constexpr int64_t NANO = 1000000000LL;
57     static constexpr int64_t MILLI = 1000000LL;
58 };
59 
60 struct RSB_EXPORT ExceptionCheck {
61     void UploadRenderExceptionData();
62     int32_t pid_ = 0;
63     uint32_t uid_ = 0;
64     std::string processName_;
65     int32_t exceptionCnt_ = 0;
66     int64_t exceptionMoment_ = 0;
67     std::string exceptionPoint_;
68     bool isUpload_ = true;
69 };
70 
71 } // namespace Rosen
72 } // namespace OHOS
73 
74 #endif