• 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 #include "event_delayed_util.h"
16 
17 #include "running_status_logger.h"
18 
19 namespace OHOS {
20 namespace HiviewDFX {
CheckIfEventDelayed(std::shared_ptr<SysEvent> event)21 void EventDelayedUtil::CheckIfEventDelayed(std::shared_ptr<SysEvent> event)
22 {
23     uint64_t happenTime = event->happenTime_;
24     uint64_t createTime = event->createTime_ / 1000; // 1000: us->ms
25     if (createTime < happenTime) { // for the time jump scene
26         LogEventDelayedInfo(false, happenTime, createTime);
27         return;
28     }
29 
30     // event delay exceeds threshold
31     constexpr uint64_t delayDetectLimit = 5 * 1000; // 5s
32     if (uint64_t delayTime = createTime - happenTime; delayTime > delayDetectLimit) {
33         LogEventDelayedInfo(true, happenTime, createTime);
34         return;
35     }
36 
37     // event not delayed
38     LogEventDelayedInfo(false, happenTime, createTime);
39 }
40 
LogEventDelayedInfo(bool isCurEventDelayed,uint64_t happenTime,uint64_t createTime)41 void EventDelayedUtil::LogEventDelayedInfo(bool isCurEventDelayed, uint64_t happenTime, uint64_t createTime)
42 {
43     if (isLastEventDelayed_ == isCurEventDelayed) {
44         return;
45     }
46 
47     // reset delay info of the last event by delay info of current event
48     isLastEventDelayed_ = isCurEventDelayed;
49     std::string info { "event delay " };
50     if (isCurEventDelayed) {
51         info.append("start;");
52     } else {
53         info.append("end;");
54     }
55     info.append("happen_time=[").append(std::to_string(happenTime)).append("]; ");
56     info.append("create_time=[").append(std::to_string(createTime)).append("]");
57     RunningStatusLogger::GetInstance().LogEventRunningLogInfo(info);
58 }
59 } // namespace HiviewDFX
60 } // namespace OHOS
61