• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "ecmascript/ecma_vm.h"
17 
18 namespace panda::ecmascript {
19 
20 const std::string PC_TOOL_HELP_MSG =
21     "Usage: ark_js_heap_snapshot_tool <bin_filename> <ouput_filename>\n"
22     "\tWill decode the heapdump bin file to the target file named ouput_filename\n";
23 
GetHelper()24 std::string GetHelper()
25 {
26     std::string str;
27     str.append(PC_TOOL_HELP_MSG);
28     return str;
29 }
30 
HeapSnapshotPcToolMain(const int argc,const char ** argv)31 int HeapSnapshotPcToolMain(const int argc, const char **argv)
32 {
33     if (argc < 3) { // 3: at least have 3 arguments
34         std::cerr << GetHelper();
35         return -1;
36     }
37 
38     int newArgc = argc;
39     std::string filePath = argv[argc - 2];
40     std::string outputPath = argv[argc - 1];
41     newArgc--;
42     JSRuntimeOptions runtimeOptions;
43 
44     EcmaVM *vm = JSNApi::CreateEcmaVM(runtimeOptions);
45     if (vm == nullptr) {
46         std::cerr << "Cannot Create vm" << std::endl;
47         return -1;
48     }
49     std::cout << "(INFO) ark Decode: " << filePath << std::endl;
50     DFXJSNApi::GenerateHeapSnapshotByBinFile(vm, filePath, outputPath);
51     JSNApi::DestroyJSVM(vm);
52     std::cout << "(INFO) ark HeapSnapshotPcToolMain finished" << std::endl;
53     return 0;
54 }
55 }  // namespace panda::ecmascript
56 
57 
main(int argc,char const * argv[])58 int main([[maybe_unused]] int argc, [[maybe_unused]] char const *argv[])
59 {
60     return panda::ecmascript::HeapSnapshotPcToolMain(argc, argv);
61 }
62