• 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 "faultlog_jserror.h"
16 
17 #include "constants.h"
18 #include "hiview_logger.h"
19 #include "page_history_manager.h"
20 
21 namespace OHOS {
22 namespace HiviewDFX {
23 DEFINE_LOG_LABEL(0xD002D11, "Faultlogger");
ReportToAppEvent(std::shared_ptr<SysEvent> sysEvent,const FaultLogInfo & info) const24 bool FaultLogJsError::ReportToAppEvent(std::shared_ptr<SysEvent> sysEvent, const FaultLogInfo& info) const
25 {
26     if (!info.reportToAppEvent || !sysEvent) {
27         return false;
28     }
29     errorReporter_.ReportErrorToAppEvent(sysEvent, "JsError", "/data/test_jsError_info");
30     return true;
31 }
32 
FaultLogJsError()33 FaultLogJsError::FaultLogJsError()
34 {
35     faultType_ = FaultLogType::JS_CRASH;
36 }
37 
GetFaultModule(SysEvent & sysEvent) const38 std::string FaultLogJsError::GetFaultModule(SysEvent& sysEvent) const
39 {
40     return sysEvent.GetEventValue(FaultKey::PACKAGE_NAME);
41 }
42 
FillSpecificFaultLogInfo(SysEvent & sysEvent,FaultLogInfo & info) const43 void FaultLogJsError::FillSpecificFaultLogInfo(SysEvent& sysEvent, FaultLogInfo& info) const
44 {
45     std::string rssStr = sysEvent.GetEventValue("PROCESS_RSS_MEMINFO");
46     info.sectionMap["PROCESS_RSS_MEMINFO"] = "Process Memory(kB): " + rssStr + "(Rss)";
47     auto trace = PageHistoryManager::GetInstance().GetPageHistory(info.module, info.pid);
48     if (!trace.empty()) {
49         info.sectionMap[FaultKey::PAGE_SWITCH_HISTORY] = std::move(trace);
50     }
51 }
52 } // namespace HiviewDFX
53 } // namespace OHOS
54