Skip to content

Commit

Permalink
Setters and getters for trace IDs (#967)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #967

This commit moves the trace ID initialization logic to be inline with how ActivityProfilers interact with LoggerObservers by setting a default local trace ID when a profiler config does not contain a trace ID.

The USTLoggerCollector, which is our internal LoggerObserver will record the trace ID for a given environment (which is a PID today) using the `setTraceID` method that all LoggerObservers must staisfy. Additionally any internal calls to read this trace ID, for example from our ManifoldChromeTrace logger, may use a special `getTraceID` method that ships with `USTLoggerCollector`.

Group trace IDs are handled accordingly.

Differential Revision: D60267172
  • Loading branch information
sanrise authored and facebook-github-bot committed Jul 26, 2024
1 parent c2bc752 commit 41a8948
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
4 changes: 4 additions & 0 deletions libkineto/src/ActivityProfilerController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ void ActivityProfilerController::setLoggerCollectorFactory(
std::function<std::shared_ptr<LoggerCollector>()> factory) {
loggerCollectorFactory() = factory();
}

std::shared_ptr<LoggerCollector> ActivityProfilerController::getLoggerCollector() {
return loggerCollectorFactory();
}
#endif // !USE_GOOGLE_LOG

ActivityProfilerController::ActivityProfilerController(
Expand Down
1 change: 1 addition & 0 deletions libkineto/src/ActivityProfilerController.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class ActivityProfilerController : public ConfigLoader::ConfigHandler {
~ActivityProfilerController();

#if !USE_GOOGLE_LOG
static std::shared_ptr<LoggerCollector> getLoggerCollector();
static void setLoggerCollectorFactory(
std::function<std::shared_ptr<LoggerCollector>()> factory);
#endif // !USE_GOOGLE_LOG
Expand Down
8 changes: 2 additions & 6 deletions libkineto/src/CuptiActivityProfiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -973,12 +973,8 @@ void CuptiActivityProfiler::configure(

// Set useful metadata into the logger.
LOGGER_OBSERVER_SET_TRACE_DURATION_MS(config_->activitiesDuration().count());
if (!config_->requestTraceID().empty()) {
LOGGER_OBSERVER_SET_TRACE_ID(config_->requestTraceID());
}
if (!config_->requestGroupTraceID().empty()) {
LOGGER_OBSERVER_SET_GROUP_TRACE_ID(config_->requestGroupTraceID());
}
LOGGER_OBSERVER_SET_TRACE_ID(config_->requestTraceID());
LOGGER_OBSERVER_SET_GROUP_TRACE_ID(config_->requestGroupTraceID());

#if defined(HAS_CUPTI) || defined(HAS_ROCTRACER)
if (!cpuOnly_) {
Expand Down

0 comments on commit 41a8948

Please sign in to comment.