@@ -399,6 +399,73 @@ static void ompi_spc_dump(void)
399399    ompi_spc_comm -> c_coll -> coll_barrier (ompi_spc_comm , ompi_spc_comm -> c_coll -> coll_barrier_module );
400400}
401401
402+ 
403+ /* 
404+  * Helper function for checking diff with given SPC. 
405+  * 
406+  * Given a specific SPC name and prior value, we 
407+  * get the new value and return the difference between 
408+  * the prior and new values (diff = new - prev). 
409+  * If do not care about the diff you can pass NULL for spc_diff, 
410+  * and will simply get the new_value. 
411+  * 
412+  * Note: The value for timer events are converted to microseconds. 
413+  * Note: Any highwater events are reset after being read. 
414+  * 
415+  * On success, return MPI_SUCCESS, otherwise return -1. 
416+  */ 
417+ int  ompi_spc_value_diff (char  * spc_name ,
418+                         long long  prev_value ,
419+                         long long  * cur_value ,
420+                         long long  * diff )
421+ {
422+     int  i ;
423+     long long  value  =  -1 ;
424+     int  found  =  0 ;
425+ 
426+     if  (NULL  ==  ompi_spc_events ) {
427+         //fprintf(stderr, " #-- DBG: WARN: SPC system not setup/available\n"); 
428+         return  -1 ;
429+     }
430+ 
431+     /* Find the index of given SPC. */ 
432+     for (i  =  0 ; i  <  OMPI_SPC_NUM_COUNTERS ; i ++ ) {
433+ 
434+         /* If this is our requested counter */ 
435+         if ( 0  ==  strcmp (ompi_spc_events_desc [i ].counter_name , spc_name ) ) {
436+ 
437+             value  =  (long long )ompi_spc_events [i ].value ;
438+ 
439+             /* If this is a timer-based counter, convert from cycles to microseconds */ 
440+             if ( ompi_spc_events [i ].is_timer_event  ) {
441+                 value  =  ompi_spc_cycles_to_usecs_internal (value );
442+             }
443+ 
444+             /* If this is a high watermark counter, reset it after it has been read */ 
445+             if ( ompi_spc_events [i ].is_high_watermark ) {
446+                 ompi_spc_events [i ].value  =  0 ;
447+             }
448+ 
449+             found  =  1 ;
450+             break ;
451+         }
452+     }
453+ 
454+     if  (found  !=  1 ) {
455+         fprintf (stderr , "Error: Failed to find SPC counter '%s'\n" , spc_name );
456+         return  -1 ;
457+     }
458+ 
459+     * cur_value  =  value ;
460+ 
461+     if  (NULL  !=  diff ) {
462+         * diff  =  value  -  prev_value ;
463+     }
464+ 
465+     return  MPI_SUCCESS ;
466+ }
467+ 
468+ 
402469/* Frees any dynamically allocated OMPI SPC data structures */ 
403470void  ompi_spc_fini (void )
404471{
0 commit comments