output_base.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. #include <fstream>
  11. #include <map>
  12. #include <ostream>
  13. #include <thread>
  14. #include <unordered_map>
  15. // TODO(T90238193)
  16. // @lint-ignore-every CLANGTIDY facebook-hte-RelativeInclude
  17. #include "GenericTraceActivity.h"
  18. #include "IActivityProfiler.h"
  19. #include "ThreadUtil.h"
  20. #include "TraceSpan.h"
  21. namespace KINETO_NAMESPACE {
  22. struct ActivityBuffers;
  23. }
  24. namespace libkineto {
  25. using namespace KINETO_NAMESPACE;
  26. // Used by sortIndex to put GPU tracks at the bottom
  27. // of the trace timelines. The largest valid CPU PID is 4,194,304,
  28. // so 5000000 is enough to guarantee that GPU tracks are sorted after CPU.
  29. constexpr int64_t kExceedMaxPid = 5000000;
  30. class ActivityLogger {
  31. public:
  32. virtual ~ActivityLogger() = default;
  33. struct OverheadInfo {
  34. explicit OverheadInfo(const std::string& name) : name(name) {}
  35. const std::string name;
  36. };
  37. virtual void handleDeviceInfo(const DeviceInfo& info, uint64_t time) = 0;
  38. virtual void handleResourceInfo(const ResourceInfo& info, int64_t time) = 0;
  39. virtual void handleOverheadInfo(const OverheadInfo& info, int64_t time) = 0;
  40. virtual void handleTraceSpan(const TraceSpan& span) = 0;
  41. virtual void handleActivity(const libkineto::ITraceActivity& activity) = 0;
  42. virtual void handleGenericActivity(
  43. const libkineto::GenericTraceActivity& activity) = 0;
  44. virtual void handleTraceStart(
  45. const std::unordered_map<std::string, std::string>& metadata,
  46. const std::string& device_properties) = 0;
  47. void handleTraceStart() {
  48. handleTraceStart(std::unordered_map<std::string, std::string>(), "");
  49. }
  50. virtual void finalizeMemoryTrace(const std::string&, const Config&) = 0;
  51. virtual void finalizeTrace(
  52. const Config& config,
  53. std::unique_ptr<ActivityBuffers> buffers,
  54. int64_t endTime,
  55. std::unordered_map<std::string, std::vector<std::string>>& metadata) = 0;
  56. protected:
  57. ActivityLogger() = default;
  58. };
  59. } // namespace libkineto
  60. #else
  61. #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
  62. #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)