• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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 "executor/memory_dumper.h"
16 #include "dump_common_utils.h"
17 
18 using namespace std;
19 namespace OHOS {
20 namespace HiviewDFX {
MemoryDumper()21 MemoryDumper::MemoryDumper()
22 {
23     if (memoryInfo_ == nullptr) {
24         memoryInfo_ = std::make_unique<MemoryInfo>();
25     }
26 }
27 
~MemoryDumper()28 MemoryDumper::~MemoryDumper()
29 {
30 }
31 
PreExecute(const shared_ptr<DumperParameter> & parameter,StringMatrix dumpDatas)32 DumpStatus MemoryDumper::PreExecute(const shared_ptr<DumperParameter> &parameter, StringMatrix dumpDatas)
33 {
34     pid_ = parameter->GetOpts().memPid_;
35     DUMPER_HILOGD(MODULE_SERVICE, "MemoryDumper pid:%d\n", pid_);
36     dumpDatas_ = dumpDatas;
37     return DumpStatus::DUMP_OK;
38 }
39 
Execute()40 DumpStatus MemoryDumper::Execute()
41 {
42     if (dumpDatas_ != nullptr && memoryInfo_ != nullptr) {
43         if (pid_ >= 0) {
44             bool success = memoryInfo_->GetMemoryInfoByPid(pid_, dumpDatas_);
45             if (success) {
46                 status_ = DumpStatus::DUMP_OK;
47             } else {
48                 status_ = DumpStatus::DUMP_FAIL;
49             }
50         } else {
51             status_ = memoryInfo_->GetMemoryInfoNoPid(dumpDatas_);
52         }
53     }
54 
55     return status_;
56 }
57 
AfterExecute()58 DumpStatus MemoryDumper::AfterExecute()
59 {
60     return status_;
61 }
62 } // namespace HiviewDFX
63 } // namespace OHOS