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 "executor/memory/dump_jsheap_info.h"
17 #include "executor/memory/memory_util.h"
18 #include "executor/memory/memory_info.h"
19 #include "hilog_wrapper.h"
20 #include "util/string_utils.h"
21 using namespace std;
22 namespace OHOS {
23 namespace HiviewDFX {
DumpJsHeapInfo()24 DumpJsHeapInfo::DumpJsHeapInfo()
25 {
26 }
27 
~DumpJsHeapInfo()28 DumpJsHeapInfo::~DumpJsHeapInfo()
29 {
30 }
31 
DumpJsHeapMemory(OHOS::AppExecFwk::JsHeapDumpInfo & info)32 bool DumpJsHeapInfo::DumpJsHeapMemory(OHOS::AppExecFwk::JsHeapDumpInfo &info)
33 {
34     DUMPER_HILOGI(MODULE_SERVICE, "DumpJsHeapMemory pid:%{public}d, tid:%{public}d, "
35         "needGc:%{public}d, needSnapshot:%{public}d",
36         info.pid, info.tid, info.needGc, info.needSnapshot);
37 #ifdef HIDUMPER_ABILITY_RUNTIME_ENABLE
38     OHOS::sptr<OHOS::ISystemAbilityManager> systemAbilityManager =
39         OHOS::SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
40     OHOS::sptr<OHOS::AppExecFwk::IAppMgr> appManager =
41         OHOS::iface_cast<OHOS::AppExecFwk::IAppMgr>(systemAbilityManager->GetSystemAbility(OHOS::APP_MGR_SERVICE_ID));
42     if (appManager == nullptr) {
43         DUMPER_HILOGE(MODULE_SERVICE, "DumpJsHeapMemory: Get the appManager is nullptr.");
44         return false;
45     }
46     int ret = appManager->DumpJsHeapMemory(info);
47     if (ret != ERR_OK) {
48         DUMPER_HILOGE(MODULE_SERVICE, "DumpJsHeapMemory return failed, ret is:%{public}d", ret);
49         return false;
50     }
51 #endif
52     return true;
53 }
54 } // namespace HiviewDFX
55 } // namespace OHOS
56