1 /** 2 * Copyright (c) 2021-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 #ifndef PANDA_TOOLS_SAMPLER_CONVERTER_IMPL_H 17 #define PANDA_TOOLS_SAMPLER_CONVERTER_IMPL_H 18 19 #include "libpandabase/os/filesystem.h" 20 #include "libpandabase/utils/utf.h" 21 22 #include "runtime/tooling/sampler/sample_info.h" 23 #include "runtime/tooling/sampler/sample_reader-inl.h" 24 #include "tools/sampler/trace_dumper.h" 25 #include "tools/sampler/args_parser.h" 26 27 #include <optional> 28 29 namespace ark::tooling::sampler { 30 31 struct SubstituteModules { 32 std::vector<std::string> source; 33 std::vector<std::string> destination; 34 }; 35 36 class AsptConverter { 37 public: 38 NO_COPY_SEMANTIC(AsptConverter); 39 NO_MOVE_SEMANTIC(AsptConverter); 40 41 using StackTraceMap = std::unordered_map<SampleInfo, size_t>; 42 AsptConverter(const char * filename)43 explicit AsptConverter(const char *filename) : reader_(filename) {} 44 ~AsptConverter() = default; 45 46 size_t CollectTracesStats(); 47 48 bool CollectModules(); 49 50 bool BuildModulesMap(); 51 52 void BuildMethodsMap(); 53 54 void SubstituteDirectories(std::string *pathname) const; 55 56 bool DumpModulesToFile(const std::string &outname) const; 57 58 bool DumpResolvedTracesAsCSV(const char *filename); 59 60 bool RunWithOptions(const Options &cliOptions); 61 62 bool RunDumpModulesMode(const std::string &outname); 63 64 bool RunDumpTracesInCsvMode(const std::string &outname); 65 66 static DumpType GetDumpTypeFromOptions(const Options &cliOptions); 67 68 private: 69 void BuildMethodsMapHelper(const panda_file::File *pf, Span<const uint32_t> &classesSpan); 70 71 SampleReader reader_; 72 73 std::vector<FileInfo> modules_; 74 75 ModuleMap modulesMap_; 76 MethodMap methodsMap_; 77 StackTraceMap stackTraces_; 78 79 DumpType dumpType_ {DumpType::THREAD_SEPARATION_BY_TID}; 80 bool buildColdGraph_ {false}; 81 82 bool buildSystemFrames_ {false}; 83 84 std::optional<SubstituteModules> substituteDirectories_; 85 }; 86 87 } // namespace ark::tooling::sampler 88 89 #endif // PANDA_TOOLS_SAMPLER_CONVERTER_IMPL_H 90