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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. return instance;
  30. }
  31. void Parse();
  32. bool rdr_enabled() const { return rdr_enabled_; }
  33. std::string rdr_path() const { return rdr_path_; }
  34. private:
  35. EnvConfigParser() {}
  36. ~EnvConfigParser() {}
  37. std::mutex lock_;
  38. std::string config_file_{""};
  39. bool already_parsed_{false};
  40. bool rdr_enabled_{false};
  41. std::string rdr_path_{"./rdr/"};
  42. std::string GetIfstreamString(const std::ifstream &ifstream);
  43. void ParseRdrSetting(const nlohmann::json &content);
  44. bool CheckJsonStringType(const nlohmann::json &content, const std::string &setting_key, const std::string &key);
  45. std::optional<nlohmann::detail::iter_impl<const nlohmann::json>> CheckJsonKeyExist(const nlohmann::json &content,
  46. const std::string &setting_key,
  47. const std::string &key);
  48. void ParseRdrPath(const nlohmann::json &content);
  49. void ParseRdrEnable(const nlohmann::json &content);
  50. void ConfigToString();
  51. };
  52. } // namespace mindspore
  53. #endif // MINDSPORE_CCSRC_DEBUG_ENV_CONFIG_PARSER_H_