3.1-rc3 (revision d9ca08bb)
otf2_writer_example.c

Simple writing example

/*
* This file is part of the Score-P software (http://www.score-p.org)
*
* Copyright (c) 2009-2013,
* RWTH Aachen University, Germany
*
* Copyright (c) 2009-2013,
* Gesellschaft fuer numerische Simulation mbH Braunschweig, Germany
*
* Copyright (c) 2009-2014, 2021,
* Technische Universitaet Dresden, Germany
*
* Copyright (c) 2009-2013,
* University of Oregon, Eugene, USA
*
* Copyright (c) 2009-2013,
* Forschungszentrum Juelich GmbH, Germany
*
* Copyright (c) 2009-2013,
* German Research School for Simulation Sciences GmbH, Juelich/Aachen, Germany
*
* Copyright (c) 2009-2013,
* Technische Universitaet Muenchen, Germany
*
* This software may be modified and distributed under the terms of
* a BSD-style license. See the COPYING file in the package base
* directory for details.
*
*/
#include <otf2/otf2.h>
#include <stdlib.h>
get_time( void )
{
static uint64_t sequence;
return sequence++;
}
pre_flush( void* userData,
OTF2_FileType fileType,
OTF2_LocationRef location,
void* callerData,
bool final )
{
return OTF2_FLUSH;
}
post_flush( void* userData,
OTF2_FileType fileType,
OTF2_LocationRef location )
{
return get_time();
}
static OTF2_FlushCallbacks flush_callbacks =
{
.otf2_pre_flush = pre_flush,
.otf2_post_flush = post_flush
};
int
main( int argc,
char** argv )
{
OTF2_Archive* archive = OTF2_Archive_Open( "ArchivePath",
"ArchiveName",
1024 * 1024 /* event chunk size */,
4 * 1024 * 1024 /* def chunk size */,
OTF2_Archive_SetFlushCallbacks( archive, &flush_callbacks, NULL );
OTF2_EvtWriter* evt_writer = OTF2_Archive_GetEvtWriter( archive, 0 );
OTF2_EvtWriter_Enter( evt_writer,
NULL,
get_time(),
0 /* region */ );
OTF2_EvtWriter_Leave( evt_writer,
NULL,
get_time(),
0 /* region */ );
OTF2_Archive_CloseEvtWriter( archive, evt_writer );
OTF2_DefWriter* def_writer = OTF2_Archive_GetDefWriter( archive, 0 );
OTF2_Archive_CloseDefWriter( archive, def_writer );
OTF2_GlobalDefWriter* global_def_writer = OTF2_Archive_GetGlobalDefWriter( archive );
1 /* 1 tick per second */,
0 /* epoch */,
2 /* length */,
OTF2_GlobalDefWriter_WriteString( global_def_writer, 0, "" );
OTF2_GlobalDefWriter_WriteString( global_def_writer, 1, "Initial Process" );
OTF2_GlobalDefWriter_WriteString( global_def_writer, 2, "Main Thread" );
OTF2_GlobalDefWriter_WriteString( global_def_writer, 3, "MyFunction" );
OTF2_GlobalDefWriter_WriteString( global_def_writer, 4, "Alternative function name (e.g. mangled one)" );
OTF2_GlobalDefWriter_WriteString( global_def_writer, 5, "Computes something" );
OTF2_GlobalDefWriter_WriteString( global_def_writer, 6, "MyHost" );
OTF2_GlobalDefWriter_WriteString( global_def_writer, 7, "node" );
0 /* id */,
3 /* region name */,
4 /* alternative name */,
5 /* description */,
0 /* source file */,
0 /* begin lno */,
0 /* end lno */ );
0 /* id */,
6 /* name */,
7 /* class */,
0 /* id */,
1 /* name */,
0 /* system tree */,
OTF2_UNDEFINED_LOCATION_GROUP /* creating process */ );
0 /* id */,
2 /* name */,
2 /* # events */,
0 /* location group */ );
OTF2_Archive_Close( archive );
return EXIT_SUCCESS;
}