diff --git a/common/JackGnuPlotMonitor.cpp b/common/JackGnuPlotMonitor.cpp new file mode 100644 index 00000000..d7fd4b4c --- /dev/null +++ b/common/JackGnuPlotMonitor.cpp @@ -0,0 +1,147 @@ +/* + Copyright (C) 2006-2008 Grame + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation; either version 2.1 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +*/ + +#include "JackGnuPlotMonitor.h" +#include "JackError.h" + +using namespace std; + +namespace Jack { + +template +JackGnuPlotMonitor::JackGnuPlotMonitor(uint32_t measure_cnt, uint32_t measure_points, std::string name) +{ + jack_log ( "JackGnuPlotMonitor::JackGnuPlotMonitor %u measure points - %u measures", measure_points, measure_cnt ); + + fMeasureCnt = measure_cnt; + fMeasurePoints = measure_points; + fTablePos = 0; + fName = name; + fCurrentMeasure = new T[fMeasurePoints]; + fMeasureTable = new T*[fMeasureCnt]; + for ( uint32_t cnt = 0; cnt < fMeasureCnt; cnt++ ) + { + fMeasureTable[cnt] = new T[fMeasurePoints]; + fill_n ( fMeasureTable[cnt], fMeasurePoints, 0 ); + } +} + +template +JackGnuPlotMonitor::~JackGnuPlotMonitor() +{ + jack_log ( "JackGnuPlotMonitor::~JackGnuPlotMonitor" ); + + for ( uint32_t cnt = 0; cnt < fMeasureCnt; cnt++ ) + delete[] fMeasureTable[cnt]; + delete[] fMeasureTable; + delete[] fCurrentMeasure; +} + +template +T JackGnuPlotMonitor::AddNew(T measure_point) +{ + fMeasureId = 0; + return fCurrentMeasure[fMeasureId++] = measure_point; +} + +template +uint32_t JackGnuPlotMonitor::New() +{ + return fMeasureId = 0; +} + +template +T JackGnuPlotMonitor::Add(T measure_point) +{ + return fCurrentMeasure[fMeasureId++] = measure_point; +} + +template +uint32_t JackGnuPlotMonitor::AddLast(T measure_point) +{ + fCurrentMeasure[fMeasureId] = measure_point; + fMeasureId = 0; + return Write(); +} + +template +uint32_t JackGnuPlotMonitor::Write() +{ + for ( uint32_t point = 0; point < fMeasurePoints; point++ ) + fMeasureTable[fTablePos][point] = fCurrentMeasure[point]; + if ( ++fTablePos == fMeasureCnt ) + fTablePos = 0; + return fTablePos; +} + +template +int JackGnuPlotMonitor::Save(std::string name) +{ + std::string filename = ( name.empty() ) ? fName : name; + filename += ".log"; + + jack_log ( "JackGnuPlotMonitor::Save filename %s", filename.c_str() ); + + std::ofstream file ( filename.c_str() ); + + for ( uint32_t cnt = 0; cnt < fMeasureCnt; cnt++ ) + { + for ( uint32_t point = 0; point < fMeasurePoints; point++ ) + file << fMeasureTable[cnt][point] << " \t"; + file << std::endl; + } + + file.close(); + return 0; +} + +template +int JackGnuPlotMonitor::SetPlotFile(std::string* options_list, uint32_t options_number, + std::string* field_names, uint32_t field_number, + std::string name) +{ + std::string title = ( name.empty() ) ? fName : name; + std::string plot_filename = title + ".plt"; + std::string data_filename = title + ".log"; + + std::ofstream file ( plot_filename.c_str() ); + + file << "set multiplot" << std::endl; + file << "set grid" << std::endl; + file << "set title \"" << title << "\"" << std::endl; + + for ( uint32_t i = 0; i < options_number; i++ ) + file << options_list[i] << std::endl; + + file << "plot "; + for ( uint32_t row = 1; row <= field_number; row++ ) + { + file << "\"" << data_filename << "\" using " << row << " title \"" << field_names[row-1] << "\" with lines"; + file << ( ( row < field_number ) ? ", " : "\n" ); + } + + jack_log ( "JackGnuPlotMonitor::SetPlotFile - Save GnuPlot file to '%s'", plot_filename.c_str() ); + + file.close(); + return 0; +} + +} // end of namespace + + diff --git a/common/JackGnuPlotMonitor.h b/common/JackGnuPlotMonitor.h new file mode 100644 index 00000000..3d8e2f4b --- /dev/null +++ b/common/JackGnuPlotMonitor.h @@ -0,0 +1,89 @@ +/* + Copyright (C) 2006-2008 Grame + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation; either version 2.1 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +*/ + +#ifndef __JackGnuPlotMonitor__ +#define __JackGnuPlotMonitor__ + +#include +#include + +#include +#include +#include +#include +#include + +namespace Jack +{ + + /*! + \brief Generic monitoring class. Saves data to GnuPlot files ('.plt' and '.log' datafile) + + This template class allows to manipulate monitoring records, and automatically generate the GnuPlot config and data files. + Operations are RT safe because it uses fixed size data buffers. + You can set the number of measure points, and the number of records. + + To use it : + - create a JackGnuPlotMonitor, you can use the data type you want. + - create a temporary array for your measure + - once you have filled this array with 'measure points' value, call write() to add it to the record + - once you've done with your measurment, just call save() to save your data file + + You can also call SetPlotFile() to automatically generate '.plt' file from an options list. + + */ + + template class JackGnuPlotMonitor + { + private: + uint32_t fMeasureCnt; + uint32_t fMeasurePoints; + uint32_t fMeasureId; + T* fCurrentMeasure; + T** fMeasureTable; + uint32_t fTablePos; + std::string fName; + + public: + + JackGnuPlotMonitor(uint32_t measure_cnt = 512, uint32_t measure_points = 5, std::string name = std::string("default")); + + ~JackGnuPlotMonitor(); + + T AddNew(T measure_point); + + uint32_t New(); + + T Add(T measure_point); + + uint32_t AddLast(T measure_point); + + uint32_t Write(); + + int Save(std::string name = std::string("")); + + int SetPlotFile(std::string* options_list = NULL, uint32_t options_number = 0, + std::string* field_names = NULL, uint32_t field_number = 0, + std::string name = std::string("")); + }; + +} + +#endif + diff --git a/common/JackNetDriver.h b/common/JackNetDriver.h index 48a733bf..663e93c6 100644 --- a/common/JackNetDriver.h +++ b/common/JackNetDriver.h @@ -22,6 +22,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. #include "JackTimedDriver.h" #include "JackNetInterface.h" +#include "JackGnuPlotMonitor.h" //#define JACK_MONITOR diff --git a/common/JackNetManager.h b/common/JackNetManager.h index c88a09ba..af35130a 100644 --- a/common/JackNetManager.h +++ b/common/JackNetManager.h @@ -21,6 +21,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. #define __JACKNETMANAGER_H__ #include "JackNetInterface.h" +#include "JackGnuPlotMonitor.h" #include "thread.h" #include "jack.h" #include "jslist.h" diff --git a/common/JackTools.cpp b/common/JackTools.cpp index a00e1645..444e28c4 100644 --- a/common/JackTools.cpp +++ b/common/JackTools.cpp @@ -290,123 +290,5 @@ namespace Jack { } #endif -template -JackGnuPlotMonitor::JackGnuPlotMonitor(uint32_t measure_cnt, uint32_t measure_points, std::string name) -{ - jack_log ( "JackGnuPlotMonitor::JackGnuPlotMonitor %u measure points - %u measures", measure_points, measure_cnt ); - - fMeasureCnt = measure_cnt; - fMeasurePoints = measure_points; - fTablePos = 0; - fName = name; - fCurrentMeasure = new T[fMeasurePoints]; - fMeasureTable = new T*[fMeasureCnt]; - for ( uint32_t cnt = 0; cnt < fMeasureCnt; cnt++ ) - { - fMeasureTable[cnt] = new T[fMeasurePoints]; - fill_n ( fMeasureTable[cnt], fMeasurePoints, 0 ); - } -} - -template -JackGnuPlotMonitor::~JackGnuPlotMonitor() -{ - jack_log ( "JackGnuPlotMonitor::~JackGnuPlotMonitor" ); - - for ( uint32_t cnt = 0; cnt < fMeasureCnt; cnt++ ) - delete[] fMeasureTable[cnt]; - delete[] fMeasureTable; - delete[] fCurrentMeasure; -} - -template -T JackGnuPlotMonitor::AddNew(T measure_point) -{ - fMeasureId = 0; - return fCurrentMeasure[fMeasureId++] = measure_point; -} - -template -uint32_t JackGnuPlotMonitor::New() -{ - return fMeasureId = 0; -} - -template -T JackGnuPlotMonitor::Add(T measure_point) -{ - return fCurrentMeasure[fMeasureId++] = measure_point; -} - -template -uint32_t JackGnuPlotMonitor::AddLast(T measure_point) -{ - fCurrentMeasure[fMeasureId] = measure_point; - fMeasureId = 0; - return Write(); -} - -template -uint32_t JackGnuPlotMonitor::Write() -{ - for ( uint32_t point = 0; point < fMeasurePoints; point++ ) - fMeasureTable[fTablePos][point] = fCurrentMeasure[point]; - if ( ++fTablePos == fMeasureCnt ) - fTablePos = 0; - return fTablePos; -} - -template -int JackGnuPlotMonitor::Save(std::string name) -{ - std::string filename = ( name.empty() ) ? fName : name; - filename += ".log"; - - jack_log ( "JackGnuPlotMonitor::Save filename %s", filename.c_str() ); - - std::ofstream file ( filename.c_str() ); - - for ( uint32_t cnt = 0; cnt < fMeasureCnt; cnt++ ) - { - for ( uint32_t point = 0; point < fMeasurePoints; point++ ) - file << fMeasureTable[cnt][point] << " \t"; - file << std::endl; - } - - file.close(); - return 0; -} - -template -int JackGnuPlotMonitor::SetPlotFile(std::string* options_list, uint32_t options_number, - std::string* field_names, uint32_t field_number, - std::string name) -{ - std::string title = ( name.empty() ) ? fName : name; - std::string plot_filename = title + ".plt"; - std::string data_filename = title + ".log"; - - std::ofstream file ( plot_filename.c_str() ); - - file << "set multiplot" << std::endl; - file << "set grid" << std::endl; - file << "set title \"" << title << "\"" << std::endl; - - for ( uint32_t i = 0; i < options_number; i++ ) - file << options_list[i] << std::endl; - - file << "plot "; - for ( uint32_t row = 1; row <= field_number; row++ ) - { - file << "\"" << data_filename << "\" using " << row << " title \"" << field_names[row-1] << "\" with lines"; - file << ( ( row < field_number ) ? ", " : "\n" ); - } - - jack_log ( "JackGnuPlotMonitor::SetPlotFile - Save GnuPlot file to '%s'", plot_filename.c_str() ); - - file.close(); - return 0; -} - } // end of namespace diff --git a/common/JackTools.h b/common/JackTools.h index 5d9d6336..be7c8330 100644 --- a/common/JackTools.h +++ b/common/JackTools.h @@ -38,12 +38,6 @@ #include "jslist.h" #include "JackCompilerDeps.h" -#include -#include -#include -#include -#include - namespace Jack { @@ -82,57 +76,6 @@ namespace Jack } }; - /*! - \brief Generic monitoring class. Saves data to GnuPlot files ('.plt' and '.log' datafile) - - This template class allows to manipulate monitoring records, and automatically generate the GnuPlot config and data files. - Operations are RT safe because it uses fixed size data buffers. - You can set the number of measure points, and the number of records. - - To use it : - - create a JackGnuPlotMonitor, you can use the data type you want. - - create a temporary array for your measure - - once you have filled this array with 'measure points' value, call write() to add it to the record - - once you've done with your measurment, just call save() to save your data file - - You can also call SetPlotFile() to automatically generate '.plt' file from an options list. - - */ - - template class JackGnuPlotMonitor - { - private: - uint32_t fMeasureCnt; - uint32_t fMeasurePoints; - uint32_t fMeasureId; - T* fCurrentMeasure; - T** fMeasureTable; - uint32_t fTablePos; - std::string fName; - - public: - - JackGnuPlotMonitor(uint32_t measure_cnt = 512, uint32_t measure_points = 5, std::string name = std::string("default")); - - ~JackGnuPlotMonitor(); - - T AddNew(T measure_point); - - uint32_t New(); - - T Add(T measure_point); - - uint32_t AddLast(T measure_point); - - uint32_t Write(); - - int Save(std::string name = std::string("")); - - int SetPlotFile(std::string* options_list = NULL, uint32_t options_number = 0, - std::string* field_names = NULL, uint32_t field_number = 0, - std::string name = std::string("")); - }; - void BuildClientPath(char* path_to_so, int path_len, const char* so_name); void PrintLoadError(const char* so_name); diff --git a/common/wscript b/common/wscript index 7a79a8a8..b870412c 100644 --- a/common/wscript +++ b/common/wscript @@ -63,6 +63,7 @@ def build(bld): 'JackTransportEngine.cpp', 'timestamps.c', 'JackTools.cpp', + 'JackGnuPlotMonitor.cpp', 'JackMessageBuffer.cpp', 'JackEngineProfiling.cpp', ]