Browse Source

Moved JackGnuPlotMonitor into a file of his own

pull/3/head
Léo Gillot-Lamure Léo Gillot-Lamure 14 years ago
parent
commit
24e67b2a30
7 changed files with 239 additions and 175 deletions
  1. +147
    -0
      common/JackGnuPlotMonitor.cpp
  2. +89
    -0
      common/JackGnuPlotMonitor.h
  3. +1
    -0
      common/JackNetDriver.h
  4. +1
    -0
      common/JackNetManager.h
  5. +0
    -118
      common/JackTools.cpp
  6. +0
    -57
      common/JackTools.h
  7. +1
    -0
      common/wscript

+ 147
- 0
common/JackGnuPlotMonitor.cpp View File

@@ -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 <class T>
JackGnuPlotMonitor<T>::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 <class T>
JackGnuPlotMonitor<T>::~JackGnuPlotMonitor()
{
jack_log ( "JackGnuPlotMonitor::~JackGnuPlotMonitor" );

for ( uint32_t cnt = 0; cnt < fMeasureCnt; cnt++ )
delete[] fMeasureTable[cnt];
delete[] fMeasureTable;
delete[] fCurrentMeasure;
}

template <class T>
T JackGnuPlotMonitor<T>::AddNew(T measure_point)
{
fMeasureId = 0;
return fCurrentMeasure[fMeasureId++] = measure_point;
}

template <class T>
uint32_t JackGnuPlotMonitor<T>::New()
{
return fMeasureId = 0;
}

template <class T>
T JackGnuPlotMonitor<T>::Add(T measure_point)
{
return fCurrentMeasure[fMeasureId++] = measure_point;
}

template <class T>
uint32_t JackGnuPlotMonitor<T>::AddLast(T measure_point)
{
fCurrentMeasure[fMeasureId] = measure_point;
fMeasureId = 0;
return Write();
}

template <class T>
uint32_t JackGnuPlotMonitor<T>::Write()
{
for ( uint32_t point = 0; point < fMeasurePoints; point++ )
fMeasureTable[fTablePos][point] = fCurrentMeasure[point];
if ( ++fTablePos == fMeasureCnt )
fTablePos = 0;
return fTablePos;
}

template <class T>
int JackGnuPlotMonitor<T>::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 <class T>
int JackGnuPlotMonitor<T>::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



+ 89
- 0
common/JackGnuPlotMonitor.h View File

@@ -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 <stdlib.h>
#include <jack/systemdeps.h>

#include <string>
#include <algorithm>
#include <vector>
#include <iostream>
#include <fstream>

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 T> 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


+ 1
- 0
common/JackNetDriver.h View File

@@ -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



+ 1
- 0
common/JackNetManager.h View File

@@ -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"


+ 0
- 118
common/JackTools.cpp View File

@@ -290,123 +290,5 @@ namespace Jack {
}
#endif

template <class T>
JackGnuPlotMonitor<T>::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 <class T>
JackGnuPlotMonitor<T>::~JackGnuPlotMonitor()
{
jack_log ( "JackGnuPlotMonitor::~JackGnuPlotMonitor" );

for ( uint32_t cnt = 0; cnt < fMeasureCnt; cnt++ )
delete[] fMeasureTable[cnt];
delete[] fMeasureTable;
delete[] fCurrentMeasure;
}

template <class T>
T JackGnuPlotMonitor<T>::AddNew(T measure_point)
{
fMeasureId = 0;
return fCurrentMeasure[fMeasureId++] = measure_point;
}

template <class T>
uint32_t JackGnuPlotMonitor<T>::New()
{
return fMeasureId = 0;
}

template <class T>
T JackGnuPlotMonitor<T>::Add(T measure_point)
{
return fCurrentMeasure[fMeasureId++] = measure_point;
}

template <class T>
uint32_t JackGnuPlotMonitor<T>::AddLast(T measure_point)
{
fCurrentMeasure[fMeasureId] = measure_point;
fMeasureId = 0;
return Write();
}

template <class T>
uint32_t JackGnuPlotMonitor<T>::Write()
{
for ( uint32_t point = 0; point < fMeasurePoints; point++ )
fMeasureTable[fTablePos][point] = fCurrentMeasure[point];
if ( ++fTablePos == fMeasureCnt )
fTablePos = 0;
return fTablePos;
}

template <class T>
int JackGnuPlotMonitor<T>::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 <class T>
int JackGnuPlotMonitor<T>::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


+ 0
- 57
common/JackTools.h View File

@@ -38,12 +38,6 @@
#include "jslist.h"
#include "JackCompilerDeps.h"

#include <string>
#include <algorithm>
#include <vector>
#include <iostream>
#include <fstream>

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 T> 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);



+ 1
- 0
common/wscript View File

@@ -63,6 +63,7 @@ def build(bld):
'JackTransportEngine.cpp',
'timestamps.c',
'JackTools.cpp',
'JackGnuPlotMonitor.cpp',
'JackMessageBuffer.cpp',
'JackEngineProfiling.cpp',
]


Loading…
Cancel
Save