diff --git a/mindspore/ccsrc/profiler/device/ascend/memory_profiling.cc b/mindspore/ccsrc/profiler/device/ascend/memory_profiling.cc index 4c3a2227bad..ce037ed7cdb 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 cdef0eaeaa6..0aca67ddeea 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 baae89a1939..7e2709f04b0 100644 --- a/mindspore/ccsrc/profiler/device/gpu/gpu_data_saver.cc +++ b/mindspore/ccsrc/profiler/device/gpu/gpu_data_saver.cc @@ -281,6 +281,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++; } @@ -326,6 +327,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; } } } @@ -351,6 +353,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;