ITraceActivity.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. * Copyright (c) Meta Platforms, Inc. and affiliates.
  3. * All rights reserved.
  4. *
  5. * This source code is licensed under the BSD-style license found in the
  6. * LICENSE file in the root directory of this source tree.
  7. */
  8. #pragma once
  9. #include <string>
  10. #include "ActivityType.h"
  11. namespace libkineto {
  12. class ActivityLogger;
  13. struct TraceSpan;
  14. // Generic activity interface is borrowed from tensorboard protobuf format.
  15. struct ITraceActivity {
  16. virtual ~ITraceActivity() {}
  17. // Device is a physical or logical entity, e.g. CPU, GPU or process
  18. virtual int64_t deviceId() const = 0;
  19. // A resource is something on the device, h/w thread,
  20. // functional units etc.
  21. virtual int64_t resourceId() const = 0;
  22. // s/w thread
  23. virtual int32_t getThreadId() const = 0;
  24. // Start timestamp in nanoseconds
  25. virtual int64_t timestamp() const = 0;
  26. // Duration in nanoseconds
  27. virtual int64_t duration() const = 0;
  28. // Used to link up async activities
  29. virtual int64_t correlationId() const = 0;
  30. // Part of a flow, identified by flow id and type
  31. virtual int flowType() const = 0;
  32. virtual int64_t flowId() const = 0;
  33. virtual bool flowStart() const = 0;
  34. virtual ActivityType type() const = 0;
  35. virtual const std::string name() const = 0;
  36. // Optional linked activity
  37. virtual const ITraceActivity* linkedActivity() const = 0;
  38. // Optional containing trace object
  39. virtual const TraceSpan* traceSpan() const = 0;
  40. // Log activity
  41. virtual void log(ActivityLogger& logger) const = 0;
  42. // Return json formatted metadata
  43. // FIXME: Return iterator to dynamic type map here instead
  44. virtual const std::string metadataJson() const = 0;
  45. // Return the metadata value in string format with key
  46. // @lint-ignore CLANGTIDY: clang-diagnostic-unused-parameter
  47. virtual const std::string getMetadataValue(const std::string& key) const {
  48. return "";
  49. }
  50. static int64_t nsToUs(int64_t ns) {
  51. // It's important that this conversion is the same everywhere.
  52. // No rounding!
  53. return ns / 1000;
  54. }
  55. };
  56. } // namespace libkineto