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.

env_config_parser.h 2.3 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef MINDSPORE_CCSRC_DEBUG_ENV_CONFIG_PARSER_H_
  17. #define MINDSPORE_CCSRC_DEBUG_ENV_CONFIG_PARSER_H_
  18. #include <string>
  19. #include <map>
  20. #include <set>
  21. #include <mutex>
  22. #include "nlohmann/json.hpp"
  23. #include "utils/ms_utils.h"
  24. namespace mindspore {
  25. class EnvConfigParser {
  26. public:
  27. static EnvConfigParser &GetInstance() {
  28. static EnvConfigParser instance;
  29. instance.Parse();
  30. return instance;
  31. }
  32. void Parse();
  33. std::string ConfigPath() const { return config_file_; }
  34. bool HasRdrSetting() const { return has_rdr_setting_; }
  35. bool RdrEnabled() const { return rdr_enabled_; }
  36. std::string RdrPath() const { return rdr_path_; }
  37. private:
  38. EnvConfigParser() {}
  39. ~EnvConfigParser() {}
  40. std::mutex lock_;
  41. std::string config_file_{""};
  42. bool already_parsed_{false};
  43. bool rdr_enabled_{false};
  44. bool has_rdr_setting_{false};
  45. std::string rdr_path_{"./rdr/"};
  46. void ParseFromFile();
  47. void ParseFromEnv();
  48. std::string GetIfstreamString(const std::ifstream &ifstream);
  49. void ParseRdrSetting(const nlohmann::json &content);
  50. bool CheckJsonStringType(const nlohmann::json &content, const std::string &setting_key, const std::string &key);
  51. std::optional<nlohmann::detail::iter_impl<const nlohmann::json>> CheckJsonKeyExist(const nlohmann::json &content,
  52. const std::string &setting_key,
  53. const std::string &key);
  54. void ParseRdrPath(const nlohmann::json &content);
  55. void ParseRdrEnable(const nlohmann::json &content);
  56. void ConfigToString();
  57. };
  58. } // namespace mindspore
  59. #endif // MINDSPORE_CCSRC_DEBUG_ENV_CONFIG_PARSER_H_