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 | |
9 | #pragma once |
10 | |
11 | #include <string> |
12 | |
13 | #include "ActivityType.h" |
14 | |
15 | namespace libkineto { |
16 | |
17 | class ActivityLogger; |
18 | struct TraceSpan; |
19 | |
20 | // Generic activity interface is borrowed from tensorboard protobuf format. |
21 | struct ITraceActivity { |
22 | virtual ~ITraceActivity() {} |
23 | // Device is a physical or logical entity, e.g. CPU, GPU or process |
24 | virtual int64_t deviceId() const = 0; |
25 | // A resource is something on the device, h/w thread, |
26 | // functional units etc. |
27 | virtual int64_t resourceId() const = 0; |
28 | // s/w thread |
29 | virtual int32_t getThreadId() const = 0; |
30 | // Start timestamp in mucrosecond |
31 | virtual int64_t timestamp() const = 0; |
32 | // Duration in microseconds |
33 | virtual int64_t duration() const = 0; |
34 | // Used to link up async activities |
35 | virtual int64_t correlationId() const = 0; |
36 | // Part of a flow, identified by flow id and type |
37 | virtual int flowType() const = 0; |
38 | virtual int flowId() const = 0; |
39 | virtual bool flowStart() const = 0; |
40 | virtual ActivityType type() const = 0; |
41 | virtual const std::string name() const = 0; |
42 | // Optional linked activity |
43 | virtual const ITraceActivity* linkedActivity() const = 0; |
44 | // Optional containing trace object |
45 | virtual const TraceSpan* traceSpan() const = 0; |
46 | // Log activity |
47 | virtual void log(ActivityLogger& logger) const = 0; |
48 | // Return json formatted metadata |
49 | // FIXME: Return iterator to dynamic type map here instead |
50 | virtual const std::string metadataJson() const = 0; |
51 | |
52 | static int64_t nsToUs(int64_t ns) { |
53 | // It's important that this conversion is the same everywhere. |
54 | // No rounding! |
55 | return ns / 1000; |
56 | } |
57 | }; |
58 | |
59 | } // namespace libkineto |
60 | |