• 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 
16 #include "executor/memory/dump_cjheap_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 {
DumpCjHeapInfo()24 DumpCjHeapInfo::DumpCjHeapInfo()
25 {
26 }
27 
~DumpCjHeapInfo()28 DumpCjHeapInfo::~DumpCjHeapInfo()
29 {
30 }
31 
DumpCjHeapMemory(OHOS::AppExecFwk::CjHeapDumpInfo & info)32 bool DumpCjHeapInfo::DumpCjHeapMemory(OHOS::AppExecFwk::CjHeapDumpInfo &info)
33 {
34     DUMPER_HILOGI(MODULE_SERVICE, "DumpCjHeapMemory pid:%{public}d, needGc:%{public}d, needSnapshot:%{public}d",
35         info.pid, info.needGc, info.needSnapshot);
36 #ifdef HIDUMPER_ABILITY_RUNTIME_ENABLE
37     OHOS::sptr<OHOS::ISystemAbilityManager> systemAbilityManager =
38         OHOS::SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
39     OHOS::sptr<OHOS::AppExecFwk::IAppMgr> appManager =
40         OHOS::iface_cast<OHOS::AppExecFwk::IAppMgr>(systemAbilityManager->GetSystemAbility(OHOS::APP_MGR_SERVICE_ID));
41     if (appManager == nullptr) {
42         DUMPER_HILOGE(MODULE_SERVICE, "DumpCjHeapMemory: Get the appManager is nullptr.");
43         return false;
44     }
45     int ret = appManager->DumpCjHeapMemory(info);
46     if (ret != ERR_OK) {
47         DUMPER_HILOGE(MODULE_SERVICE, "DumpCjHeapMemory return failed, ret is:%{public}d", ret);
48         return false;
49     }
50 #endif
51     return true;
52 }
53 } // namespace HiviewDFX
54 } // namespace OHOS
55