common/writedata.c
///////////////////////////////////////////////////////////////////////////////
// Filename: writedata.c
///////////////////////////////////////////////////////////////////////////////
// Purpose: for performance measurements: write data read by
// readdata(). The time used to write all the data is displayed.
///////////////////////////////////////////////////////////////////////////////
// History:
// ========
//
// Date Time Name Description
// -------- -------- -------- ------------------------------------------------
// 96/02/27 18:57:56 muellerg: created
//
///////////////////////////////////////////////////////////////////////////////
// Feature test switches ///////////////////////////// Feature test switches //
/* NONE */
// System headers /////////////////////////////////////////// System headers //
#include <stdlib.h>
// Local headers ///////////////////////////////////////////// Local headers //
#include "../common.h"
#include "readwritedata.h"
// Macros /////////////////////////////////////////////////////////// Macros //
/* NONE */
// File scope objects /////////////////////////////////// File scope objects //
/* NONE */
// 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 //
/*
* writedata(): write data which is read by readdata() and writes out how
* long it took to write all the data
* the function needs a file descriptor to read from, so it is
* only usable for IPC facilities which allow reading and writing
* data to descriptors.
*
* in: name: base name for logfile(s)
* ext: extension (e.g. "read" or "write")
* fd: descriptor to write to
* pid: process to synchronize with (if 0, no synchronation is done,
* e.g. if processes run on different computers...)
* to use these facility the caller has to install a special
* signal handler with synchronization_init();
*
*
* return: true if everything is ok, else false
*
*/
bool
writedata(char *name, char *ext, int fd, pid_t pid)
{
char *buffer=new char[size_max];
if(!buffer) return false;
int i, size;
measurement mes(name, ext, measurement_max);
for(size=1; size <= size_max; size*=2 )
{
if(pid)
{
// wait for start signal from other process
synchronization_wait();
// and acknowledge
synchronization_signal_child(pid);
}
// start timer
mes.start(size, how_often);
for(i=0; i < how_often; i++)
{
writen(fd, buffer, size);
}
// store data about measurement
mes.end();
}
mes.writeout_logfile();
mes.writeout_plain_logfile();
delete[] buffer;
return true;
}
// Main /////////////////////////////////////////////////////////////// Main //
/* NONE */