From e28e839127998f3fe08e33416eb4cc45f6e90577 Mon Sep 17 00:00:00 2001 From: taoxiangdong Date: Fri, 25 Dec 2020 16:45:46 +0800 Subject: [PATCH] Parse training trace switch in profstart --- ge/common/profiling/profiling_manager.cc | 14 ++- tests/ut/ge/CMakeLists.txt | 2 +- .../ge_profiling_manager_unittest.cc | 117 +++--------------- 3 files changed, 25 insertions(+), 108 deletions(-) diff --git a/ge/common/profiling/profiling_manager.cc b/ge/common/profiling/profiling_manager.cc index 73d0cc3c..52fd3d2d 100644 --- a/ge/common/profiling/profiling_manager.cc +++ b/ge/common/profiling/profiling_manager.cc @@ -94,8 +94,8 @@ ge::Status ProfilingManager::InitFromOptions(const Options &options, MsprofGeOpt if (options.profiling_mode == "1" && !options.profiling_options.empty()) { // enable profiling by ge option - if (memcpy_s(prof_conf.options, MSPROF_OPTIONS_DEF_LEN_MAX, options.profiling_options.c_str(), - options.profiling_options.size()) != EOK) { + if (strncpy_s(prof_conf.options, MSPROF_OPTIONS_DEF_LEN_MAX, options.profiling_options.c_str(), + MSPROF_OPTIONS_DEF_LEN_MAX - 1) != EOK) { GELOGE(INTERNAL_ERROR, "copy profiling_options failed."); return INTERNAL_ERROR; } @@ -125,11 +125,12 @@ ge::Status ProfilingManager::InitFromOptions(const Options &options, MsprofGeOpt return ge::PARAM_INVALID; } - if (memcpy_s(prof_conf.jobId, sizeof(prof_conf.jobId), options.job_id.c_str(), - sizeof(options.job_id.c_str())) != EOK) { + if (strncpy_s(prof_conf.jobId, MSPROF_OPTIONS_DEF_LEN_MAX, options.job_id.c_str(), + MSPROF_OPTIONS_DEF_LEN_MAX - 1) != EOK) { GELOGE(INTERNAL_ERROR, "copy job_id failed."); return INTERNAL_ERROR; } + GELOGI("Job id: %s, original job id: %s.", prof_conf.jobId, options.job_id.c_str()); #endif return ge::SUCCESS; } @@ -159,6 +160,7 @@ ge::Status ProfilingManager::ParseOptions(const std::string &options) { if (!fp_point_.empty() && !bp_point_.empty()) { GELOGI("Training trace bp fp is set, bp_point:%s, fp_point:%s.", bp_point_.c_str(), fp_point_.c_str()); } + is_training_trace_ = true; } catch (...) { GELOGE(FAILED, "Json prof_conf options is invalid."); return ge::PARAM_INVALID; @@ -632,6 +634,10 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status ProfilingManager::ProfSt uint64_t module, const std::map &config_para) { #ifdef DAVINCI_SUPPORT_PROFILING std::lock_guard lock(mutex_); + uint64_t training_trace_mask = module & PROF_TRAINING_TRACE_MASK; + if (training_trace_mask == PROF_TRAINING_TRACE_MASK) { + is_training_trace_ = true; + } int32_t device_num = 0; vector device_list; if (ProfParseParam(config_para, device_num, device_list) != SUCCESS) { diff --git a/tests/ut/ge/CMakeLists.txt b/tests/ut/ge/CMakeLists.txt index 77c55077..e6c0038d 100755 --- a/tests/ut/ge/CMakeLists.txt +++ b/tests/ut/ge/CMakeLists.txt @@ -681,7 +681,7 @@ set(SINGLE_OP_TEST_FILES ) set(PROFILING_MNG_TEST_FILES - #"profiling/ge_profiling_manager_unittest.cc" + "profiling/ge_profiling_manager_unittest.cc" ) set(OTHERS_TEST_FILES diff --git a/tests/ut/ge/profiling/ge_profiling_manager_unittest.cc b/tests/ut/ge/profiling/ge_profiling_manager_unittest.cc index 5027c988..ef19b516 100644 --- a/tests/ut/ge/profiling/ge_profiling_manager_unittest.cc +++ b/tests/ut/ge/profiling/ge_profiling_manager_unittest.cc @@ -37,121 +37,32 @@ class UtestGeProfilinganager : public testing::Test { void TearDown() override {} }; -class TestReporter : public Msprof::Engine::Reporter { - public: - TestReporter() {} - ~TestReporter() {} - - public: - int Report(const Msprof::Engine::ReporterData *data) { return 0; } - - int Flush() { return 0; } -}; - -class TestPluginIntf : public Msprof::Engine::PluginIntf { - public: - TestPluginIntf() {} - ~TestPluginIntf() {} - - public: - int Init(const Msprof::Engine::Reporter *reporter) { return 0; } - - int UnInit() { return 0; } -}; - TEST_F(UtestGeProfilinganager, init_success) { setenv("PROFILING_MODE", "true", true); Options options; options.device_id = 0; options.job_id = "0"; - string profiling_config; - - ProfilingManager::Instance().SetProfilingConfig(profiling_config); - - Status ret = ProfilingManager::Instance().Init(options); - EXPECT_EQ(ret, ge::SUCCESS); -} - -TEST_F(UtestGeProfilinganager, start_profiling_success) { - int32_t iter_num = 1; - - setenv("PROFILING_MODE", "true", true); - setenv("PROFILING_OPTIONS", "training_trace", true); - Options options; - string profiling_config; - - ProfilingManager::Instance().SetProfilingConfig(profiling_config); - - Status ret = ProfilingManager::Instance().Init(options); - EXPECT_EQ(ret, ge::SUCCESS); - ret = ProfilingManager::Instance().StartProfiling(iter_num, 0); - EXPECT_EQ(ret, ge::SUCCESS); + options.profiling_mode = "1"; + options.profiling_options = R"({"result_path":"/data/profiling","training_trace":"on","task_trace":"on","aicpu_trace":"on","fp_point":"Data_0","bp_point":"addn","ai_core_metrics":"ResourceConflictRatio"})"; - setenv("PROFILING_OPTIONS", "op_trance", true); - ret = ProfilingManager::Instance().Init(options); - EXPECT_EQ(ret, ge::SUCCESS); - ret = ProfilingManager::Instance().StartProfiling(iter_num, 0); - EXPECT_EQ(ret, ge::SUCCESS); -} - -TEST_F(UtestGeProfilinganager, stop_profiling_success) { - int32_t iter_num = 1; - Options options; - TestReporter test_reporter; + struct MsprofGeOptions prof_conf = {{ 0 }}; - string profiling_config; - ProfilingManager::Instance().SetProfilingConfig(profiling_config); - - Status ret = 0; - setenv("PROFILING_OPTIONS", "op_trance", true); - ret = ProfilingManager::Instance().Init(options); - EXPECT_EQ(ret, ge::SUCCESS); - ret = ProfilingManager::Instance().StartProfiling(iter_num, 0); + Status ret = ProfilingManager::Instance().InitFromOptions(options, prof_conf); EXPECT_EQ(ret, ge::SUCCESS); - ProfilingManager::Instance().StopProfiling(); -} - -TEST_F(UtestGeProfilinganager, plugin_impl_success) { - PluginImpl plugin_Impl("FMK"); - TestReporter test_reporter; - Msprof::Engine::Reporter *reporter_ptr = &test_reporter; - plugin_Impl.Init(reporter_ptr); - plugin_Impl.UnInit(); -} - -TEST_F(UtestGeProfilinganager, profiling_engine_impl_success) { - ProfilingEngineImpl profiling_engine_impl; - - Msprof::Engine::PluginIntf *plugin_ptr = new TestPluginIntf(); - profiling_engine_impl.ReleasePlugin(plugin_ptr); - - Msprof::Engine::PluginIntf *ptr = profiling_engine_impl.CreatePlugin(); - delete ptr; - ptr = nullptr; -} - -TEST_F(UtestGeProfilinganager, set_profilng_cfg_success) { - string profiling_config = "profiling_mode: true"; - ProfilingManager::Instance().SetProfilingConfig(profiling_config); } -TEST_F(UtestGeProfilinganager, init_from_cfg_success0) { - Options options; - string profiling_config = - "{\"startCfg\":[{\"deviceID\":\"0\",\"features\":[{\"name\":\"op_trace\",\"conf\":\"2\"}]}]}"; - ProfilingManager::Instance().SetProfilingConfig(profiling_config); +TEST_F(UtestGeProfilinganager, ParseOptions) { +setenv("PROFILING_MODE", "true", true); +Options options; +options.device_id = 0; +options.job_id = "0"; +options.profiling_mode = "1"; +options.profiling_options = R"({"result_path":"/data/profiling","training_trace":"on","task_trace":"on","aicpu_trace":"on","fp_point":"Data_0","bp_point":"addn","ai_core_metrics":"ResourceConflictRatio"})"; - Status ret = ProfilingManager::Instance().Init(options); - EXPECT_EQ(ret, ge::SUCCESS); -} -TEST_F(UtestGeProfilinganager, init_from_cfg_success1) { - Options options; - string profiling_config = - "{\"startCfg\":[{\"deviceID\":\"0\",\"features\":[{\"name\":\"test_trace\"}],\"jobID\":\"1231231231\"}]}"; - ProfilingManager::Instance().SetProfilingConfig(profiling_config); +struct MsprofGeOptions prof_conf = {{ 0 }}; - Status ret = ProfilingManager::Instance().Init(options); - EXPECT_EQ(ret, ge::SUCCESS); +Status ret = ProfilingManager::Instance().ParseOptions(options.profiling_options); +EXPECT_EQ(ret, ge::SUCCESS); }