ILoggerObserver.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
  2. /*
  3. * Copyright (c) Meta Platforms, Inc. and affiliates.
  4. * All rights reserved.
  5. *
  6. * This source code is licensed under the BSD-style license found in the
  7. * LICENSE file in the root directory of this source tree.
  8. */
  9. #pragma once
  10. #define NOGDI
  11. #include <string>
  12. // Stages in libkineto used when pushing logs to UST Logger.
  13. constexpr char kWarmUpStage[] = "Warm Up";
  14. constexpr char kCollectionStage[] = "Collection";
  15. constexpr char kPostProcessingStage[] = "Post Processing";
  16. // Special string in UST for determining if traces are empty
  17. constexpr char kEmptyTrace[] =
  18. "No Valid Trace Events (CPU/GPU) found. Outputting empty trace.";
  19. #if !USE_GOOGLE_LOG
  20. #include <map>
  21. #include <vector>
  22. #include <cstdint>
  23. #ifdef _MSC_VER
  24. // unset a predefined ERROR (windows)
  25. #undef ERROR
  26. #endif // _MSC_VER
  27. namespace libkineto {
  28. enum LoggerOutputType {
  29. VERBOSE = 0,
  30. INFO = 1,
  31. WARNING = 2,
  32. STAGE = 3,
  33. ERROR = 4,
  34. ENUM_COUNT = 5
  35. };
  36. const char* toString(LoggerOutputType t);
  37. LoggerOutputType toLoggerOutputType(const std::string& str);
  38. constexpr int LoggerTypeCount = (int)LoggerOutputType::ENUM_COUNT;
  39. class ILoggerObserver {
  40. public:
  41. virtual ~ILoggerObserver() = default;
  42. virtual void write(const std::string& message, LoggerOutputType ot) = 0;
  43. virtual const std::map<LoggerOutputType, std::vector<std::string>>
  44. extractCollectorMetadata() = 0;
  45. virtual void reset() = 0;
  46. virtual void addDevice(const int64_t device) = 0;
  47. virtual void setTraceDurationMS(const int64_t duration) = 0;
  48. virtual void addEventCount(const int64_t count) = 0;
  49. virtual void setTraceID(const std::string& /*unused*/) {}
  50. virtual void setGroupTraceID(const std::string& /*unused*/) {}
  51. virtual void addDestination(const std::string& dest) = 0;
  52. virtual void setTriggerOnDemand() {}
  53. virtual void addMetadata(
  54. const std::string& key,
  55. const std::string& value) = 0;
  56. };
  57. } // namespace libkineto
  58. #endif // !USE_GOOGLE_LOG
  59. #else
  60. #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
  61. #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)