XrdMonCout2FileApp.cc

Go to the documentation of this file.
00001 /*****************************************************************************/
00002 /*                                                                           */
00003 /*                           XrdMonCout2FileApp.cc                           */
00004 /*                                                                           */
00005 /* (c) 2005 by the Board of Trustees of the Leland Stanford, Jr., University */
00006 /*                            All Rights Reserved                            */
00007 /*       Produced by Jacek Becla for Stanford University under contract      */
00008 /*              DE-AC02-76SF00515 with the Department of Energy              */
00009 /*****************************************************************************/
00010 
00011 // $Id: XrdMonCout2FileApp.cc 24468 2008-06-22 16:47:03Z ganis $
00012 
00013 
00014 // Reads from standard input, buffers incoming data and flushes to file
00015 // every x sec or whenever buffer is full whichever comes first (x is set
00016 // via argument). It locks the lock file before doing any io.
00017 
00018 #include "XrdMon/XrdMonBufferedOutput.hh"
00019 #include "XProtocol/XPtypes.hh"
00020 #include "XrdSys/XrdSysHeaders.hh"
00021 #include <unistd.h> /* access */
00022 #include <assert.h>
00023 using namespace std;
00024 
00025 int flushFreq = 30; // in seconds
00026 
00027 extern "C"
00028 void* flush2disk(void* arg)
00029 {
00030     XrdMonBufferedOutput* bOut = (XrdMonBufferedOutput*) arg;
00031     assert ( 0 != bOut );
00032 
00033     while ( 1 ) {
00034         sleep(flushFreq);
00035         bOut->flush();
00036     }
00037     return (void*) 0;
00038 }
00039 
00040 int main(int argc, char* argv[])
00041 {
00042     if ( argc != 2 ) {
00043         cerr << "Expected arg: <outFileName>" << endl;
00044         return 1;
00045     }
00046 
00047     const char* fName = argv[1];
00048     const kXR_int32 bufSize = 128*1024; // Make it configurable?
00049 
00050     XrdMonBufferedOutput bOut(fName, (const char*) 0, bufSize);
00051 
00052     pthread_t flushThread;
00053     if ( 0 != pthread_create(&flushThread,
00054                              0,
00055                              flush2disk,
00056                              (void*)&bOut) ) {
00057         cerr << "Can't start flush2disk thread" << endl;
00058         return 2;
00059     }
00060 
00061     char line[1024];
00062     while ( 1 ) {
00063         cin.getline(line, 1024);
00064         strcat(line, "\n");
00065         bOut.add(line);
00066     }
00067 
00068     // never reached    
00069     bOut.flush();
00070     return 0;
00071 }
00072 
00073 

Generated on Tue Jul 5 14:46:36 2011 for ROOT_528-00b_version by  doxygen 1.5.1