8.4 (revision 624046d2)
Score-P Substrate Plugin Example

Simple example of a Score-P substrate plugin

#include <assert.h>
#include <inttypes.h>
#include <stdio.h>
#include <string.h>
static const SCOREP_SubstratePluginCallbacks* callbacks;
static size_t plugin_id;
static void
print( const char* event,
struct SCOREP_Location* location,
uint64_t timestamp,
SCOREP_RegionHandle regionHandle,
uint64_t stackdepth )
{
uint64_t i;
const char* slocation = callbacks->SCOREP_Location_GetName( location );
const char* sregion = callbacks->SCOREP_RegionHandle_GetName( regionHandle );
printf( "%" PRIu64 ": %s >%" PRIu64 " %s %s\n", timestamp, slocation, stackdepth, event, sregion );
}
/* An enter event has been received from Score-P */
static void
enter_region(
struct SCOREP_Location* location,
uint64_t timestamp,
SCOREP_RegionHandle regionHandle,
uint64_t* metricValues )
{
uint64_t* stackdepth = callbacks->SCOREP_Location_GetData( location, plugin_id );
print( "Enter", location, timestamp, regionHandle, *stackdepth );
( *stackdepth )++;
}
/* An exit event has been received from Score-P */
static void
exit_region(
struct SCOREP_Location* location,
uint64_t timestamp,
SCOREP_RegionHandle regionHandle,
uint64_t* metricValues )
{
uint64_t* stackdepth = callbacks->SCOREP_Location_GetData( location, plugin_id );
( *stackdepth )--;
print( "Exit", location, timestamp, regionHandle, *stackdepth );
}
/* is only called when process is currently not parallel */
static void
disable(
struct SCOREP_Location* location,
uint64_t timestamp,
SCOREP_RegionHandle regionHandle,
uint64_t* metricValues )
{
const char* slocation = callbacks->SCOREP_Location_GetName( location );
const char* sregion = callbacks->SCOREP_RegionHandle_GetName( regionHandle );
printf( "--------Disabled recording (%s - %s)------------\n",
slocation,
sregion );
}
/* is only called when process is currently not parallel */
static void
enable(
struct SCOREP_Location* location,
uint64_t timestamp,
SCOREP_RegionHandle regionHandle,
uint64_t* metricValues )
{
const char* slocation = callbacks->SCOREP_Location_GetName( location );
const char* sregion = callbacks->SCOREP_RegionHandle_GetName( regionHandle );
printf( "--------Enabled recording (%s - %s)------------\n",
slocation,
sregion );
}
/* Register event functions */
static uint32_t
get_event_functions(
{
/* Only print region events when recording is enabled */
{
functions[ SCOREP_EVENT_ENTER_REGION ] = ( SCOREP_Substrates_Callback )enter_region;
/* function prototypes for other events can be found in scorep/SCOREP_SubstrateEvents.h */
/* enable and disable are guaranteed to be called for SCOREP_SUBSTRATES_RECORDING_ENABLED */
}
*returned = functions;
}
/* Receive callbacks from Score-P */
static void
set_callbacks( const SCOREP_SubstratePluginCallbacks* incoming_callbacks,
size_t size )
{
assert( sizeof( SCOREP_SubstratePluginCallbacks ) <= size );
callbacks = incoming_callbacks;
}
/* assign id */
static void
assign_id( size_t id )
{
plugin_id = id;
}
static void
create_location( const struct SCOREP_Location* location,
const struct SCOREP_Location* parentLocation )
{
/* we store the stackdepth per location and initialize it with 0 */
uint64_t* stackdepth = calloc( sizeof( uint64_t ), 1 );
callbacks->SCOREP_Location_SetData( location, plugin_id, ( void* )stackdepth );
}
/* Define plugins and some plugin functions */
{
memset( &info, 0, sizeof( SCOREP_SubstratePluginInfo ) );
info.set_callbacks = set_callbacks;
info.create_location = create_location;
info.assign_id = assign_id;
info.get_event_functions = get_event_functions;
return info;
}
See also
SCOREP_SubstratePlugins.h