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.

error_code.h 3.8 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /**
  2. * Copyright 2019 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_UTILS_LOG_DE_ERROR_CODE_H_
  17. #define MINDSPORE_CCSRC_UTILS_LOG_DE_ERROR_CODE_H_
  18. #include <map>
  19. #include <string>
  20. namespace DataEngineBase {
  21. // system ID
  22. const int SYSID_MD = 20;
  23. // Runtime location
  24. enum LogRuntime {
  25. RT_HOST = 0b01,
  26. RT_DEVICE = 0b10,
  27. };
  28. // sub model
  29. enum SubModuleId {
  30. COMMON_MODULE = 0,
  31. DATAGET_MODULE,
  32. MINDRECORD_MODULE,
  33. };
  34. // error code type
  35. enum ErrorCodeType {
  36. ERROR_CODE = 0b01,
  37. EXCEPTION_CODE = 0b10,
  38. };
  39. // error level
  40. enum ErrorLevel {
  41. COMMON_LEVEL = 0b000,
  42. SUGGESTION_LEVEL = 0b001,
  43. MINOR_LEVEL = 0b010,
  44. MAJOR_LEVEL = 0b011,
  45. CRITICAL_LEVEL = 0b100,
  46. };
  47. // code compose(4 byte), runtime: 2 bit, type: 2 bit, level: 3 bit, sysid: 8 bit, modid: 5 bit, value: 12 bit
  48. #define DE_ERRORNO(runtime, type, level, sysid, submodid, name, value, desc) \
  49. constexpr DataEngineBase::Status name = ((0xFF & ((uint8_t)runtime)) << 30) | ((0xFF & ((uint8_t)type)) << 28) | \
  50. ((0xFF & ((uint8_t)level)) << 25) | ((0xFF & ((uint8_t)sysid)) << 17) | \
  51. ((0xFF & ((uint8_t)submodid)) << 12) | (0x0FFF & ((uint16_t)value)); \
  52. const DataEngineBase::ErrorNoRegisterar g_##name##_errorno(name, desc);
  53. // each module defines error codes using the following macros
  54. #define DE_ERRORNO_COMMON(name, value, desc) \
  55. DE_ERRORNO(DataEngineBase::RT_HOST, DataEngineBase::ERROR_CODE, DataEngineBase::COMMON_LEVEL, \
  56. DataEngineBase::SYSID_MD, DataEngineBase::COMMON_MODULE, name, value, desc)
  57. #define DE_ERRORNO_DATASET(name, value, desc) \
  58. DE_ERRORNO(DataEngineBase::RT_HOST, DataEngineBase::ERROR_CODE, DataEngineBase::COMMON_LEVEL, \
  59. DataEngineBase::SYSID_MD, DataEngineBase::DATAGET_MODULE, name, value, desc)
  60. #define DE_ERRORNO_MINDRECORD(name, value, desc) \
  61. DE_ERRORNO(DataEngineBase::RT_HOST, DataEngineBase::ERROR_CODE, DataEngineBase::COMMON_LEVEL, \
  62. DataEngineBase::SYSID_MD, DataEngineBase::MINDRECORD_MODULE, name, value, desc)
  63. // get error code description
  64. #define DE_GET_ERRORNO_STR(value) DataEngineBase::StatusFactory::Instance()->GetErrDesc(value)
  65. class StatusFactory {
  66. public:
  67. static StatusFactory *Instance() {
  68. static StatusFactory instance;
  69. return &instance;
  70. }
  71. void RegisterErrorNo(uint32_t err, const std::string &desc) {
  72. if (err_desc_.find(err) != err_desc_.end()) return;
  73. err_desc_[err] = desc;
  74. }
  75. std::string GetErrDesc(uint32_t err) {
  76. auto iter_find = err_desc_.find(err);
  77. if (iter_find == err_desc_.end()) return "";
  78. return iter_find->second;
  79. }
  80. protected:
  81. StatusFactory() = default;
  82. ~StatusFactory() = default;
  83. private:
  84. std::map<uint32_t, std::string> err_desc_;
  85. };
  86. class ErrorNoRegisterar {
  87. public:
  88. ErrorNoRegisterar(uint32_t err, const std::string &desc) { StatusFactory::Instance()->RegisterErrorNo(err, desc); }
  89. ~ErrorNoRegisterar() = default;
  90. };
  91. using Status = uint32_t;
  92. } // namespace DataEngineBase
  93. #endif // MINDSPORE_CCSRC_UTILS_LOG_DE_ERROR_CODE_H_