1 /*
2 * Copyright (C) 2021-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 #include "event_log_task.h"
16
17 #include <unistd.h>
18 #include <regex>
19
20 #include "common_utils.h"
21 #include "hiview_logger.h"
22 #include "parameter_ex.h"
23 #include "securec.h"
24 #include "shell_catcher.h"
25 #include "string_util.h"
26 #include "time_util.h"
27 #include "freeze_common.h"
28 #include "thermal_mgr_client.h"
29
30 #ifdef STACKTRACE_CATCHER_ENABLE
31 #include "open_stacktrace_catcher.h"
32 #endif // STACKTRACE_CATCHER_ENABLE
33
34 #ifdef BINDER_CATCHER_ENABLE
35 #include "binder_catcher.h"
36 #include "peer_binder_catcher.h"
37 #endif // BINDER_CATCHER_ENABLE
38
39 #ifdef DMESG_CATCHER_ENABLE
40 #include "dmesg_catcher.h"
41 #endif // DMESG_CATCHER_ENABLE
42
43 #ifdef HITRACE_CATCHER_ENABLE
44 #include "trace_collector.h"
45 #endif // HITRACE_CATCHER_ENABLE
46
47 #ifdef USAGE_CATCHER_ENABLE
48 #include "memory_catcher.h"
49 #endif // USAGE_CATCHER_ENABLE
50
51 #ifdef OTHER_CATCHER_ENABLE
52 #include "ffrt_catcher.h"
53 #endif // OTHER_CATCHER_ENABLE
54
55 namespace OHOS {
56 namespace HiviewDFX {
57 namespace {
58 static constexpr int BP_CMD_PERF_TYPE_INDEX = 2;
59 static constexpr int BP_CMD_LAYER_INDEX = 1;
60 static constexpr size_t BP_CMD_SZ = 3;
61 const char* SYSTEM_STACK[] = {
62 "foundation",
63 "render_service",
64 };
65 static constexpr int TRACE_OUT_OF_TIME = 30; // 30s
66 static constexpr int DELAY_OUT_OF_TIME = 15; // 15s
67 static constexpr int DEFAULT_LOG_SIZE = 1024 * 1024; // 1M
68 static constexpr uint64_t MILLISEC_TO_SEC = 1000;
69 static constexpr uint64_t DELAY_TIME = 2;
70 }
71 DEFINE_LOG_LABEL(0xD002D01, "EventLogger-EventLogTask");
EventLogTask(int fd,int jsonFd,std::shared_ptr<SysEvent> event)72 EventLogTask::EventLogTask(int fd, int jsonFd, std::shared_ptr<SysEvent> event)
73 : targetFd_(fd),
74 targetJsonFd_(jsonFd),
75 event_(event),
76 maxLogSize_(DEFAULT_LOG_SIZE),
77 taskLogSize_(0),
78 status_(Status::TASK_RUNNABLE)
79 {
80 int pid = event_->GetEventIntValue("PID");
81 pid_ = pid ? pid : event_->GetPid();
82 #ifdef STACKTRACE_CATCHER_ENABLE
83 captureList_.insert(std::pair<std::string, capture>("s", [this] { this->AppStackCapture(); }));
84 captureList_.insert(std::pair<std::string, capture>("S", [this] { this->SystemStackCapture(); }));
85 #endif // STACKTRACE_CATCHER_ENABLE
86 #ifdef BINDER_CATCHER_ENABLE
87 captureList_.insert(std::pair<std::string, capture>("b", [this] { this->BinderLogCapture(); }));
88 #endif // BINDER_CATCHER_ENABLE
89 #ifdef OTHER_CATCHER_ENABLE
90 captureList_.insert(std::pair<std::string, capture>("ffrt", [this] { this->FfrtCapture(); }));
91 #endif // OTHER_CATCHER_ENABLE
92 #ifdef USAGE_CATCHER_ENABLE
93 captureList_.insert(std::pair<std::string, capture>("cmd:m", [this] { this->MemoryUsageCapture(); }));
94 captureList_.insert(std::pair<std::string, capture>("cmd:c", [this] { this->CpuUsageCapture(); }));
95 captureList_.insert(std::pair<std::string, capture>("cmd:w", [this] { this->WMSUsageCapture(); }));
96 captureList_.insert(std::pair<std::string, capture>("cmd:a", [this] { this->AMSUsageCapture(); }));
97 captureList_.insert(std::pair<std::string, capture>("cmd:p", [this] { this->PMSUsageCapture(); }));
98 captureList_.insert(std::pair<std::string, capture>("cmd:d", [this] { this->DPMSUsageCapture(); }));
99 captureList_.insert(std::pair<std::string, capture>("cmd:rs", [this] { this->RSUsageCapture(); }));
100 #endif // USAGE_CATCHER_ENABLE
101 #ifdef OTHER_CATCHER_ENABLE
102 captureList_.insert(std::pair<std::string, capture>("cmd:mmi", [this] { this->MMIUsageCapture(); }));
103 captureList_.insert(std::pair<std::string, capture>("cmd:dms", [this] { this->DMSUsageCapture(); }));
104 captureList_.insert(std::pair<std::string, capture>("cmd:eec", [this] { this->EECStateCapture(); }));
105 captureList_.insert(std::pair<std::string, capture>("cmd:gec", [this] { this->GECStateCapture(); }));
106 captureList_.insert(std::pair<std::string, capture>("cmd:ui", [this] { this->UIStateCapture(); }));
107 captureList_.insert(std::pair<std::string, capture>("cmd:ss", [this] { this->Screenshot(); }));
108 #endif // OTHER_CATCHER_ENABLE
109 #ifdef HILOG_CATCHER_ENABLE
110 captureList_.insert(std::pair<std::string, capture>("T", [this] { this->HilogCapture(); }));
111 captureList_.insert(std::pair<std::string, capture>("T:power", [this] { this->HilogTagCapture(); }));
112 captureList_.insert(std::pair<std::string, capture>("t", [this] { this->LightHilogCapture(); }));
113 #endif // HILOG_CATCHER_ENABLE
114 #ifdef DMESG_CATCHER_ENABLE
115 captureList_.insert(std::pair<std::string, capture>("e", [this] { this->DmesgCapture(); }));
116 captureList_.insert(std::pair<std::string, capture>("k:SysRq",
117 [this] { this->SysrqCapture(false); }));
118 captureList_.insert(std::pair<std::string, capture>("k:SysRqFile",
119 [this] { this->SysrqCapture(true); }));
120 #endif // DMESG_CATCHER_ENABLE
121 #ifdef HITRACE_CATCHER_ENABLE
122 captureList_.insert(std::pair<std::string, capture>("tr", [this] { this->HitraceCapture(); }));
123 #endif // HITRACE_CATCHER_ENABLE
124 AddCapture();
125 }
AddCapture()126 void EventLogTask::AddCapture()
127 {
128 #ifdef SCB_CATCHER_ENABLE
129 captureList_.insert(std::pair<std::string, capture>("cmd:scbCS",
130 [this] { this->SCBSessionCapture(); }));
131 captureList_.insert(std::pair<std::string, capture>("cmd:scbVP",
132 [this] { this->SCBViewParamCapture(); }));
133 captureList_.insert(std::pair<std::string, capture>("cmd:scbWMS",
134 [this] { this->SCBWMSCapture(); }));
135 captureList_.insert(std::pair<std::string, capture>("cmd:scbWMSEVT",
136 [this] { this->SCBWMSEVTCapture(); }));
137 #endif // SCB_CATCHER_ENABLE
138 #ifdef USAGE_CATCHER_ENABLE
139 captureList_.insert(std::pair<std::string, capture>("cmd:dam",
140 [this] { this->DumpAppMapCapture(); }));
141 #endif // USAGE_CATCHER_ENABLE
142 #ifdef HILOG_CATCHER_ENABLE
143 captureList_.insert(std::pair<std::string, capture>("t:input",
144 [this] { this->InputHilogCapture(); }));
145 #endif // HILOG_CATCHER_ENABLE
146 #ifdef STACKTRACE_CATCHER_ENABLE
147 captureList_.insert(std::pair<std::string, capture>("cmd:remoteS",
148 [this] { this->RemoteStackCapture(); }));
149 captureList_.insert(std::pair<std::string, capture>("GpuStack",
150 [this] { this->GetGPUProcessStack(); }));
151 captureList_.insert(std::pair<std::string, capture>("specificStack",
152 [this] { this->GetSpecificProcessStack(); }));
153 #endif // STACKTRACE_CATCHER_ENABLE
154 }
155
AddLog(const std::string & cmd)156 void EventLogTask::AddLog(const std::string &cmd)
157 {
158 if (tasks_.size() == 0) {
159 status_ = Status::TASK_RUNNABLE;
160 }
161
162 if (captureList_.find(cmd) != captureList_.end()) {
163 captureList_[cmd]();
164 return;
165 }
166 #ifdef BINDER_CATCHER_ENABLE
167 PeerBinderCapture(cmd);
168 #endif // BINDER_CATCHER_ENABLE
169 catchedPids_.clear();
170 }
171
SetFocusWindowId(const std::string & focusWindowId)172 void EventLogTask::SetFocusWindowId(const std::string& focusWindowId)
173 {
174 focusWindowId_ = focusWindowId;
175 }
176
StartCompose()177 EventLogTask::Status EventLogTask::StartCompose()
178 {
179 // nothing to do, return success
180 if (status_ != Status::TASK_RUNNABLE) {
181 return status_;
182 }
183 status_ = Status::TASK_RUNNING;
184 // nothing to do, return success
185 if (tasks_.size() == 0) {
186 return Status::TASK_SUCCESS;
187 }
188
189 auto dupedFd = dup(targetFd_);
190 int dupedJsonFd = -1;
191 if (targetJsonFd_ >= 0) {
192 dupedJsonFd = dup(targetJsonFd_);
193 }
194 uint32_t catcherIndex = 0;
195 for (auto& catcher : tasks_) {
196 catcherIndex++;
197 if (dupedFd < 0) {
198 status_ = Status::TASK_FAIL;
199 AddStopReason(targetFd_, catcher, "Fail to dup file descriptor, exit!");
200 return TASK_FAIL;
201 }
202
203 FreezeCommon::WriteStartInfoToFd(dupedFd, catcher->GetDescription() + "start time: ");
204 int curLogSize = catcher->Catch(dupedFd, dupedJsonFd);
205 if (catcher->name_ == "PeerBinderCatcher") {
206 terminalThreadStack_ = catcher->terminalBinder_.threadStack;
207 }
208 HIVIEW_LOGI("finish catcher: %{public}s, curLogSize: %{public}d", catcher->GetDescription().c_str(),
209 curLogSize);
210 FreezeCommon::WriteEndInfoToFd(dupedFd, catcher->GetDescription() + "end time: ");
211 if (ShouldStopLogTask(dupedFd, catcherIndex, curLogSize, catcher)) {
212 break;
213 }
214 }
215 GetThermalInfo(dupedFd);
216 close(dupedFd);
217 if (dupedJsonFd >= 0) {
218 close(dupedJsonFd);
219 }
220 if (status_ == Status::TASK_RUNNING) {
221 status_ = Status::TASK_SUCCESS;
222 }
223 return status_;
224 }
225
ShouldStopLogTask(int fd,uint32_t curTaskIndex,int curLogSize,std::shared_ptr<EventLogCatcher> catcher)226 bool EventLogTask::ShouldStopLogTask(int fd, uint32_t curTaskIndex, int curLogSize,
227 std::shared_ptr<EventLogCatcher> catcher)
228 {
229 if (status_ == Status::TASK_TIMEOUT) {
230 HIVIEW_LOGE("Break Log task, parent has timeout.");
231 return true;
232 }
233
234 bool encounterErr = (curLogSize < 0);
235 bool hasFinished = (curTaskIndex == tasks_.size());
236 if (!encounterErr) {
237 taskLogSize_ += static_cast<uint32_t>(curLogSize);
238 }
239
240 if (taskLogSize_ > maxLogSize_ && !hasFinished) {
241 AddStopReason(fd, catcher, "Exceed max log size");
242 status_ = Status::TASK_EXCEED_SIZE;
243 return true;
244 }
245
246 if (encounterErr) {
247 AddStopReason(fd, catcher, "Log catcher not successful");
248 HIVIEW_LOGE("catcher %{public}s, Log catcher not successful", catcher->GetDescription().c_str());
249 }
250 return false;
251 }
252
AddStopReason(int fd,std::shared_ptr<EventLogCatcher> catcher,const std::string & reason)253 void EventLogTask::AddStopReason(int fd, std::shared_ptr<EventLogCatcher> catcher, const std::string& reason)
254 {
255 char buf[BUF_SIZE_512] = {0};
256 int ret = -1;
257 if (catcher != nullptr) {
258 catcher->Stop();
259 // sleep 1s for syncing log to the fd, then we could append failure reason ?
260 sleep(1);
261 std::string summary = catcher->GetDescription();
262 ret = snprintf_s(buf, BUF_SIZE_512, BUF_SIZE_512 - 1, "\nTask stopped when running catcher:%s, Reason:%s \n",
263 summary.c_str(), reason.c_str());
264 } else {
265 ret = snprintf_s(buf, BUF_SIZE_512, BUF_SIZE_512 - 1, "\nTask stopped, Reason:%s \n", reason.c_str());
266 }
267
268 if (ret > 0) {
269 write(fd, buf, strnlen(buf, BUF_SIZE_512));
270 fsync(fd);
271 }
272 }
273
AddSeparator(int fd,std::shared_ptr<EventLogCatcher> catcher) const274 void EventLogTask::AddSeparator(int fd, std::shared_ptr<EventLogCatcher> catcher) const
275 {
276 char buf[BUF_SIZE_512] = {0};
277 std::string summary = catcher->GetDescription();
278 if (summary.empty()) {
279 HIVIEW_LOGE("summary.empty() catcher is %{public}s", catcher->GetName().c_str());
280 return;
281 }
282
283 int ret = snprintf_s(buf, BUF_SIZE_512, BUF_SIZE_512 - 1, "\n%s\n", summary.c_str());
284 if (ret > 0) {
285 write(fd, buf, strnlen(buf, BUF_SIZE_512));
286 fsync(fd);
287 }
288 }
289
RecordCatchedPids(const std::string & packageName)290 void EventLogTask::RecordCatchedPids(const std::string& packageName)
291 {
292 int pid = CommonUtils::GetPidByName(packageName);
293 if (pid > 0) {
294 catchedPids_.insert(pid);
295 }
296 }
297
GetTaskStatus() const298 EventLogTask::Status EventLogTask::GetTaskStatus() const
299 {
300 return status_;
301 }
302
GetLogSize() const303 long EventLogTask::GetLogSize() const
304 {
305 return taskLogSize_;
306 }
307
308 #ifdef STACKTRACE_CATCHER_ENABLE
AppStackCapture()309 void EventLogTask::AppStackCapture()
310 {
311 auto capture = std::make_shared<OpenStacktraceCatcher>();
312 capture->Initialize(event_->GetEventValue("PACKAGE_NAME"), pid_, 0);
313 tasks_.push_back(capture);
314 }
315
SystemStackCapture()316 void EventLogTask::SystemStackCapture()
317 {
318 for (auto packageName : SYSTEM_STACK) {
319 auto capture = std::make_shared<OpenStacktraceCatcher>();
320 capture->Initialize(packageName, 0, 0);
321 RecordCatchedPids(packageName);
322 tasks_.push_back(capture);
323 }
324 }
325
RemoteStackCapture()326 void EventLogTask::RemoteStackCapture()
327 {
328 auto capture = std::make_shared<OpenStacktraceCatcher>();
329 int32_t remotePid = event_->GetEventIntValue("REMOTE_PID");
330 capture->Initialize(event_->GetEventValue("PACKAGE_NAME"), remotePid, 0);
331 tasks_.push_back(capture);
332 }
333
GetProcessStack(const std::string & processName)334 void EventLogTask::GetProcessStack(const std::string& processName)
335 {
336 auto capture = std::make_shared<OpenStacktraceCatcher>();
337 int pid = CommonUtils::GetPidByName(processName);
338 HIVIEW_LOGI("get pid of %{public}s: %{public}d.", processName.c_str(), pid);
339 if (pid != -1) {
340 capture->Initialize(processName, pid, 0);
341 tasks_.push_back(capture);
342 }
343 }
344
GetGPUProcessStack()345 void EventLogTask::GetGPUProcessStack()
346 {
347 std::string processName = event_->GetEventValue("PACKAGE_NAME");
348 processName += ":gpu";
349 GetProcessStack(processName);
350 }
351
GetSpecificProcessStack()352 void EventLogTask::GetSpecificProcessStack()
353 {
354 std::string processName = event_->GetEventValue("SPECIFICSTACK_NAME");
355 if (!processName.empty()) {
356 GetProcessStack(processName);
357 }
358 }
359 #endif // STACKTRACE_CATCHER_ENABLE
360
361 #ifdef BINDER_CATCHER_ENABLE
BinderLogCapture()362 void EventLogTask::BinderLogCapture()
363 {
364 auto capture = std::make_shared<BinderCatcher>();
365 capture->Initialize("", 0, 0);
366 tasks_.push_back(capture);
367 }
368
PeerBinderCapture(const std::string & cmd)369 bool EventLogTask::PeerBinderCapture(const std::string &cmd)
370 {
371 auto find = cmd.find("pb");
372 if (find == cmd.npos) {
373 return false;
374 }
375
376 std::vector<std::string> cmdList;
377 StringUtil::SplitStr(cmd, ":", cmdList, true);
378 if (cmdList.size() != BP_CMD_SZ || cmdList.front() != "pb") {
379 return false;
380 }
381
382 auto capture = std::make_shared<PeerBinderCatcher>();
383 capture->Initialize(cmdList[BP_CMD_PERF_TYPE_INDEX],
384 StringUtil::StrToInt(cmdList[BP_CMD_LAYER_INDEX]), pid_);
385 capture->Init(event_, "", catchedPids_);
386 tasks_.push_back(capture);
387 return true;
388 }
389 #endif // BINDER_CATCHER_ENABLE
390
391 #ifdef DMESG_CATCHER_ENABLE
DmesgCapture()392 void EventLogTask::DmesgCapture()
393 {
394 if (!Parameter::IsBetaVersion()) {
395 HIVIEW_LOGI("the version is not a beta version");
396 return;
397 }
398 auto capture = std::make_shared<DmesgCatcher>();
399 capture->Initialize("", 0, 0);
400 capture->Init(event_);
401 tasks_.push_back(capture);
402 }
403
SysrqCapture(bool isWriteNewFile)404 void EventLogTask::SysrqCapture(bool isWriteNewFile)
405 {
406 auto capture = std::make_shared<DmesgCatcher>();
407 capture->Initialize("", isWriteNewFile, 1);
408 capture->Init(event_);
409 if (isWriteNewFile) {
410 capture->WriteNewSysrq();
411 } else {
412 tasks_.push_back(capture);
413 }
414 }
415 #endif // DMESG_CATCHER_ENABLE
416
417 #ifdef HILOG_CATCHER_ENABLE
HilogCapture()418 void EventLogTask::HilogCapture()
419 {
420 if (!Parameter::IsBetaVersion()) {
421 HIVIEW_LOGI("the version is not a beta version");
422 return;
423 }
424 auto capture = std::make_shared<ShellCatcher>();
425 capture->Initialize("hilog -x", ShellCatcher::CATCHER_HILOG, 0);
426 tasks_.push_back(capture);
427 }
428
HilogTagCapture()429 void EventLogTask::HilogTagCapture()
430 {
431 if (!Parameter::IsBetaVersion()) {
432 HIVIEW_LOGI("the version is not a beta version");
433 return;
434 }
435 auto capture = std::make_shared<ShellCatcher>();
436 capture->Initialize("hilog -x", ShellCatcher::CATCHER_TAGHILOG, 0);
437 tasks_.push_back(capture);
438 }
439
LightHilogCapture()440 void EventLogTask::LightHilogCapture()
441 {
442 auto capture = std::make_shared<ShellCatcher>();
443 capture->Initialize("hilog -z 1000 -P", ShellCatcher::CATCHER_LIGHT_HILOG, pid_);
444 tasks_.push_back(capture);
445 }
446
InputHilogCapture()447 void EventLogTask::InputHilogCapture()
448 {
449 auto capture = std::make_shared<ShellCatcher>();
450 int32_t eventId = event_->GetEventIntValue("INPUT_ID");
451 if (eventId > 0) {
452 std::string cmd = "hilog -T InputKeyFlow -e " +
453 std::to_string(eventId) + " -x";
454 capture->Initialize(cmd, ShellCatcher::CATCHER_INPUT_EVENT_HILOG, eventId);
455 } else {
456 capture->Initialize("hilog -T InputKeyFlow -x", ShellCatcher::CATCHER_INPUT_HILOG,
457 pid_);
458 }
459 tasks_.push_back(capture);
460 }
461 #endif // HILOG_CATCHER_ENABLE
462
463 #ifdef HITRACE_CATCHER_ENABLE
HitraceCapture()464 void EventLogTask::HitraceCapture()
465 {
466 std::shared_ptr<UCollectUtil::TraceCollector> collector = UCollectUtil::TraceCollector::Create();
467 UCollect::TraceCaller caller = UCollect::TraceCaller::RELIABILITY;
468 std::regex reg("Fault time:(\\d{4}/\\d{2}/\\d{2}-\\d{2}:\\d{2}:\\d{2})");
469 std::string timeStamp = event_->GetEventValue("MSG");
470 std::smatch match;
471 timeStamp = std::regex_search(timeStamp, match, reg) ? match[1].str() : "";
472 uint64_t faultTime = timeStamp.empty() ? (event_->happenTime_ / MILLISEC_TO_SEC) :
473 static_cast<uint64_t>(TimeUtil::StrToTimeStamp(timeStamp, "%Y/%m/%d-%H:%M:%S"));
474 faultTime += DELAY_TIME;
475 uint64_t currentTime = TimeUtil::GetMilliseconds() / MILLISEC_TO_SEC;
476 if (currentTime >= (TRACE_OUT_OF_TIME + faultTime)) {
477 faultTime = currentTime - DELAY_OUT_OF_TIME;
478 }
479 HIVIEW_LOGI("get hitrace start, faultTime: %{public}" PRIu64, faultTime);
480 auto result = collector->DumpTraceWithDuration(caller, MAX_DUMP_TRACE_LIMIT, faultTime);
481 if (result.retCode != 0) {
482 HIVIEW_LOGE("get hitrace fail! error code : %{public}d", result.retCode);
483 return;
484 }
485 HIVIEW_LOGI("get hitrace end, faultTime: %{public}" PRIu64, faultTime);
486 }
487 #endif // HITRACE_CATCHER_ENABLE
488
489 #ifdef USAGE_CATCHER_ENABLE
MemoryUsageCapture()490 void EventLogTask::MemoryUsageCapture()
491 {
492 auto capture = std::make_shared<MemoryCatcher>();
493 capture->SetEvent(event_);
494 capture->Initialize("", 0, 0);
495 if (!memoryCatched_) {
496 tasks_.push_back(capture);
497 memoryCatched_ = true;
498 } else {
499 capture->CollectMemInfo();
500 }
501 }
502
CpuUsageCapture()503 void EventLogTask::CpuUsageCapture()
504 {
505 auto capture = std::make_shared<ShellCatcher>();
506 capture->Initialize("hidumper --cpuusage", ShellCatcher::CATCHER_CPU, pid_);
507 tasks_.push_back(capture);
508 }
509
WMSUsageCapture()510 void EventLogTask::WMSUsageCapture()
511 {
512 auto capture = std::make_shared<ShellCatcher>();
513 capture->Initialize("hidumper -s WindowManagerService -a -a", ShellCatcher::CATCHER_WMS, pid_);
514 tasks_.push_back(capture);
515 }
516
AMSUsageCapture()517 void EventLogTask::AMSUsageCapture()
518 {
519 auto capture = std::make_shared<ShellCatcher>();
520 capture->Initialize("hidumper -s AbilityManagerService -a -a", ShellCatcher::CATCHER_AMS, pid_);
521 tasks_.push_back(capture);
522 }
523
PMSUsageCapture()524 void EventLogTask::PMSUsageCapture()
525 {
526 auto capture = std::make_shared<ShellCatcher>();
527 capture->Initialize("hidumper -s PowerManagerService -a -s", ShellCatcher::CATCHER_PMS, pid_);
528 tasks_.push_back(capture);
529 }
530
DPMSUsageCapture()531 void EventLogTask::DPMSUsageCapture()
532 {
533 auto capture = std::make_shared<ShellCatcher>();
534 capture->Initialize("hidumper -s DisplayPowerManagerService", ShellCatcher::CATCHER_DPMS, pid_);
535 tasks_.push_back(capture);
536 }
537
RSUsageCapture()538 void EventLogTask::RSUsageCapture()
539 {
540 if (!Parameter::IsBetaVersion()) {
541 HIVIEW_LOGI("the version is not a beta version");
542 return;
543 }
544 auto capture = std::make_shared<ShellCatcher>();
545 capture->Initialize("hidumper -s RenderService -a allInfo", ShellCatcher::CATCHER_RS, pid_);
546 tasks_.push_back(capture);
547 }
548
DumpAppMapCapture()549 void EventLogTask::DumpAppMapCapture()
550 {
551 auto capture = std::make_shared<ShellCatcher>();
552 capture->Initialize("hidumper -s 1910 -a DumpAppMap", ShellCatcher::CATCHER_DAM, pid_);
553 tasks_.push_back(capture);
554 }
555 #endif // USAGE_CATCHER_ENABLE
556
557 #ifdef SCB_CATCHER_ENABLE
SCBSessionCapture()558 void EventLogTask::SCBSessionCapture()
559 {
560 auto capture = std::make_shared<ShellCatcher>();
561 capture->Initialize("hidumper -s 4606 -a '-b SCBScenePanel getContainerSession'",
562 ShellCatcher::CATCHER_SCBSESSION, pid_);
563 tasks_.push_back(capture);
564 }
565
SCBViewParamCapture()566 void EventLogTask::SCBViewParamCapture()
567 {
568 auto capture = std::make_shared<ShellCatcher>();
569 capture->Initialize("hidumper -s 4606 -a '-b SCBScenePanel getViewParam'",
570 ShellCatcher::CATCHER_SCBVIEWPARAM, pid_);
571 tasks_.push_back(capture);
572 }
573
SCBWMSCapture()574 void EventLogTask::SCBWMSCapture()
575 {
576 auto capture = std::make_shared<ShellCatcher>();
577 capture->SetEvent(event_);
578 if (focusWindowId_.empty()) {
579 HIVIEW_LOGE("dump simplify get focus window error");
580 return;
581 }
582 std::string cmd = "hidumper -s WindowManagerService -a -w " + focusWindowId_ + " -simplify";
583 capture->Initialize(cmd, ShellCatcher::CATCHER_SCBWMS, pid_);
584 capture->SetFocusWindowId(focusWindowId_);
585 tasks_.push_back(capture);
586 }
587
SCBWMSEVTCapture()588 void EventLogTask::SCBWMSEVTCapture()
589 {
590 auto capture = std::make_shared<ShellCatcher>();
591 capture->SetEvent(event_);
592 if (focusWindowId_.empty()) {
593 HIVIEW_LOGE("dump event get focus window error");
594 return;
595 }
596 std::string cmd = "hidumper -s WindowManagerService -a -w " + focusWindowId_ + " -event";
597 capture->Initialize(cmd, ShellCatcher::CATCHER_SCBWMSEVT, pid_);
598 capture->SetFocusWindowId(focusWindowId_);
599 tasks_.push_back(capture);
600 }
601 #endif // SCB_CATCHER_ENABLE
602
603 #ifdef OTHER_CATCHER_ENABLE
FfrtCapture()604 void EventLogTask::FfrtCapture()
605 {
606 if (pid_ > 0) {
607 auto capture = std::make_shared<FfrtCatcher>();
608 capture->Initialize("", pid_, 0);
609 tasks_.push_back(capture);
610 }
611 }
612
MMIUsageCapture()613 void EventLogTask::MMIUsageCapture()
614 {
615 auto capture = std::make_shared<ShellCatcher>();
616 capture->Initialize("hidumper -s MultimodalInput -a -w", ShellCatcher::CATCHER_MMI, pid_);
617 tasks_.push_back(capture);
618 }
619
DMSUsageCapture()620 void EventLogTask::DMSUsageCapture()
621 {
622 auto capture = std::make_shared<ShellCatcher>();
623 capture->Initialize("hidumper -s DisplayManagerService -a -a", ShellCatcher::CATCHER_DMS, pid_);
624 tasks_.push_back(capture);
625 }
626
EECStateCapture()627 void EventLogTask::EECStateCapture()
628 {
629 auto capture = std::make_shared<ShellCatcher>();
630 capture->Initialize("hidumper -s 4606 -a '-b EventExclusiveCommander getAllEventExclusiveCaller'",
631 ShellCatcher::CATCHER_EEC, pid_);
632 tasks_.push_back(capture);
633 }
634
GECStateCapture()635 void EventLogTask::GECStateCapture()
636 {
637 auto capture = std::make_shared<ShellCatcher>();
638 capture->Initialize("hidumper -s 4606 -a '-b SCBGestureManager getAllGestureEnableCaller'",
639 ShellCatcher::CATCHER_GEC, pid_);
640 tasks_.push_back(capture);
641 }
642
UIStateCapture()643 void EventLogTask::UIStateCapture()
644 {
645 auto capture = std::make_shared<ShellCatcher>();
646 capture->Initialize("hidumper -s 4606 -a '-p 0'", ShellCatcher::CATCHER_UI, pid_);
647 tasks_.push_back(capture);
648 }
649
Screenshot()650 void EventLogTask::Screenshot()
651 {
652 auto capture = std::make_shared<ShellCatcher>();
653 capture->Initialize("snapshot_display -f x.jpeg", ShellCatcher::CATCHER_SNAPSHOT, pid_);
654 tasks_.push_back(capture);
655 }
656 #endif // OTHER_CATCHER_ENABLE
657
GetThermalInfo(int fd)658 void EventLogTask::GetThermalInfo(int fd)
659 {
660 FreezeCommon::WriteStartInfoToFd(fd, "collect ThermalLevel start time: ");
661 PowerMgr::ThermalLevel temp = PowerMgr::ThermalMgrClient::GetInstance().GetThermalLevel();
662 int tempNum = static_cast<int>(temp);
663 FileUtil::SaveStringToFd(fd, "\ncollect ThermalLevel end time: " + std::to_string(tempNum) + "\n");
664 FreezeCommon::WriteEndInfoToFd(fd, "\nend collect hotInfo: ");
665 }
666 } // namespace HiviewDFX
667 } // namespace OHOS
668