@@ -95,6 +95,63 @@ class PluginProfilerSession : public IActivityProfilerSession {
9595 }
9696 }
9797
98+ void pushCorrelationId (uint64_t id) override {
99+ KinetoPlugin_ProfilerPushCorrelationId_Params pushCorrelationIdParams{
100+ KINETO_PLUGIN_PROFILER_PUSH_CORRELATION_ID_PARAMS_UNPADDED_STRUCT_SIZE};
101+ pushCorrelationIdParams.pProfilerHandle = pProfilerHandle_;
102+ pushCorrelationIdParams.correlationId = id;
103+
104+ int errorCode =
105+ profiler_.profilerPushCorrelationId (&pushCorrelationIdParams);
106+ if (errorCode != 0 ) {
107+ LOG (ERROR) << " Plugin profiler " << name_
108+ << " failed at profilerPushCorrelationId() with error "
109+ << errorCode;
110+ }
111+ }
112+
113+ void popCorrelationId () override {
114+ KinetoPlugin_ProfilerPopCorrelationId_Params popCorrelationIdParams{
115+ KINETO_PLUGIN_PROFILER_POP_CORRELATION_ID_PARAMS_UNPADDED_STRUCT_SIZE};
116+ popCorrelationIdParams.pProfilerHandle = pProfilerHandle_;
117+
118+ int errorCode = profiler_.profilerPopCorrelationId (&popCorrelationIdParams);
119+ if (errorCode != 0 ) {
120+ LOG (ERROR) << " Plugin profiler " << name_
121+ << " failed at profilerPopCorrelationId() with error "
122+ << errorCode;
123+ }
124+ }
125+
126+ void pushUserCorrelationId (uint64_t id) override {
127+ KinetoPlugin_ProfilerPushUserCorrelationId_Params pushUserCorrelationIdParams{
128+ KINETO_PLUGIN_PROFILER_PUSH_USER_CORRELATION_ID_PARAMS_UNPADDED_STRUCT_SIZE};
129+ pushUserCorrelationIdParams.pProfilerHandle = pProfilerHandle_;
130+ pushUserCorrelationIdParams.userCorrelationId = id;
131+
132+ int errorCode =
133+ profiler_.profilerPushUserCorrelationId (&pushUserCorrelationIdParams);
134+ if (errorCode != 0 ) {
135+ LOG (ERROR) << " Plugin profiler " << name_
136+ << " failed at profilerPushUserCorrelationId() with error "
137+ << errorCode;
138+ }
139+ }
140+
141+ void popUserCorrelationId () override {
142+ KinetoPlugin_ProfilerPopUserCorrelationId_Params popUserCorrelationIdParams{
143+ KINETO_PLUGIN_PROFILER_POP_USER_CORRELATION_ID_PARAMS_UNPADDED_STRUCT_SIZE};
144+ popUserCorrelationIdParams.pProfilerHandle = pProfilerHandle_;
145+
146+ int errorCode =
147+ profiler_.profilerPopUserCorrelationId (&popUserCorrelationIdParams);
148+ if (errorCode != 0 ) {
149+ LOG (ERROR) << " Plugin profiler " << name_
150+ << " failed at profilerPopUserCorrelationId() with error "
151+ << errorCode;
152+ }
153+ }
154+
98155 TraceStatus status () { return status_; }
99156
100157 // returns errors with this trace
@@ -169,8 +226,13 @@ class PluginProfiler : public IActivityProfiler {
169226
170227public:
171228 PluginProfiler (const KinetoPlugin_ProfilerInterface &profiler)
172- : profiler_(profiler) {
173- validateProfiler ();
229+ : profiler_(profiler), isValid_(true ) {
230+ isValid_ = validateProfiler ();
231+ if (!isValid_) {
232+ LOG (ERROR) << " Plugin profiler " << name_
233+ << " is not valid; skipping registration" ;
234+ return ;
235+ }
174236
175237 char profilerName[32 ];
176238
@@ -216,6 +278,13 @@ class PluginProfiler : public IActivityProfiler {
216278 std::unique_ptr<IActivityProfilerSession>
217279 configure (const std::set<ActivityType> &activity_types,
218280 const Config & /* config*/ ) override {
281+ // Check if profiler is valid
282+ if (!isValid_) {
283+ LOG (ERROR) << " Plugin profiler " << name_
284+ << " is not valid, cannot configure" ;
285+ return nullptr ;
286+ }
287+
219288 // Check if the plugin supports ANY of the requested activity types
220289 bool hasSupported = false ;
221290 for (const auto &activity_type : activity_types) {
@@ -245,7 +314,9 @@ class PluginProfiler : public IActivityProfiler {
245314 }
246315
247316private:
248- void validateProfiler () {
317+ bool validateProfiler () {
318+ bool isValid = true ;
319+
249320 // Handle versioning
250321 // Currently expect the exact same version
251322 if (profiler_.unpaddedStructSize <
@@ -265,14 +336,128 @@ class PluginProfiler : public IActivityProfiler {
265336 profiler_.profilerStop = [](struct KinetoPlugin_ProfilerStop_Params *) {
266337 return -1 ;
267338 };
339+ profiler_.profilerPushCorrelationId =
340+ [](struct KinetoPlugin_ProfilerPushCorrelationId_Params *) {
341+ return -1 ;
342+ };
343+ profiler_.profilerPopCorrelationId =
344+ [](struct KinetoPlugin_ProfilerPopCorrelationId_Params *) {
345+ return -1 ;
346+ };
347+ profiler_.profilerPushUserCorrelationId =
348+ [](struct KinetoPlugin_ProfilerPushUserCorrelationId_Params *) {
349+ return -1 ;
350+ };
351+ profiler_.profilerPopUserCorrelationId =
352+ [](struct KinetoPlugin_ProfilerPopUserCorrelationId_Params *) {
353+ return -1 ;
354+ };
268355 profiler_.profilerProcessEvents =
269356 [](struct KinetoPlugin_ProfilerProcessEvents_Params *) { return -1 ; };
357+ return false ;
358+ }
359+
360+ // Check if individual function pointers are implemented
361+ // For critical functions, set them to error-returning stubs if nullptr and
362+ // mark as invalid
363+ if (profiler_.profilerCreate == nullptr ) {
364+ LOG (ERROR) << " Plugin profiler profilerCreate is not implemented" ;
365+ profiler_.profilerCreate =
366+ [](struct KinetoPlugin_ProfilerCreate_Params *) { return -1 ; };
367+ isValid = false ;
368+ }
369+
370+ if (profiler_.profilerDestroy == nullptr ) {
371+ LOG (ERROR) << " Plugin profiler profilerDestroy is not implemented" ;
372+ profiler_.profilerDestroy =
373+ [](struct KinetoPlugin_ProfilerDestroy_Params *) { return -1 ; };
374+ isValid = false ;
375+ }
376+
377+ if (profiler_.profilerQuery == nullptr ) {
378+ LOG (ERROR) << " Plugin profiler profilerQuery is not implemented" ;
379+ profiler_.profilerQuery = [](struct KinetoPlugin_ProfilerQuery_Params *) {
380+ return -1 ;
381+ };
382+ isValid = false ;
383+ }
384+
385+ if (profiler_.profilerStart == nullptr ) {
386+ LOG (ERROR) << " Plugin profiler profilerStart is not implemented" ;
387+ profiler_.profilerStart = [](struct KinetoPlugin_ProfilerStart_Params *) {
388+ return -1 ;
389+ };
390+ isValid = false ;
270391 }
392+
393+ if (profiler_.profilerStop == nullptr ) {
394+ LOG (ERROR) << " Plugin profiler profilerStop is not implemented" ;
395+ profiler_.profilerStop = [](struct KinetoPlugin_ProfilerStop_Params *) {
396+ return -1 ;
397+ };
398+ isValid = false ;
399+ }
400+
401+ if (profiler_.profilerProcessEvents == nullptr ) {
402+ LOG (ERROR) << " Plugin profiler profilerProcessEvents is not implemented" ;
403+ profiler_.profilerProcessEvents =
404+ [](struct KinetoPlugin_ProfilerProcessEvents_Params *) { return -1 ; };
405+ isValid = false ;
406+ }
407+
408+ // For correlation functions, provide default warning implementations if not
409+ // provided These don't affect validity
410+ if (profiler_.profilerPushCorrelationId == nullptr ) {
411+ LOG (INFO) << " Plugin profiler profilerPushCorrelationId is not "
412+ " implemented, using default stub" ;
413+ profiler_.profilerPushCorrelationId =
414+ [](struct KinetoPlugin_ProfilerPushCorrelationId_Params *) {
415+ LOG (WARNING) << " profilerPushCorrelationId called but not "
416+ " implemented by plugin" ;
417+ return 0 ;
418+ };
419+ }
420+
421+ if (profiler_.profilerPopCorrelationId == nullptr ) {
422+ LOG (INFO) << " Plugin profiler profilerPopCorrelationId is not "
423+ " implemented, using default stub" ;
424+ profiler_.profilerPopCorrelationId =
425+ [](struct KinetoPlugin_ProfilerPopCorrelationId_Params *) {
426+ LOG (WARNING) << " profilerPopCorrelationId called but not "
427+ " implemented by plugin" ;
428+ return 0 ;
429+ };
430+ }
431+
432+ if (profiler_.profilerPushUserCorrelationId == nullptr ) {
433+ LOG (INFO) << " Plugin profiler profilerPushUserCorrelationId is not "
434+ " implemented, using default stub" ;
435+ profiler_.profilerPushUserCorrelationId =
436+ [](struct KinetoPlugin_ProfilerPushUserCorrelationId_Params *) {
437+ LOG (WARNING) << " profilerPushUserCorrelationId called but not "
438+ " implemented by plugin" ;
439+ return 0 ;
440+ };
441+ }
442+
443+ if (profiler_.profilerPopUserCorrelationId == nullptr ) {
444+ LOG (INFO) << " Plugin profiler profilerPopUserCorrelationId is not "
445+ " implemented, using default stub" ;
446+ profiler_.profilerPopUserCorrelationId =
447+ [](struct KinetoPlugin_ProfilerPopUserCorrelationId_Params *) {
448+ LOG (WARNING) << " profilerPopUserCorrelationId called but not "
449+ " implemented by plugin" ;
450+ return 0 ;
451+ };
452+ }
453+
454+ return isValid;
271455 }
272456
273457 KinetoPlugin_ProfilerInterface profiler_;
274458 std::string name_;
275459 std::set<ActivityType> supportedActivities_;
460+ bool isValid_;
276461};
277462
278463} // namespace libkineto
0 commit comments