An Example of a Manually Instrumented C Code (Corresponding, Uninstrumented C Code)

 

/*
* ioexample2: Sample program that demonstrates I/O tracing
* with the user initializing the trace library directly and
* replacing the I/O calls to be traced with
* corresponding trace library versions.
* Lines related to, or affected by, tracing have PABLO in
* their comments
*/
# include "IOTrace.h"                                              /* PABLO */

# include <stdio.h>
# include <stdlib.h>

main()
{
FILE    *fp;
char    buffer[1024];
size_t cnt;
int    bytesRead = 0;

initIOTrace();                                                     /* PABLO: Initialize the I/O tracing */
enableLifetimeSummaries();                                         /* PABLO: Lifetime Summaries     */
enableTimeWindowSummaries( .1 );                                   /* PABLO: Time summaries: .1 second */
enableFileRegionSummaries( 8192 );                                 /* PABLO: Region summaries: 8192 bytes */

fp = traceFOPEN( "/tmp/TestFile", "w+" );                          /* PABLO */
if ( fp !=NULL ) {
    traceFWRITE( "Hi!", sizeof(char), strlen("Hi!") , fp );       /* PABLO */
    traceREWIND( fp );                                             /* PABLO */
    traceFGETS( buffer, 1024, fp );                                /* PABLO */
    traceFCLOSE( fp );                                             /* PABLO */
}

fp = traceFOPEN( "/etc/termcap", "r" );                            /* PABLO */
if ( fp !=NULL ) {
    do {
    cnt = traceFREAD( buffer, sizeof(char), 1024, fp );            /* PABLO */
    bytesRead += cnt;
    } while (cnt > 0 );
    traceFWRITE( "Bye", 1, 2, fp );                                /* call fails (no write perm) */
    traceFCLOSE( fp );                                             /* PABLO */
}
printf( "Read %d bytes from /etc/termcap\n", bytesRead );

endIOTrace();                                                      /* PABLO: End the I/O tracing    */
endTracing();                                                      /* PABLO: End all Palbo tracing */   
}

 

An Uninstrumented Version of the Same Code

 

/*
* ioexample: Sample program that does some I/O, non-tracing verison. I/O activity is as follows:
* /tmp/TestFile: open; write; rewind; fgets; close;
* /etc/termcap: open; read in 1024 byte increments till end of file;
* try to write but fail because of permissions; close;
* Print number of bytes read from /etc/termcap
*/

# include <stdio.h>
# include <stdlib.h>

main()
{
FILE    *fp;
char    buffer[1024];
size_t cnt;
int    bytesRead = 0;

fp = fopen( "/tmp/TestFile", "w+" );
if  ( fp !=NULL ) {
    fwrite( "Hi!", sizeof(char), strlen("Hi!") , fp );
    rewind( fp );
    fgets( buffer, 1024, fp );
    fclose( fp );
}

fp = fopen( "/etc/termcap", "r" );
if  ( fp !=NULL ) {
    do {
    cnt = fread( buffer, sizeof(char), 1024, fp );
    bytesRead += cnt;
    } while (cnt > 0 );
    fwrite( "Bye", 1, 2, fp ); /* call fails (no write perm) */
    fclose( fp );
}
printf( "Read %d bytes from /etc/termcap\n", bytesRead );
}