| /*
* 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 */
}
|