diff --git a/mindspore/ccsrc/profiler/device/ascend/memory_profiling.cc b/mindspore/ccsrc/profiler/device/ascend/memory_profiling.cc index 7d54c6ec2af..53a808a6f33 100644 --- a/mindspore/ccsrc/profiler/device/ascend/memory_profiling.cc +++ b/mindspore/ccsrc/profiler/device/ascend/memory_profiling.cc @@ -46,6 +46,7 @@ void MemoryProfiling::StartMemoryProfiling() { is_enabled_ = true; if (NeedSaveMemoryProfiling()) { SaveMemoryProfiling(); + has_save_memory_data_ = true; } } @@ -143,7 +144,6 @@ void MemoryProfiling::SaveMemoryProfiling() { } handle.close(); - has_save_memory_data_ = true; MS_LOG(INFO) << "Start save memory profiling data to " << file << " end"; return; } diff --git a/mindspore/ccsrc/profiler/device/ascend/memory_profiling.h b/mindspore/ccsrc/profiler/device/ascend/memory_profiling.h index 42a751a4fb8..f2e270d8f18 100644 --- a/mindspore/ccsrc/profiler/device/ascend/memory_profiling.h +++ b/mindspore/ccsrc/profiler/device/ascend/memory_profiling.h @@ -115,7 +115,7 @@ class MemoryProfiling { bool IsMemoryProfilingInitialized() const { return is_initialized_; } bool IsMemoryProfilingEnabled() const { return is_enabled_; } void SetMemoryProfilingInitialize(const std::string &profiling_options); - bool NeedSaveMemoryProfiling() { return (is_enabled_) && (!has_save_memory_data_); } + bool NeedSaveMemoryProfiling() { return (is_enabled_) && (graph_memory_.size() != 0) && (!has_save_memory_data_); } void StartMemoryProfiling(); void StopMemoryProfiling();