You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

options.cc 2.1 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /**
  2. * Copyright 2021 Huawei Technologies Co., Ltd
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. */
  15. #include <string>
  16. #include <climits>
  17. #include "profiler/device/ascend/options.h"
  18. #include "utils/ms_context.h"
  19. #include "debug/common.h"
  20. #include "profiler/device/ascend/ascend_profiling.h"
  21. constexpr char kOutputPath[] = "output";
  22. namespace mindspore {
  23. namespace profiler {
  24. namespace ascend {
  25. std::string GetOutputPath() {
  26. auto ascend_profiler = AscendProfiler::GetInstance();
  27. MS_EXCEPTION_IF_NULL(ascend_profiler);
  28. const std::string options_str = ascend_profiler->GetProfilingOptions();
  29. nlohmann::json options_json;
  30. try {
  31. options_json = nlohmann::json::parse(options_str);
  32. } catch (nlohmann::json::parse_error &e) {
  33. MS_LOG(EXCEPTION) << "Parse profiling option json failed, error:" << e.what();
  34. }
  35. auto iter = options_json.find(kOutputPath);
  36. if (iter != options_json.end() && iter->is_string()) {
  37. char real_path[PATH_MAX] = {0};
  38. if ((*iter).size() >= PATH_MAX) {
  39. MS_LOG(ERROR) << "Path is invalid for profiling.";
  40. return "";
  41. }
  42. #if defined(_WIN32) || defined(_WIN64)
  43. if (_fullpath(real_path, common::SafeCStr(*iter), PATH_MAX) == nullptr) {
  44. MS_LOG(ERROR) << "Path is invalid for memory profiling.";
  45. return "";
  46. }
  47. #else
  48. if (realpath(common::SafeCStr(*iter), real_path) == nullptr) {
  49. MS_LOG(ERROR) << "Path is invalid for profiling.";
  50. return "";
  51. }
  52. #endif
  53. return real_path;
  54. }
  55. MS_LOG(ERROR) << "Output path is not found when save profiling data";
  56. return "";
  57. }
  58. } // namespace ascend
  59. } // namespace profiler
  60. } // namespace mindspore