|
- /**
- * Copyright 2020 Huawei Technologies Co., Ltd
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
- #include "profiling_properties.h"
- #include "framework/common/debug/ge_log.h"
- #include "framework/common/debug/log.h"
- #include "graph/ge_context.h"
-
- namespace {
- const uint64_t kMsProfOptionsMaxlen = 2048;
- const char *const kFpPoint = "fp_point";
- const char *const kBpPoint = "bp_point";
- } // namespace ge
-
- namespace ge{
- ProfilingProperties& ProfilingProperties::Instance() {
- static ProfilingProperties profiling_properties;
- return profiling_properties;
- }
-
- void ProfilingProperties::SetLoadProfiling(bool is_load_profiling) {
- std::lock_guard<std::mutex>lock(mutex_);
- is_load_profiling_ = is_load_profiling;
- }
-
- bool ProfilingProperties::IsLoadProfiling() {
- std::lock_guard<std::mutex>lock(mutex_);
- return is_load_profiling_;
- }
-
- void ProfilingProperties::SetExecuteProfiling(bool is_exec_profiling) {
- std::lock_guard<std::mutex>lock(mutex_);
- is_execute_profiling_ = is_exec_profiling;
- }
-
- bool ProfilingProperties::IsExecuteProfiling() {
- std::lock_guard<std::mutex>lock(mutex_);
- return is_execute_profiling_;
- }
-
- void ProfilingProperties::SetTrainingTrace(bool is_train_trance) {
- std::lock_guard<std::mutex>lock(mutex_);
- is_training_trace_ = is_train_trance;
- }
-
- void ProfilingProperties::GetFpBpPoint(std::string &fp_point, std::string &bp_point) {
- // Env or options mode, fp_point_/bp_point_ have initiliazed on profiling init
- std::lock_guard<std::mutex>lock(mutex_);
- if (!fp_point_.empty() && !bp_point_.empty()) {
- fp_point = fp_point_;
- bp_point = bp_point_;
- GELOGI("Bp Fp have been initialized in env or options. bp_point: %s, fp_point: %s", bp_point.c_str(),
- fp_point.c_str());
- return;
- }
- // ProfApi mode and training trace is set
- // Parse options first
- char env_profiling_options[kMsProfOptionsMaxlen] = {0x00};
- bool is_profiling_valid = false;
- std::string profiling_options;
- if (ge::GetContext().GetOption(OPTION_EXEC_PROFILING_OPTIONS, profiling_options) == SUCCESS &&
- !profiling_options.empty()) {
- is_profiling_valid = true;
- } else {
- INT32 ret = mmGetEnv("PROFILING_OPTIONS", env_profiling_options, kMsProfOptionsMaxlen);
- if (ret != EN_OK) {
- GELOGI("PROFILING_OPTIONS env is not exist.");
- return;
- }
- GELOGI("Parse env PROFILING_OPTIONS:%s.", env_profiling_options);
- profiling_options = env_profiling_options;
- is_profiling_valid = true;
- }
- if (is_profiling_valid) {
- try {
- Json prof_options = Json::parse(profiling_options);
- if (prof_options.contains(kFpPoint)) {
- fp_point_ = prof_options[kFpPoint];
- }
- if (prof_options.contains(kBpPoint)) {
- bp_point_ = prof_options[kBpPoint];
- }
- fp_point = fp_point_;
- bp_point = bp_point_;
- 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());
- }
- } catch (...) {
- GELOGW("Json prof options is invalid.");
- return;
- }
- }
-
- return;
- }
-
- } // namespace ge
|