Skip to content

Commit 7b0a63b

Browse files
guyang3532bertmahergdankelchaekitIlia Cherniavskii
authored
Merge master (#293)
* Put HeartbeatMonitor in a detail namespace (#143) Summary: Pull Request resolved: #143 I'm not actually sure there's any potential negative consequence here, but it's potentially harmful to use an anonymous namespace in a header, since it creates a unique symbol for each translation unit which can lead to ODR violations. I happened to notice a warning for this while building OSS pytorch :-) Reviewed By: gdankel Differential Revision: D27383716 fbshipit-source-id: 0fffc93478bc044a543b44011943652dc13c75cd * Fix C++14 compile error (#144) Summary: Pull Request resolved: #144 Accidentally used C++17 feature, and PyTorch still only supports C++14. Reviewed By: ilia-cher Differential Revision: D27422287 fbshipit-source-id: d5b72571f0272cb0cb25a395caf916ac3c16a4d3 * add JSON-formatted metadata for ClientTraceActivity (#164) Summary: Pull Request resolved: #164 Plan is to deprecate ClientTraceActivity and use a single concrete data structure to log all client side activities :`GenericTraceActivity`. CTA has a lot of explicit fields for metadata that are rarely used which results in sparse definition of activities. Instead of adding a new field, encode the key/value as a string. Note, more type-safe and rich alternative is `std::map` but we are not using it for performance reason. Reviewed By: gdankel Differential Revision: D27298829 fbshipit-source-id: b7a82081f983c5502f6d53104fc2d01ddee77b08 * deprecate metdata args from ClientTraceActivity (#55988) Summary: Pull Request resolved: pytorch/pytorch#55988 Pull Request resolved: #165 as part of the ClientTraceActivity -> GenericTraceActivity migration, move all the metadata fields to JSON encoded string Reviewed By: gdankel Differential Revision: D27340314 fbshipit-source-id: f55b77a779e4bda1fb8667cb4e0f4252b93af5ea * deprecate pthreadid (#56209) Summary: Pull Request resolved: pytorch/pytorch#56209 Pull Request resolved: #172 in this diff of the stack, we remove the threadId field from the ClientTraceActivity as our step towards the deprecation Reviewed By: ilia-cher Differential Revision: D27662747 fbshipit-source-id: 040ba040390680a0fc63ddc8149c6fad940439fc * Fix empty metadata invalid json (#173) Summary: Pull Request resolved: #173 Fix a case of invalid json when metadata is empty Reviewed By: chaekit Differential Revision: D27837639 fbshipit-source-id: 24c80671d8a15ac2d39096d401a5ec05b3339317 * Fix OSS compilation error (#176) Summary: Pull Request resolved: #176 In OSS not all builds support nodiscard https://app.circleci.com/pipelines/github/pytorch/pytorch/305130/workflows/1885277b-9d54-4637-ab9f-7234be2f2ee2/jobs/12588162 Reviewed By: dzhulgakov Differential Revision: D27872203 fbshipit-source-id: 711712f5b819fd4faf21da1c363b70960acf9518 * Support for trace metadata (#192) Summary: Pull Request resolved: #192 Add user-defined metadata api Reviewed By: gdankel Differential Revision: D27906278 fbshipit-source-id: 601de1e6f7ce61ed2cc62dd7d9a4bd3d4c955286 * Fix TraceActivity forward declaration (#199) Summary: Types defined as `struct` should be forward declared as struct https://github.com/pytorch/kineto/blob/5bc9386b6d60c3b34b77961ea2900947103304b9/libkineto/include/TraceActivity.h#L21 Find while working on making PyTorch clang-tidy compliant Pull Request resolved: #199 Reviewed By: ilia-cher Differential Revision: D28092540 Pulled By: malfet fbshipit-source-id: 428a5e762002f763f636957f8c207122f411f3c0 * Deprecate ClientTraceActivity and merge it with GenericTraceActivity (#56743) Summary: Pull Request resolved: pytorch/pytorch#56743 Pull Request resolved: #184 as part of the migration to ClientTraceActivity -> GenericTraceActivity, now that all CTA mirrors GTA's data structure, we can safely swap out the symbol name. Reviewed By: gdankel Differential Revision: D27353973 fbshipit-source-id: 7012c6524c3c75079029ac290c1dd722ac187ec5 * Expand Kineto profiler support (part 1) (#57333) Summary: Pull Request resolved: pytorch/pytorch#57333 Pull Request resolved: #193 Expanding Kineto support to more platforms Reviewed By: gdankel Differential Revision: D27873669 fbshipit-source-id: 4a72a589f958440cbfff247751b7f4e1910a10c7 * Refactor CuptiActivityBuffer Summary: Refactor for better readability. Also add locks to ensure CUPTI threads and profiler threads don't interfere. Reviewed By: chaekit Differential Revision: D28051462 fbshipit-source-id: c8a4f75b47c20f8467145728d4b38da8bdfcdccd * Fix a couple of trace collection corner cases Summary: Fixes two issues: 1) Back-to-back collections hit concurrency issue in the observer. 2) Early exit due to running out of buffers during warmup is broken due to missing break statement. Reviewed By: leitian, ilia-cher Differential Revision: D28051464 fbshipit-source-id: 7ddc46a344af2a922ee8f7e904b1b4e48bfac773 * Minor refactoring of per-op metadata Summary: I hit some jemalloc aborts (size mismatch) occasionally when freeing metadata strings. Not entirely sure I understand why but I have simplified the code and the issue has disappeared. Reviewed By: chaekit Differential Revision: D28051465 fbshipit-source-id: 699515409d6600f7aea14a96c1dac6fb9cad311e * Allow specifying CPU_OP as activity type via config Summary: CPU_OP was missing from the available activity types. It should be possible to profile only CPU ops, or to exclude them. Reviewed By: chaekit Differential Revision: D28051461 fbshipit-source-id: 2cfc3e4262b39ad08e38d7bf79541ce0cca97e60 * Shorten default warmup period Summary: The current warmup time is extremely conservative and not needed for the vast majority of workloads. Change the default to something more reasonable: 5s. Reviewed By: chaekit Differential Revision: D28051463 fbshipit-source-id: 3919342978e7137c0bd9d57536ee1e59eeb2f704 * Remove distinction between active and inactive profiler interval (#201) Summary: Pull Request resolved: #201 Previously tracing buffers were being cleared frequently during warmup in order to stay under the buffer memory limit. But most use cases need at least 1-2s active trace time to capture multiple iterations and so clearing the buffers every 1s seems sufficient. Reviewed By: chaekit Differential Revision: D28094676 fbshipit-source-id: a6a99ff02c710587a467d1d607964939bf23f39e * add 2 kernel metrics (#185) Summary: 1. Update "warps per sm" to "blocks per sm". 2. Add "occupancy" per kernel. Pull Request resolved: #185 Reviewed By: chaekit Differential Revision: D28120846 Pulled By: gdankel fbshipit-source-id: c7ce33b1421b60ae4323c66d38bba5eb175b105b * Fix empty metadata invalid json (#205) Summary: Pull Request resolved: #205 Fix invalid json in case of empty metadata Reviewed By: rohan-varma Differential Revision: D28239004 fbshipit-source-id: 3e2930b1b80a5d5f6c6f92de7eee899729a048dc * set the correct device id for GenericTraceActivity Summary: while merging ClientTraceActivity and GenericTraceActivity, we accidentally adopted CTA's behavior of returning process id over its `device`. This causes GTA to show up in CPU timeline rather than associated GPU's Reviewed By: gdankel Differential Revision: D28196723 fbshipit-source-id: eb8330c14e7c43a470bb4df4811b80754d96535b * Fix clock discrepancy (#207) Summary: Pull Request resolved: #207 Different platforms may use different aliases for clocks, fixing the discrepancy by specifying system_clock directly Reviewed By: gdankel Differential Revision: D28272403 fbshipit-source-id: 79df6c3e67cf883ca73146a15a9de2ce226891ae * Support for memory allocs/deallocs in the traces (#57835) Summary: Pull Request resolved: pytorch/pytorch#57835 Pull Request resolved: #208 Adding ability to save memory allocs/deallocs into the trace Reviewed By: gdankel Differential Revision: D28260915 fbshipit-source-id: d7905d38d7fac9750754ac1b293d3a1951590b5f * Rename theoretical occupancy to est. achieved occupancy (#210) Summary: Pull Request resolved: #210 Theoretical occupancy is used in Nvidia docs to mean the occupancy a kernel could achieve given sufficient input parallelism (grid size). It's more interesting in a trace to know what occupancy is actually achieved. Then if it's low, theoretical occupancy can be studied for each kernel to estimate improvement from increasing grid size. But that's something we can do as part of a recommendation or tutorial. Reviewed By: ilia-cher Differential Revision: D28327605 fbshipit-source-id: 80b54a955fa2885dbbd45006c45f2fb0d9fca2d2 * Log compute properties to trace file (#211) Summary: Pull Request resolved: #211 Device properties are useful in any case, but especially for performing analysis on traces such as occupancy. This patch is a re-implementation of #209 Reviewed By: ilia-cher Differential Revision: D28337067 fbshipit-source-id: 87267d53bdc1c257db452319339518539b81efed * Kineto cmake fix (#216) Summary: Pull Request resolved: #216 Check the variable value before adding dep on cupti Reviewed By: gdankel, malfet Differential Revision: D28363222 fbshipit-source-id: 09f7da1e756ee35559e79ec7a2e5018223f5a12f * Call [Get|Set]ThreadDescription via runtime linking (#224) Summary: SetThreadDescription is not available on some older runtimes/older versions of Windows, which can lead to to following linker errors: ``` kineto.lib(ThreadUtil.cpp.obj) : error LNK2019: unresolved external symbol __imp_SetThreadDescription referenced in function "bool __cdecl libkineto::setThreadName(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (?setThreadName@libkineto@YA_NAEBV?$basic_string@DU?$char_traits@D@std@V?$allocator@D@2@std@@z) ``` Use runtime linking method recommended in See https://docs.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-setthreaddescription Pull Request resolved: #224 Reviewed By: ilia-cher Differential Revision: D28404596 Pulled By: malfet fbshipit-source-id: 01937821a131aeff562aed5ebf274eac74bd816e * Get rid of tautological check (#225) Summary: `daemonConfigLoaderFactory` is a function and therefore always non-null Fixes following clang warning: ``` ../third_party/kineto/libkineto/src/ConfigLoader.cpp:161:7: warning: address of function 'daemonConfigLoaderFactory' will always evaluate to 'true' [-Wpointer-bool-conversion] if (daemonConfigLoaderFactory && daemonConfigLoaderFactory()) { ^~~~~~~~~~~~~~~~~~~~~~~~~ ~~ ``` Pull Request resolved: #225 Reviewed By: ilia-cher Differential Revision: D28405389 Pulled By: malfet fbshipit-source-id: 3930ab1acd6f2909602eada246d9ad01d9a923e3 * Remove dependency on CuptiInterface from loggers Summary: Now that we're extracting SM count from CUDA API in the chrome trace logger, there is no longer any need for passing in the CUPTI API wrapper. Reviewed By: ilia-cher Differential Revision: D28579642 fbshipit-source-id: 75004e092d3bc9c26435a02ce1a2034c0ea70004 * Add support for multiple protocols in client API (#251) Summary: Pull Request resolved: #251 Add a way to add support for multiple protocols and associated logger objects. Reviewed By: ilia-cher Differential Revision: D28579660 fbshipit-source-id: 497c45eca0529ba0620d635c6605fc0f20172d9c * Invert ConfigLoader -> profiler dependency (#271) Summary: Pull Request resolved: #271 Change direction of dependency from ConfigLoader -> profiler to profiler -> ConfigLoader. This way, the profiler is able to lazily initialize config loader and also move towards the pluggable profiler design. Reviewed By: xw285cornell Differential Revision: D28802798 fbshipit-source-id: 56e88b223fe8fc5276500e1b9a19c602450ae6dc * Revert verbose logging Summary: Verbose logging was accidentally left enabled, revert. Reviewed By: ilia-cher Differential Revision: D28916054 fbshipit-source-id: 9dd3bd831190f246990f1fe17c04ea505ce219e5 * Back out "Invert ConfigLoader -> profiler dependency" Summary: S233925 Reviewed By: satgera, xw285cornell Differential Revision: D28907829 fbshipit-source-id: 2224720c178fb885d8dccb8a38f50c856e48bdd7 * Refactor trace activities (#59360) Summary: Pull Request resolved: pytorch/pytorch#59360 Pull Request resolved: #206 Replace ClientTraceActivity with GenericActivity. In addition: * Add a couple of new activity types for user annotations * Simplify code for GPU-side user annotations * Add accessor to containing trace span object in activities. Later we can replace this with a trace context / trace session object. * Simplified MemoryTraceLogger * Added early exit for cupti push/pop correlation ID Reviewed By: ilia-cher Differential Revision: D28231675 fbshipit-source-id: 7129f2493016efb4d3697094f24475e2c39e6e65 * add activity profiler plugin interface and test (#202) Summary: Pull Request resolved: #202 # Activity Profiler Interface Adds the child Activiity profiler interface and implementation. This interface can be used by libraries and frameworks to supply trace events to Kineto. The first version only consolidates trace events and does not handle correlation yet. ## Details * Add Activity Profiler interface header that includes both profiler and the profiler session. A session manages all the trace event data captured by the respective profiler * Also had to move GenericTrace activity to includes dir as it used in the profiler session interface. * Creates sessions and starts and stops them in the primary ActivityProfilers flow. * First use-case is to integrate with Glow (Graph Lowering Compiler) , adding a glow_runtime event type for it. https://github.com/pytorch/glow/blob/master/docs/Tracing.md Reviewed By: gdankel Differential Revision: D27601906 fbshipit-source-id: 38e608a3a1a6e1b9e69f80d07312e388ed7ad339 * Do not leak file descriptors in processName() (#281) Summary: Each `fopen()` must be followed by `fclose()` Pull Request resolved: #281 Reviewed By: seemethere Differential Revision: D29008280 Pulled By: malfet fbshipit-source-id: 2171740a4f95bb980fe41cae1080f38458069836 * Merge Plugin/0.2 (#284) Summary: Pull Request resolved: #284 Reviewed By: leitian, chaekit Differential Revision: D29052618 Pulled By: gdankel fbshipit-source-id: 9f38cdfc7c7e73f5f62844ef857ebe6fed46f30a * Read base config via daemon (#291) Summary: Pull Request resolved: #291 In container setups, libkineto may not be able to read config file from the host file system, so add a path to retrieve it from the daemon. Reviewed By: briancoutinho Differential Revision: D28877610 fbshipit-source-id: a5f513524ac7afea14a7089677c5eff96b3530c6 Co-authored-by: Bert Maher <[email protected]> Co-authored-by: Gisle Dankel <[email protected]> Co-authored-by: Jay Chae <[email protected]> Co-authored-by: Ilia Cherniavskii <[email protected]> Co-authored-by: Nikita Shulga <[email protected]> Co-authored-by: Teng Gao <[email protected]> Co-authored-by: Chris Cai <[email protected]> Co-authored-by: Brian Coutinho <[email protected]>
1 parent 112e1b7 commit 7b0a63b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+1789
-997
lines changed

libkineto/CMakeLists.txt

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,19 @@ endif()
4242

4343
# Set LIBKINETO_NOCUPTI to explicitly disable CUPTI
4444
# Otherwise, CUPTI is disabled if not found
45-
IF (NOT CUDA_SOURCE_DIR AND NOT CUPTI_INCLUDE_DIR)
45+
IF (NOT CUDA_SOURCE_DIR OR NOT CUPTI_INCLUDE_DIR OR NOT CUDA_cupti_LIBRARY)
4646
set(LIBKINETO_NOCUPTI ON CACHE BOOL "" FORCE)
4747
endif()
4848

4949
# Define file lists
5050
if (LIBKINETO_NOCUPTI)
51-
get_filelist("get_libkineto_cpu_only_srcs()" LIBKINETO_SRCS)
51+
get_filelist("get_libkineto_cpu_only_srcs(with_api=False)" LIBKINETO_SRCS)
5252
message(INFO " CUPTI unavailable or disabled - not building GPU profilers")
5353
else()
54-
get_filelist("get_libkineto_srcs()" LIBKINETO_SRCS)
54+
get_filelist("get_libkineto_srcs(with_api=False)" LIBKINETO_SRCS)
5555
endif()
5656
get_filelist("get_libkineto_public_headers()" LIBKINETO_PUBLIC_HEADERS)
57-
set(LIBKINETO_API_SRCS "${LIBKINETO_SOURCE_DIR}/libkineto_api.cpp")
57+
get_filelist("get_libkineto_api_srcs()" LIBKINETO_API_SRCS)
5858

5959
add_library(kineto_base OBJECT ${LIBKINETO_SRCS})
6060
add_library(kineto_api OBJECT ${LIBKINETO_API_SRCS})
@@ -69,13 +69,22 @@ set_target_properties(kineto_base kineto_api PROPERTIES
6969
CXX_EXTENSIONS NO
7070
CXX_VISIBILITY_PRESET hidden)
7171

72-
target_compile_options(kineto_base PRIVATE "-DKINETO_NAMESPACE=libkineto"
73-
"-std=gnu++14")
74-
target_compile_options(kineto_api PRIVATE "-std=gnu++14")
72+
set(KINETO_COMPILE_OPTIONS "-DKINETO_NAMESPACE=libkineto")
73+
list(APPEND KINETO_COMPILE_OPTIONS "-DFMT_HEADER_ONLY")
74+
if(NOT MSVC)
75+
list(APPEND KINETO_COMPILE_OPTIONS "-std=c++14")
76+
else()
77+
list(APPEND KINETO_COMPILE_OPTIONS "/std:c++14")
78+
list(APPEND KINETO_COMPILE_OPTIONS "-DWIN32_LEAN_AND_MEAN")
79+
list(APPEND KINETO_COMPILE_OPTIONS "-DNOGDI")
80+
endif()
7581
if (NOT LIBKINETO_NOCUPTI)
76-
target_compile_options(kineto_base PRIVATE "-DHAS_CUPTI")
82+
list(APPEND KINETO_COMPILE_OPTIONS "-DHAS_CUPTI")
7783
endif()
7884

85+
target_compile_options(kineto_base PRIVATE "${KINETO_COMPILE_OPTIONS}")
86+
target_compile_options(kineto_api PRIVATE "${KINETO_COMPILE_OPTIONS}")
87+
7988
if(NOT TARGET fmt)
8089
if(NOT FMT_SOURCE_DIR)
8190
set(FMT_SOURCE_DIR "${LIBKINETO_THIRDPARTY_DIR}/fmt"
@@ -95,6 +104,8 @@ if(NOT TARGET fmt)
95104
endif()
96105

97106
set(FMT_INCLUDE_DIR "${FMT_SOURCE_DIR}/include")
107+
message(STATUS "Kineto: FMT_SOURCE_DIR = ${FMT_SOURCE_DIR}")
108+
message(STATUS "Kineto: FMT_INCLUDE_DIR = ${FMT_INCLUDE_DIR}")
98109
if (NOT CUPTI_INCLUDE_DIR)
99110
set(CUPTI_INCLUDE_DIR "${CUDA_SOURCE_DIR}/extras/CUPTI/include")
100111
endif()
@@ -112,6 +123,7 @@ target_include_directories(kineto_base PUBLIC
112123
$<BUILD_INTERFACE:${CUDA_INCLUDE_DIRS}>)
113124

114125
target_include_directories(kineto_api PUBLIC
126+
$<BUILD_INTERFACE:${FMT_INCLUDE_DIR}>
115127
$<BUILD_INTERFACE:${LIBKINETO_INCLUDE_DIR}>)
116128

117129
if(KINETO_LIBRARY_TYPE STREQUAL "default")
@@ -132,10 +144,11 @@ else()
132144
message(FATAL_ERROR "Unsupported library type ${KINETO_LIBRARY_TYPE}")
133145
endif()
134146

135-
target_link_libraries(kineto "${CUDA_cupti_LIBRARY}")
136-
137-
target_link_libraries(kineto $<BUILD_INTERFACE:fmt>)
138-
add_dependencies(kineto fmt)
147+
if(NOT LIBKINETO_NOCUPTI)
148+
target_link_libraries(kineto "${CUDA_cupti_LIBRARY}")
149+
endif()
150+
target_link_libraries(kineto $<BUILD_INTERFACE:fmt::fmt-header-only>)
151+
add_dependencies(kineto fmt::fmt-header-only)
139152

140153
install(TARGETS kineto EXPORT kinetoLibraryConfig
141154
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}

libkineto/include/ActivityProfilerInterface.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#include <memory>
1111
#include <set>
12+
#include <thread>
1213
#include <vector>
1314

1415
#include "ActivityType.h"
@@ -17,7 +18,7 @@
1718
namespace libkineto {
1819

1920
class ActivityProfilerController;
20-
class CpuTraceBuffer;
21+
struct CpuTraceBuffer;
2122
class Config;
2223

2324
class ActivityProfilerInterface {
@@ -76,6 +77,14 @@ class ActivityProfilerInterface {
7677
virtual bool enableForRegion(const std::string& match) {
7778
return true;
7879
}
80+
81+
// Saves information for the current thread to be used in profiler output
82+
// Client must record any new kernel thread where the activity has occured.
83+
virtual void recordThreadInfo() {}
84+
85+
// Record trace metadata, currently supporting only string key and values,
86+
// values with the same key are overwritten
87+
virtual void addMetadata(const std::string& key, const std::string& value) = 0;
7988
};
8089

8190
} // namespace libkineto

libkineto/include/ActivityTraceInterface.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
namespace libkineto {
1414

15-
class TraceActivity;
15+
struct TraceActivity;
1616

1717
class ActivityTraceInterface {
1818
public:

libkineto/include/ActivityType.h

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,30 @@
77

88
#pragma once
99

10+
#include <array>
11+
#include <string>
12+
1013
namespace libkineto {
1114

1215
enum class ActivityType {
13-
CPU_OP,
16+
CPU_OP = 0, // cpu side ops
17+
USER_ANNOTATION,
18+
GPU_USER_ANNOTATION,
1419
GPU_MEMCPY,
1520
GPU_MEMSET,
16-
CONCURRENT_KERNEL,
21+
CONCURRENT_KERNEL, // on-device kernels
1722
EXTERNAL_CORRELATION,
18-
CUDA_RUNTIME
23+
CUDA_RUNTIME, // host side cuda runtime events
24+
GLOW_RUNTIME, // host side glow runtime events
25+
CPU_INSTANT_EVENT, // host side point-like events
26+
ENUM_COUNT
1927
};
2028

29+
const char* toString(ActivityType t);
30+
ActivityType toActivityType(const std::string& str);
31+
32+
// Return an array of all activity types except COUNT
33+
constexpr int activityTypeCount = (int)ActivityType::ENUM_COUNT;
34+
const std::array<ActivityType, activityTypeCount> activityTypes();
35+
2136
} // namespace libkineto

libkineto/include/ClientTraceActivity.h

Lines changed: 0 additions & 77 deletions
This file was deleted.
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/*
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
* All rights reserved.
4+
* This source code is licensed under the BSD-style license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
#pragma once
9+
10+
#include <fmt/format.h>
11+
#include <string>
12+
#include <thread>
13+
#include <vector>
14+
15+
#include "ThreadUtil.h"
16+
#include "TraceActivity.h"
17+
#include "TraceSpan.h"
18+
19+
namespace libkineto {
20+
21+
// @lint-ignore-every CLANGTIDY cppcoreguidelines-non-private-member-variables-in-classes
22+
// @lint-ignore-every CLANGTIDY cppcoreguidelines-pro-type-member-init
23+
class GenericTraceActivity : public TraceActivity {
24+
25+
public:
26+
GenericTraceActivity() = delete;
27+
28+
GenericTraceActivity(
29+
const TraceSpan& trace, ActivityType type, const std::string& name)
30+
: activityType(type), activityName(name), traceSpan_(&trace) {
31+
}
32+
33+
int64_t deviceId() const override {
34+
return device;
35+
}
36+
37+
int64_t resourceId() const override {
38+
return resource;
39+
}
40+
41+
int64_t timestamp() const override {
42+
return startTime;
43+
}
44+
45+
int64_t duration() const override {
46+
return endTime - startTime;
47+
}
48+
49+
int64_t correlationId() const override {
50+
return id;
51+
}
52+
53+
ActivityType type() const override {
54+
return activityType;
55+
}
56+
57+
const std::string name() const override {
58+
return activityName;
59+
}
60+
61+
const TraceActivity* linkedActivity() const override {
62+
return nullptr;
63+
}
64+
65+
const TraceSpan* traceSpan() const override {
66+
return traceSpan_;
67+
}
68+
69+
void log(ActivityLogger& logger) const override;
70+
71+
//Encode client side metadata as a key/value string.
72+
void addMetadata(const std::string& key, const std::string& value) {
73+
metadata_.push_back(fmt::format("\"{}\": {}", key, value));
74+
}
75+
76+
const std::string getMetadata() const {
77+
return fmt::format("{}", fmt::join(metadata_, ", "));
78+
}
79+
80+
virtual ~GenericTraceActivity() {};
81+
82+
int64_t startTime{0};
83+
int64_t endTime{0};
84+
int32_t id{0};
85+
int32_t device{0};
86+
int32_t resource{0};
87+
ActivityType activityType;
88+
std::string activityName;
89+
90+
private:
91+
const TraceSpan* traceSpan_;
92+
std::vector<std::string> metadata_;
93+
};
94+
95+
} // namespace libkineto

0 commit comments

Comments
 (0)