1 /** 2 * Copyright 2020-2023 Huawei Technologies Co., Ltd 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 #ifndef MINDSPORE_CORE_UTILS_TRACE_BASE_H_ 17 #define MINDSPORE_CORE_UTILS_TRACE_BASE_H_ 18 19 #include <fstream> 20 #include <memory> 21 #include <string> 22 #include <vector> 23 #include "utils/info.h" 24 #include "ir/anf.h" 25 #include "ir/func_graph.h" 26 #include "utils/any.h" 27 28 namespace mindspore { 29 namespace trace { 30 constexpr auto kSectionPrefix = " - "; 31 32 MS_CORE_API DebugInfoPtr GetSourceCodeDebugInfo(const DebugInfoPtr &info); 33 MS_CORE_API std::string GetDebugInfoStr(const DebugInfoPtr &info, const std::string &prefix = std::string(""), 34 SourceLineTip tip = kSourceLineTipNextLine, bool is_debug = false); 35 // Generate the call stack of python source code with relevant trace info 36 MS_CORE_API std::string GetTracedDebugInfoStr(const DebugInfoPtr &debug_info, bool is_debug = false); 37 // Generate the call stack of python source code to a string 38 MS_CORE_API std::string DumpSourceLines(const AnfNodePtr &node, bool has_title = true); 39 MS_CORE_API std::string DumpSourceLines(AnfNode *node, bool has_title = true); 40 // Generate the call stack of python source code to a vector 41 MS_CORE_API std::vector<std::string> GetSourceLineList(const AnfNodePtr &node); 42 MS_CORE_API std::vector<std::string> GetSourceLineList(const DebugInfoPtr &debug_info); 43 // Get the locations of the call stack of python source code 44 std::vector<LocationPtr> GetSourceLocationList(const AnfNodePtr &node); 45 } // namespace trace 46 } // namespace mindspore 47 48 #endif // MINDSPORE_CORE_UTILS_TRACE_BASE_H_ 49