An Example of an Uninstrumented Scalar C Code (Corresponding, instrumented C code)


/*
* ioexample2: 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 );
}
   

Preprocessor Instrumented Scalar C Code (Corresponding, Uninstrumented C Code)


/*
* ioexample2: Sample program that demonstrates I/O tracing
* with the user initializing the trace library directly and
* defining IOTRACE so that the preprocessor replaces standard
* I/O calls with corresponding trace library versions.
* Lines related to, or affected by, tracing have PABLO in
* their comments
*/
# define IOTRACE                               /*PABLO */
# 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 = 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 );

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

Compiling, Linking, and Executing

Suppose the Pablo software is installed in the directory <PabloDir>. The Pablo trace header file IOTrace.h, which must be included, can be found in <PabloDir>   include subdirectory.

To compile the code, use the following command:

cc -c ioexample2.c -I<PabloDir>/include

The files must be linked with the libraries libPabloTrace.a and libPabloTraceExt.a, which can be found in the lib subdirectory of <PabloDir>. To link the code, use the following command:

cc -o myEXE ioexample2.o -L<PabloDir>/lib -lPabloTrace -lPabloTraceExt

To execute the code, use the following command:

myEXE

This will produce a trace output file named Pablo.bin

Trace Output Files

Click to download the trace output file Pablo.bin produced by following the steps above. The file is in binary. To convert it to ASCII, use the command SDDFconverter. This command will prompt users for input. The following is the session used to convert Pablo.bin from a binary format to the ASCII file Pablo.ascii. User responses are in bold. Click to download the converted trace output file Pablo.ascii

% SDDFconverter

Please enter name of the input SDDF file: Pablo.bin

File is in SDDF Non-Native Binary format

Output in Ascii, Binary or Converted (reverse byte order) format [A, B, C]: A

Please entery name of the output SDDF file: Pablo.ascii

Do you want diagnostic messages printed [Y or N}: N

Processing Data: Sample Reports

Issue the command IOStats Pablo.bin to produce the report on the screen.

Issue the command IOStatsTable Pablo.bin to produce the report on the screen.

Issue the command LifetimeIOstats Pablo.bin to produce the report on the screen.

Issue the command FileRegionIOStats Pablo.bin to produce the report on the screen.

Issue the command TimeWindowIOStats Pablo.bin to produce the report on the screen.