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.6 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. bool GetSysMemreuse() { return sys_memreuse_; }
  38. void SetSysMemreuse(bool set_memreuse) { sys_memreuse_ = set_memreuse; }
  39. private:
  40. EnvConfigParser() {}
  41. ~EnvConfigParser() {}
  42. std::mutex lock_;
  43. std::string config_file_{""};
  44. bool already_parsed_{false};
  45. bool rdr_enabled_{false};
  46. bool has_rdr_setting_{false};
  47. std::string rdr_path_{"./rdr/"};
  48. bool sys_memreuse_{true};
  49. void ParseFromFile();
  50. void ParseFromEnv();
  51. std::string GetIfstreamString(const std::ifstream &ifstream);
  52. void ParseRdrSetting(const nlohmann::json &content);
  53. bool CheckJsonStringType(const nlohmann::json &content, const std::string &setting_key, const std::string &key);
  54. std::optional<nlohmann::detail::iter_impl<const nlohmann::json>> CheckJsonKeyExist(const nlohmann::json &content,
  55. const std::string &setting_key,
  56. const std::string &key);
  57. void ParseRdrPath(const nlohmann::json &content);
  58. void ParseRdrEnable(const nlohmann::json &content);
  59. void ParseMemReuseSetting(const nlohmann::json &content);
  60. void ParseSysMemReuse(const nlohmann::json &content);
  61. void ConfigToString();
  62. };
  63. } // namespace mindspore
  64. #endif // MINDSPORE_CCSRC_DEBUG_ENV_CONFIG_PARSER_H_