/* $Id: //depot/tools/main/performance/perfstat_cluster/src/outputHandler.hpp#36 $ */ #ifndef OUTPUTHANDLER_H #define OUTPUTHANDLER_H #include "boost/filesystem.hpp" #include "boost/lexical_cast.hpp" #include #include "boost/filesystem/operations.hpp" #include "boost/filesystem/path.hpp" #include #include #include #include #include #include #ifdef WIN32 #include #include #include "zip.h" #include "unzip.h" #else #include #include #include "zlib.h" #endif using namespace std; namespace boostFileSystem = boost::filesystem; /** class to handle output file for a given node */ class outputHandler { ofstream nodeDataFile; ofstream nodeIndexFile; ofstream hostDataFile; ofstream hostIndexFile; ofstream switchDataFile; ofstream switchIndexFile; ofstream nodeTempFile; ofstream logDataFile; int currentLineNumber; string currentDataDir; void updateNodeIndexFile(string); void updateHostIndexFile(string); void updateSwitchIndexFile(string); void updateNumberOfLines(string); string getDateString(); string dataBuffer; boost::mutex node_mutex; boost::mutex log_mutex; boost::mutex node_move_mutex; #ifdef WIN32 wstring convertStringToWString(string s); #endif public: /** empty constructor */ outputHandler(); string processOutput(string data); string processStartOfOutput(string data); string processEndOfOutput(string data); string processIterOutput(string data); /** creates output handler for a given node */ void createNodeDataHandler(string filename, string nodeName, string clusterIP = "0.0.0.0"); void createHostDataHandler(string, string); void createSwitchDataHandler(string, string); /** writes Iteration data in the output file for this node */ void writeIterToNodeFile(int iterNum, string token, string dateStr); void writeIterToHostFile(int iterNum, string token, string dateStr); void writeIterToSwitchFile(int iterNum, string token, string dateStr); /** writes stats data in the output file for this node */ void writeSTATSToNodeFile(string token, string nodeName); void writeSTATSToHostFile(string , string ); void writeSTATSToSwitchFile(string , string ); /** writes data in the output file for this node */ void writeDataToNodeFile(string data, int dataSize=0); void writeDataToNodeFile(string note, string data, bool lockFlag=false); void writeDataToHostFile(string data, int dataSize=0); void writeDataToHostFile(string note, string data, bool lockFlag=false); void writeDataToSwitchFile(string data, int dataSize=0); void writeDataToSwitchFile(string note, string data, bool lockFlag=false); /** closes output file for this node */ void MoveFromTempToDataFile(string, bool lockFlag=false); ofstream* createTempFile(string); void closeNodeFile(); void closeHostFile(); void closeSwitchFile(); void MoveFromTempToHostFile(string, bool lockFlag=false); void closeTempFile(ofstream*); void writeDataToTempFile(ofstream*, string); void createLogDataHandler(string filename); void writeDataToLogFile(string type, string data); void writeDataToLogFile(string type, string node, string data); void writeDataToConsole(string type, string node, string data, bool showStatus=false); void closeLogFile(); void generateArchiveFile(string outputFilename); void generateUnArchiveFile(string outputFilename); void setOutputLevel(string); void saveSSHKeypair(string, string, vector); string readSSHKey(string); void createSSHKeyFiles(string, string); void createPerfstatPreset(vector); void writeDataToBuffer(string); string getDataBuffer(); void clearDataBuffer(); void writeBinaryDataToNodeFile(const char*, int); string getNodeDataDir(); void removeTempFile(string); string readFromFile(const string& fileName); bool fileExists(const string& fileName); ofstream* createLogsFile(string fileName, ios::openmode mode=ios::out); ifstream* ReadLogsFile(string strFile, ios::openmode mode=ios::in); }; #endif