1515#include < chrono>
1616#include < fstream>
1717
18- #include " libkineto.h"
19- #include " ActivityProfilerProxy.h"
2018#include " DaemonConfigLoader.h"
2119
2220#include " Logger.h"
@@ -120,7 +118,7 @@ void ConfigLoader::setDaemonConfigLoaderFactory(
120118}
121119
122120ConfigLoader& ConfigLoader::instance () {
123- static ConfigLoader config_loader ( libkineto::api ()) ;
121+ static ConfigLoader config_loader;
124122 return config_loader;
125123}
126124
@@ -130,9 +128,8 @@ std::string ConfigLoader::readOnDemandConfigFromDaemon(
130128 if (!daemonConfigLoader_) {
131129 return " " ;
132130 }
133- bool events =
134- now > onDemandEventProfilerConfig_->eventProfilerOnDemandEndTime ();
135- bool activities = !libkinetoApi_.activityProfiler ().isActive ();
131+ bool events = canHandlerAcceptConfig (ConfigKind::EventProfiler);
132+ bool activities = canHandlerAcceptConfig (ConfigKind::ActivityProfiler);
136133 return daemonConfigLoader_->readOnDemandConfig (events, activities);
137134}
138135
@@ -144,10 +141,8 @@ int ConfigLoader::contextCountForGpu(uint32_t device) {
144141 return daemonConfigLoader_->gpuContextCount (device);
145142}
146143
147- ConfigLoader::ConfigLoader (LibkinetoApi& api)
148- : libkinetoApi_(api),
149- onDemandEventProfilerConfig_ (new Config()),
150- configUpdateIntervalSecs_(kConfigUpdateIntervalSecs ),
144+ ConfigLoader::ConfigLoader ()
145+ : configUpdateIntervalSecs_(kConfigUpdateIntervalSecs ),
151146 onDemandConfigUpdateIntervalSecs_ (kOnDemandConfigUpdateIntervalSecs ),
152147 stopFlag_(false ),
153148 onDemandSignal_(false ) {
@@ -211,51 +206,23 @@ void ConfigLoader::configureFromSignal(
211206 if (daemonConfigLoader_) {
212207 daemonConfigLoader_->setCommunicationFabric (config_.ipcFabricEnabled ());
213208 }
214- if (eventProfilerRequest (config)) {
215- if (now > onDemandEventProfilerConfig_->eventProfilerOnDemandEndTime ()) {
216- LOG (INFO) << " Starting on-demand event profiling from signal" ;
217- std::lock_guard<std::mutex> lock (configLock_);
218- onDemandEventProfilerConfig_ = config.clone ();
219- } else {
220- LOG (ERROR) << " On-demand event profiler is busy" ;
221- }
222- }
223- // Initiate a trace by default, even when not specified in the config.
224- // Set trace duration and iterations to 0 to suppress.
225- config.updateActivityProfilerRequestReceivedTime ();
226- try {
227- auto & profiler = dynamic_cast <ActivityProfilerProxy&>(
228- libkinetoApi_.activityProfiler ());
229- profiler.scheduleTrace (config);
230- } catch (const std::exception& e) {
231- LOG (ERROR) << " Failed to schedule profiler request (busy?)" ;
232- }
209+ notifyHandlers (config);
233210}
234211
235212void ConfigLoader::configureFromDaemon (
236213 time_point<system_clock> now,
237214 Config& config) {
238215 const std::string config_str = readOnDemandConfigFromDaemon (now);
239- LOG_IF (INFO, !config_str.empty ()) << " Received config from dyno:\n "
240- << config_str;
216+ if (config_str.empty ()) {
217+ return ;
218+ }
219+
220+ LOG (INFO) << " Received config from dyno:\n " << config_str;
241221 config.parse (config_str);
242222 if (daemonConfigLoader_) {
243223 daemonConfigLoader_->setCommunicationFabric (config_.ipcFabricEnabled ());
244224 }
245- if (eventProfilerRequest (config)) {
246- std::lock_guard<std::mutex> lock (configLock_);
247- onDemandEventProfilerConfig_ = config.clone ();
248- }
249- if (config_.activityProfilerEnabled () &&
250- config.activityProfilerRequestReceivedTime () > now) {
251- try {
252- auto & profiler = dynamic_cast <ActivityProfilerProxy&>(
253- libkinetoApi_.activityProfiler ());
254- profiler.scheduleTrace (config);
255- } catch (const std::exception& e) {
256- LOG (ERROR) << " Failed to schedule profiler request (busy?)" ;
257- }
258- }
225+ notifyHandlers (config);
259226}
260227
261228void ConfigLoader::updateConfigThread () {
@@ -313,10 +280,4 @@ bool ConfigLoader::hasNewConfig(const Config& oldConfig) {
313280 return config_.timestamp () > oldConfig.timestamp ();
314281}
315282
316- bool ConfigLoader::hasNewEventProfilerOnDemandConfig (const Config& oldConfig) {
317- std::lock_guard<std::mutex> lock (configLock_);
318- return onDemandEventProfilerConfig_->eventProfilerOnDemandStartTime () >
319- oldConfig.eventProfilerOnDemandStartTime ();
320- }
321-
322283} // namespace KINETO_NAMESPACE
0 commit comments