00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef __JackTools__
00021 #define __JackTools__
00022
00023 #ifdef WIN32
00024 #include <windows.h>
00025 #else
00026 #include <sys/types.h>
00027 #include <unistd.h>
00028 #include <dirent.h>
00029 #endif
00030
00031 #ifdef __APPLE__
00032 #include <sys/syslimits.h>
00033 #endif
00034
00035 #include "jslist.h"
00036 #include "driver_interface.h"
00037 #include "JackCompilerDeps.h"
00038 #include "JackError.h"
00039
00040 #include <string>
00041 #include <algorithm>
00042 #include <vector>
00043 #include <iostream>
00044 #include <fstream>
00045
00046 namespace Jack
00047 {
00048
00053 struct SERVER_EXPORT JackTools
00054 {
00055 static int GetPID();
00056 static int GetUID();
00057
00058 static char* UserDir();
00059 static char* ServerDir ( const char* server_name, char* server_dir );
00060 static const char* DefaultServerName();
00061 static void CleanupFiles ( const char* server_name );
00062 static int GetTmpdir();
00063 static void RewriteName ( const char* name, char* new_name );
00064 };
00065
00083 template <class T> class JackGnuPlotMonitor
00084 {
00085 private:
00086 uint32_t fMeasureCnt;
00087 uint32_t fMeasurePoints;
00088 uint32_t fMeasureId;
00089 T* fCurrentMeasure;
00090 T** fMeasureTable;
00091 uint32_t fTablePos;
00092 std::string fName;
00093
00094 public:
00095 JackGnuPlotMonitor ( uint32_t measure_cnt = 512, uint32_t measure_points = 5, std::string name = std::string ( "default" ) )
00096 {
00097 jack_log ( "JackGnuPlotMonitor::JackGnuPlotMonitor %u measure points - %u measures", measure_points, measure_cnt );
00098
00099 fMeasureCnt = measure_cnt;
00100 fMeasurePoints = measure_points;
00101 fTablePos = 0;
00102 fName = name;
00103 fCurrentMeasure = new T[fMeasurePoints];
00104 fMeasureTable = new T*[fMeasureCnt];
00105 for ( uint32_t cnt = 0; cnt < fMeasureCnt; cnt++ )
00106 {
00107 fMeasureTable[cnt] = new T[fMeasurePoints];
00108 fill_n ( fMeasureTable[cnt], fMeasurePoints, 0 );
00109 }
00110 }
00111
00112 ~JackGnuPlotMonitor()
00113 {
00114 jack_log ( "JackGnuPlotMonitor::~JackGnuPlotMonitor" );
00115
00116 for ( uint32_t cnt = 0; cnt < fMeasureCnt; cnt++ )
00117 delete[] fMeasureTable[cnt];
00118 delete[] fMeasureTable;
00119 delete[] fCurrentMeasure;
00120 }
00121
00122 T AddNew ( T measure_point )
00123 {
00124 fMeasureId = 0;
00125 return fCurrentMeasure[fMeasureId++] = measure_point;
00126 }
00127
00128 uint32_t New()
00129 {
00130 return fMeasureId = 0;
00131 }
00132
00133 T Add ( T measure_point )
00134 {
00135 return fCurrentMeasure[fMeasureId++] = measure_point;
00136 }
00137
00138 uint32_t AddLast ( T measure_point )
00139 {
00140 fCurrentMeasure[fMeasureId] = measure_point;
00141 fMeasureId = 0;
00142 return Write();
00143 }
00144
00145 uint32_t Write()
00146 {
00147 for ( uint32_t point = 0; point < fMeasurePoints; point++ )
00148 fMeasureTable[fTablePos][point] = fCurrentMeasure[point];
00149 if ( ++fTablePos == fMeasureCnt )
00150 fTablePos = 0;
00151 return fTablePos;
00152 }
00153
00154 int Save ( std::string name = std::string ( "" ) )
00155 {
00156 std::string filename = ( name.empty() ) ? fName : name;
00157 filename += ".log";
00158
00159 jack_log ( "JackGnuPlotMonitor::Save filename %s", filename.c_str() );
00160
00161 std::ofstream file ( filename.c_str() );
00162
00163 for ( uint32_t cnt = 0; cnt < fMeasureCnt; cnt++ )
00164 {
00165 for ( uint32_t point = 0; point < fMeasurePoints; point++ )
00166 file << fMeasureTable[cnt][point] << " \t";
00167 file << std::endl;
00168 }
00169
00170 file.close();
00171 return 0;
00172 }
00173
00174 int SetPlotFile ( std::string* options_list = NULL, uint32_t options_number = 0,
00175 std::string* field_names = NULL, uint32_t field_number = 0,
00176 std::string name = std::string ( "" ) )
00177 {
00178 std::string title = ( name.empty() ) ? fName : name;
00179 std::string plot_filename = title + ".plt";
00180 std::string data_filename = title + ".log";
00181
00182 std::ofstream file ( plot_filename.c_str() );
00183
00184 file << "set multiplot" << std::endl;
00185 file << "set grid" << std::endl;
00186 file << "set title \"" << title << "\"" << std::endl;
00187
00188 for ( uint32_t i = 0; i < options_number; i++ )
00189 file << options_list[i] << std::endl;
00190
00191 file << "plot ";
00192 for ( uint32_t row = 1; row <= field_number; row++ )
00193 {
00194 file << "\"" << data_filename << "\" using " << row << " title \"" << field_names[row-1] << "\" with lines";
00195 file << ( ( row < field_number ) ? ", " : "\n" );
00196 }
00197
00198 jack_log ( "JackGnuPlotMonitor::SetPlotFile - Save GnuPlot file to '%s'", plot_filename.c_str() );
00199
00200 file.close();
00201 return 0;
00202 }
00203 };
00204
00205 void BuildClientPath(char* path_to_so, int path_len, const char* so_name);
00206 void PrintLoadError(const char* so_name);
00207
00208 }
00209
00210 #endif