1 /*
2 * Copyright (c) 2024 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 #include "form_render_event_report.h"
17
18 #include <chrono>
19 #include <map>
20 #include "backtrace_local.h"
21 #include "dfx_dump_catcher.h"
22 #include "fms_log_wrapper.h"
23
24 namespace OHOS {
25 namespace AppExecFwk {
26 namespace {
27 static constexpr char DOMAIN_PERFORMANCE[] = "PERFORMANCE";
28 constexpr const char *EVENT_KEY_FORM_BLOCK_CALLSTACK = "EVENT_KEY_FORM_BLOCK_CALLSTACK";
29 constexpr const char *EVENT_KEY_FORM_BLOCK_APPNAME = "EVENT_KEY_FORM_BLOCK_APPNAME";
30 }
31
32 using namespace std;
33 using namespace std::chrono;
34
GetNowMillisecond()35 int64_t FormRenderEventReport::GetNowMillisecond()
36 {
37 system_clock::time_point pointTime = system_clock::now();
38 auto timeMilliseconds = chrono::duration_cast<chrono::milliseconds>(pointTime.time_since_epoch());
39 return timeMilliseconds.count();
40 }
41
SendPerformanceEvent(SceneType sceneType,PerformanceEventInfo & eventInfo)42 void FormRenderEventReport::SendPerformanceEvent(SceneType sceneType, PerformanceEventInfo &eventInfo)
43 {
44 switch (sceneType) {
45 case SceneType::CPU_SCENE_ENTRY:
46 HiSysEventWrite(
47 DOMAIN_PERFORMANCE,
48 "CPU_SCENE_ENTRY",
49 HiSysEventType::BEHAVIOR,
50 "PACKAGE_NAME", eventInfo.bundleName,
51 "SCENE_ID", eventInfo.sceneId,
52 "HAPPEN_TIME", eventInfo.timeStamp);
53 break;
54 default:
55 break;
56 }
57 }
58
SendBlockFaultEvent(pid_t processId,pid_t jsThreadId,std::string bundleName)59 void FormRenderEventReport::SendBlockFaultEvent(pid_t processId, pid_t jsThreadId, std::string bundleName)
60 {
61 OHOS::HiviewDFX::DfxDumpCatcher dumplog;
62 std::string traceStr;
63 bool ret = dumplog.DumpCatch(processId, jsThreadId, traceStr);
64 if (ret) {
65 HILOG_INFO("Print block form's process id %{public}d and thread %{public}d call stack %{public}s",
66 processId, jsThreadId, traceStr.c_str());
67 }
68 HiSysEventWrite(
69 HiSysEvent::Domain::FORM_MANAGER,
70 "FORM_BLOCK_CALLSTACK",
71 HiSysEvent::EventType::FAULT,
72 EVENT_KEY_FORM_BLOCK_CALLSTACK, traceStr,
73 EVENT_KEY_FORM_BLOCK_APPNAME, bundleName);
74 }
75
76 } // namespace AppExecFwk
77 } // namespace OHOS
78