From 09e2d4bb887837506d271eab3d8ba8a6d51f9e1c Mon Sep 17 00:00:00 2001 From: yanghaitao1 Date: Mon, 27 Sep 2021 05:38:47 -0400 Subject: [PATCH] fix some review issues in profiler --- .../ccsrc/profiler/device/ascend/memory_profiling.cc | 9 ++++++++- .../ccsrc/profiler/device/ascend/memory_profiling.h | 1 - mindspore/ccsrc/profiler/device/gpu/gpu_data_saver.cc | 3 +++ mindspore/ccsrc/profiler/device/gpu/gpu_data_saver.h | 2 -- 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/mindspore/ccsrc/profiler/device/ascend/memory_profiling.cc b/mindspore/ccsrc/profiler/device/ascend/memory_profiling.cc index 20947217420..4afcf7e000b 100644 --- a/mindspore/ccsrc/profiler/device/ascend/memory_profiling.cc +++ b/mindspore/ccsrc/profiler/device/ascend/memory_profiling.cc @@ -36,7 +36,14 @@ bool MemoryProfiling::IsMemoryProfilingEnable() const { } const std::string prof_options_str = ascend_profiler->GetProfilingOptions(); - nlohmann::json options = nlohmann::json::parse(prof_options_str); + nlohmann::json options; + try { + options = nlohmann::json::parse(prof_options_str); + } catch (nlohmann::json::exception &e) { + MS_LOG(ERROR) << "Failed to parse profiling options."; + return false; + } + if (options["profile_memory"] == "off") { return false; } diff --git a/mindspore/ccsrc/profiler/device/ascend/memory_profiling.h b/mindspore/ccsrc/profiler/device/ascend/memory_profiling.h index d287e0721e7..8ad1ccc532b 100644 --- a/mindspore/ccsrc/profiler/device/ascend/memory_profiling.h +++ b/mindspore/ccsrc/profiler/device/ascend/memory_profiling.h @@ -108,7 +108,6 @@ class MemoryProfiling { } bool IsMemoryProfilingEnable() const; - MemoryProto &GetMemProto() { return memory_proto_; } std::shared_ptr AddGraphMemoryNode(uint32_t graph_id); std::shared_ptr GetGraphMemoryNode(uint32_t graph_id) const; void SetDeviceMemSize(uint64_t size) { device_mem_size_ = size; } diff --git a/mindspore/ccsrc/profiler/device/gpu/gpu_data_saver.cc b/mindspore/ccsrc/profiler/device/gpu/gpu_data_saver.cc index 3300b2e4925..b3b76829b5f 100644 --- a/mindspore/ccsrc/profiler/device/gpu/gpu_data_saver.cc +++ b/mindspore/ccsrc/profiler/device/gpu/gpu_data_saver.cc @@ -277,6 +277,7 @@ void GpuDataSaver::WriteStepTraceAsyncLaunchKernel(const std::string &saver_base } catch (const std::exception &e) { MS_LOG(ERROR) << "Write " << file_path << "failed:" << e.what(); ofs.close(); + return; } step++; } @@ -322,6 +323,7 @@ void GpuDataSaver::WriteStepTrace(const std::string &saver_base_dir) { } catch (const std::exception &e) { MS_LOG(ERROR) << "Write " << file_path << "failed:" << e.what(); ofs.close(); + return; } } } @@ -347,6 +349,7 @@ void GpuDataSaver::WriteStartTime(const std::string &saver_base_dir, const BaseT } catch (const std::exception &e) { MS_LOG(ERROR) << "Write " << file_path << "failed:" << e.what(); ofs.close(); + return; } ofs.close(); diff --git a/mindspore/ccsrc/profiler/device/gpu/gpu_data_saver.h b/mindspore/ccsrc/profiler/device/gpu/gpu_data_saver.h index 8477e36bf8b..8984d4b896e 100644 --- a/mindspore/ccsrc/profiler/device/gpu/gpu_data_saver.h +++ b/mindspore/ccsrc/profiler/device/gpu/gpu_data_saver.h @@ -64,8 +64,6 @@ using AllActivityInfos = std::unordered_map; // class GpuDataSaver : public DataSaver { public: - GpuDataSaver() = delete; - GpuDataSaver(ProfilingTraceInfo step_trace_op_name, const std::vector &all_step_start_end_info) : step_trace_op_name_(step_trace_op_name), all_step_start_end_info_(all_step_start_end_info) { step_trace_op_name_from_graph_ = step_trace_op_name;