performance/systemcalloverhead.c

///////////////////////////////////////////////////////////////////////////////
// Filename: systemcalloverhead.c
///////////////////////////////////////////////////////////////////////////////
// Purpose: measure the overhead of a system call
///////////////////////////////////////////////////////////////////////////////
// History:
// ========
//
// Date     Time     Name      Description   
// -------- -------- --------  ------------------------------------------------
// 96/03/15 18:28:24 muellerg: created
//
///////////////////////////////////////////////////////////////////////////////


// Feature test switches ///////////////////////////// Feature test switches //
    /* NONE */



// System headers /////////////////////////////////////////// System headers //

#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>


// Local headers ///////////////////////////////////////////// Local headers //

#include "../common.h"



// Macros /////////////////////////////////////////////////////////// Macros //
    /* NONE */



// File scope objects /////////////////////////////////// File scope objects //

const int NUMBER_REPEAT = 500000;           /* how often are signals send? */




// External variables, functions, and classes ///////////// External objects //
    /* NONE */



// Signal catching functions ///////////////////// Signal catching functions //
    /* NONE */



// Structures, unions, and class definitions /////////////////// Definitions //
    /* NONE */



// Functions and class implementation /// Functions and class implementation //
    /* NONE */



// Main /////////////////////////////////////////////////////////////// Main //

int
main(int argc, char *argv[])
{
    error.set_program_name(argv[0]);    

    cout << "This program measures the overhead of a system call." << endl;
    cout << endl;

    measurement mes(argv[0], "", 1);

    // start timer
    mes.start(-1, NUMBER_REPEAT);

    pid_t dummy;

    for(int i=0; i < NUMBER_REPEAT; i++)
    {
        // so very cheap system call (nearly no work done in kernel)

        dummy = getpid();
    }

    // end timer
    mes.end();


    // write ops/s on cout

    mes.writeout_logfile(false, true, true);

    return(EXIT_SUCCESS);
}