Browse Source

Change NetMonitor data structures

git-svn-id: http://subversion.jackaudio.org/jack/jack2/trunk/jackmp@2719 0c269be4-1314-0410-8aa9-9f06e86f4224
tags/1.90
moret 17 years ago
parent
commit
0f3c1ed9ad
5 changed files with 81 additions and 80 deletions
  1. +12
    -6
      common/JackNetDriver.cpp
  2. +6
    -4
      common/JackNetDriver.h
  3. +11
    -7
      common/JackNetManager.cpp
  4. +5
    -2
      common/JackNetManager.h
  5. +47
    -61
      common/JackNetTool.h

+ 12
- 6
common/JackNetDriver.cpp View File

@@ -33,6 +33,8 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
namespace Jack
{
#ifdef JACK_MONITOR
uint JackNetDriver::fMeasureCnt = 512;
uint JackNetDriver::fMeasurePoints = 5;
std::string JackNetDriver::fMonitorPlotOptions[] =
{
std::string ( "set xlabel \"audio cycles\"" ),
@@ -63,6 +65,7 @@ namespace Jack

//monitor
#ifdef JACK_MONITOR
fMeasure = new jack_time_t[JackNetDriver::fMeasurePoints];
std::string plot_file_name = std::string ( fParams.fName );
fMonitor.SetPlotFile ( plot_file_name, JackNetDriver::fMonitorPlotOptions, 2, JackNetDriver::fMonitorFieldNames, 5 );
#endif
@@ -81,6 +84,9 @@ namespace Jack
delete[] fMulticastIP;
delete[] fMidiCapturePortList;
delete[] fMidiPlaybackPortList;
#ifdef JACK_MONITOR
delete[] fMeasure;
#endif
}

//*************************************initialization***********************************************************************
@@ -102,7 +108,7 @@ namespace Jack
#ifdef JACK_MONITOR
int JackNetDriver::Close()
{
std::string filename = string ( fParams.fName );
std::string filename = string ( fParams.fName );
fMonitor.Save ( filename );
return JackDriver::Close();
}
@@ -519,7 +525,7 @@ namespace Jack

#ifdef JACK_MONITOR
fUsecCycleStart = GetMicroSeconds();
fMeasure.fTable[0] = GetMicroSeconds() - fUsecCycleStart;
fMeasure[0] = GetMicroSeconds() - fUsecCycleStart;
#endif

//audio, midi or sync if driver is late
@@ -562,7 +568,7 @@ namespace Jack


#ifdef JACK_MONITOR
fMeasure.fTable[1] = GetMicroSeconds() - fUsecCycleStart;
fMeasure[1] = GetMicroSeconds() - fUsecCycleStart;
#endif

return 0;
@@ -584,7 +590,7 @@ namespace Jack
fNetAudioPlaybackBuffer->SetBuffer(audio_port_index, GetOutputBuffer ( audio_port_index ));

#ifdef JACK_MONITOR
fMeasure.fTable[2] = GetMicroSeconds() - fUsecCycleStart;
fMeasure[2] = GetMicroSeconds() - fUsecCycleStart;
#endif

//sync
@@ -596,7 +602,7 @@ namespace Jack
tx_bytes = Send ( fParams.fMtu, 0 );

#ifdef JACK_MONITOR
fMeasure.fTable[3] = GetMicroSeconds() - fUsecCycleStart;
fMeasure[3] = GetMicroSeconds() - fUsecCycleStart;
#endif

//midi
@@ -632,7 +638,7 @@ namespace Jack
}

#ifdef JACK_MONITOR
fMeasure.fTable[4] = GetMicroSeconds() - fUsecCycleStart;
fMeasure[4] = GetMicroSeconds() - fUsecCycleStart;
fMonitor.Write ( fMeasure );
#endif



+ 6
- 4
common/JackNetDriver.h View File

@@ -62,11 +62,13 @@ namespace Jack

//monitoring
#ifdef JACK_MONITOR
static std::string fMonitorPlotOptions[];
static std::string fMonitorFieldNames[];
jack_time_t fUsecCycleStart;
NetMeasure<jack_time_t> fMeasure;
static uint fMeasureCnt;
static uint fMeasurePoints;
static std::string fMonitorPlotOptions[];
static std::string fMonitorFieldNames[];
jack_time_t* fMeasure;
NetMonitor<jack_time_t> fMonitor;
jack_time_t fUsecCycleStart;
#endif

bool Init();


+ 11
- 7
common/JackNetManager.cpp View File

@@ -28,6 +28,8 @@ namespace Jack
{
//JackNetMaster******************************************************************************************************
#ifdef JACK_MONITOR
uint JackNetMaster::fMeasureCnt = 512;
uint JackNetMaster::fMeasurePoints = 5;
std::string JackNetMaster::fMonitorPlotOptions[] =
{
std::string ( "set xlabel \"audio cycles\"" ),
@@ -116,6 +118,7 @@ namespace Jack

//monitor
#ifdef JACK_MONITOR
fMeasure = new jack_nframes_t[JackNetMaster::fMeasurePoints];
std::string plot_file_name = std::string ( fParams.fName );
fMonitor.SetPlotFile ( plot_file_name, fMonitorPlotOptions, 2, fMonitorFieldNames, 5 );
#endif
@@ -142,8 +145,9 @@ namespace Jack
delete[] fTxBuffer;
delete[] fRxBuffer;
#ifdef JACK_MONITOR
std::string filename = string ( fParams.fName );
std::string filename = string ( fParams.fName );
fMonitor.Save ( filename );
delete[] fMeasure;
#endif
}

@@ -387,7 +391,7 @@ fail:

#ifdef JACK_MONITOR
NetMeasure<jack_nframes_t> measure;
measure.fTable[0] = jack_frames_since_cycle_start( fJackClient );
fMeasure[0] = jack_frames_since_cycle_start( fJackClient );
#endif

//buffers
@@ -421,7 +425,7 @@ fail:
return tx_bytes;

#ifdef JACK_MONITOR
measure.fTable[1] = jack_frames_since_cycle_start( fJackClient );
fMeasure[1] = jack_frames_since_cycle_start( fJackClient );
#endif

//midi
@@ -461,7 +465,7 @@ fail:
}

#ifdef JACK_MONITOR
measure.fTable[2] = jack_frames_since_cycle_start( fJackClient );
fMeasure[2] = jack_frames_since_cycle_start( fJackClient );
#endif

//receive --------------------------------------------------------------------------------------------------------------------
@@ -475,7 +479,7 @@ fail:
while ( !rx_bytes && ( rx_head->fDataType != 's' ) );

#ifdef JACK_MONITOR
measure.fTable[3] = jack_frames_since_cycle_start( fJackClient );
fMeasure[3] = jack_frames_since_cycle_start( fJackClient );
#endif

if ( fParams.fReturnMidiChannels || fParams.fReturnAudioChannels )
@@ -517,8 +521,8 @@ fail:
}

#ifdef JACK_MONITOR
measure.fTable[4] = jack_frames_since_cycle_start( fJackClient );
fMonitor.Write ( measure );
fMeasure[4] = jack_frames_since_cycle_start( fJackClient );
fMonitor.Write ( fMeasure );
#endif
return 0;
}


+ 5
- 2
common/JackNetManager.h View File

@@ -80,8 +80,11 @@ namespace Jack

//monitoring
#ifdef JACK_MONITOR
static std::string fMonitorPlotOptions[];
static std::string fMonitorFieldNames[];
static uint fMeasureCnt;
static uint fMeasurePoints;
static std::string fMonitorPlotOptions[];
static std::string fMonitorFieldNames[];
jack_nframes_t fMeasure[];
NetMonitor<jack_nframes_t> fMonitor;
#endif



+ 47
- 61
common/JackNetTool.h View File

@@ -172,83 +172,68 @@ namespace Jack
void SetBuffer(int index, sample_t* buffer);
};

// net measure ********************************************************************************

template <class T> struct NetMeasure
{
uint fTableSize;;
T* fTable;

NetMeasure ( uint table_size = 5 )
{
fTableSize = table_size;
fTable = new T[fTableSize];
}
~NetMeasure()
{
delete[] fTable;
}
};

// net monitor ********************************************************************************

template <class T> class NetMonitor
{
private:
uint fMeasureCnt;
uint fMeasurePoints;
NetMeasure<T>* fMeasureTable;
uint fMeasureCnt;
uint fMeasurePoints;
T** fMeasureTable;
uint fTablePos;

void DisplayMeasure ( NetMeasure<T>& measure )
void DisplayMeasure ( T* measure )
{
string display;
for ( uint m_id = 0; m_id < measure.fTableSize; m_id++ )
{
char* value;
sprintf ( value, "%lu ", measure.fTable[m_id] );
display += string ( value );
}
cout << "NetMonitor:: '" << display << "'" << endl;
string display;
for ( uint m_id = 0; m_id < fMeasurePoints; m_id++ )
{
char* value;
sprintf ( value, "%llu ", measure[m_id] );
display += string ( value );
}
cout << "NetMonitor:: '" << display << "'" << endl;
}


public:
NetMonitor ( uint measure_cnt = 512, uint measure_points = 5 )
{
jack_log ( "JackNetMonitor::JackNetMonitor measure_cnt %u measure_points %u", measure_cnt, measure_points );
jack_log ( "JackNetMonitor::JackNetMonitor measure_cnt %u measure_points %u", measure_cnt, measure_points );

fMeasureCnt = measure_cnt;
fMeasurePoints = measure_points;
fMeasureTable = new NetMeasure<T>[fMeasureCnt];
fMeasureCnt = measure_cnt;
fMeasurePoints = measure_points;
fTablePos = 0;
//allocate measure table
fMeasureTable = new T*[fMeasureCnt];
for ( uint i = 0; i < fMeasureCnt; i++ )
InitTable();
fMeasureTable[i] = new T[fMeasurePoints];
//init measure table
for ( uint cnt = 0; cnt < fMeasureCnt; cnt++ )
for ( uint point = 0; point < fMeasurePoints; point++ )
fMeasureTable[cnt][point] = 0;
}

~NetMonitor()
{
jack_log ( "NetMonitor::~NetMonitor" );
delete fMeasureTable;
jack_log ( "NetMonitor::~NetMonitor" );
for ( uint cnt = 0; cnt < fMeasureCnt; cnt++ )
delete[] fMeasureTable[cnt];
delete[] fMeasureTable;
}

uint InitTable()
void InitTable()
{
uint measure_id;
for ( measure_id = 0; measure_id < fMeasureTable[fTablePos].fTableSize; measure_id++ )
fMeasureTable[fTablePos].fTable[measure_id] = 0;
if ( ++fTablePos == fMeasureCnt )
fTablePos = 0;
return fTablePos;
for ( uint cnt = 0; cnt < fMeasureCnt; cnt++ )
for ( uint point = 0; point < fMeasurePoints; point++ )
fMeasureTable[cnt][point] = 0;
}

uint Write ( NetMeasure<T>& measure )
uint Write ( T* measure )
{
for ( uint m_id = 0; m_id < measure.fTableSize; m_id++ )
fMeasureTable[fTablePos].fTable[m_id] = measure.fTable[m_id];
for ( uint point = 0; point < fMeasurePoints; point++ )
fMeasureTable[fTablePos][point] = measure[point];
if ( ++fTablePos == fMeasureCnt )
fTablePos = 0;
//DisplayMeasure ( fMeasureTable[fTablePos] );
return fTablePos;
}

@@ -256,16 +241,16 @@ namespace Jack
{
filename += "_netmonitor.log";

jack_log ( "JackNetMonitor::Save filename %s", filename.c_str() );
jack_log ( "JackNetMonitor::Save filename %s", filename.c_str() );

FILE* file = fopen ( filename.c_str(), "w" );

//printf each measure with tab separated values
for ( uint id = 0; id < fMeasureCnt; id++ )
//print each measure with tab separated values
for ( uint cnt = 0; cnt < fMeasureCnt; cnt++ )
{
for ( uint m_id = 0; m_id < fMeasureTable[id].fTableSize; m_id++ )
fprintf ( file, "%lu \t ", fMeasureTable[id].fTable[m_id] );
fprintf ( file, "\n" );
for ( uint pt = 0; pt < fMeasurePoints; pt++ )
fprintf ( file, "%llu \t ", fMeasureTable[cnt][pt] );
fprintf ( file, "\n" );
}

fclose(file);
@@ -274,7 +259,8 @@ namespace Jack

int SetPlotFile ( string& name, string* options_list = NULL, uint options_number = 0, string* field_names = NULL, uint field_number = 0 )
{
string title = name + "_netmonitor";
//names and file
string title = name + "_netmonitor";
string plot_filename = title + ".plt";
string data_filename = title + ".log";
FILE* file = fopen ( plot_filename.c_str(), "w" );
@@ -287,7 +273,7 @@ namespace Jack
//additional options
for ( uint i = 0; i < options_number; i++ )
{
jack_log ( "JackNetMonitor::SetPlotFile : Add plot option : '%s'", options_list[i].c_str() );
jack_log ( "JackNetMonitor::SetPlotFile - Add plot option : '%s'", options_list[i].c_str() );
fprintf ( file, "%s\n", options_list[i].c_str() );
}

@@ -295,13 +281,13 @@ namespace Jack
fprintf ( file, "plot " );
for ( uint row = 1; row <= field_number; row++ )
{
jack_log ( "JackNetMonitor::SetPlotFile - Add plot : file '%s' row '%d' title '%s' field '%s'",
data_filename.c_str(), row, name.c_str(), field_names[row-1].c_str() );
fprintf ( file, "\"%s\" using %u title \"%s : %s\" with lines", data_filename.c_str(), row, name.c_str(), field_names[row-1].c_str() );
fprintf ( file, ( row < field_number ) ? "," : "\n" );
jack_log ( "JackNetMonitor::SetPlotFile - Add plot : file '%s' row '%d' title '%s' field '%s'",
data_filename.c_str(), row, name.c_str(), field_names[row-1].c_str() );
fprintf ( file, "\"%s\" using %u title \"%s : %s\" with lines", data_filename.c_str(), row, name.c_str(), field_names[row-1].c_str() );
fprintf ( file, ( row < field_number ) ? "," : "\n" );
}

jack_log ( "JackNetMonitor::SetPlotFile - Saving GnuPlot '.plt' file to '%s'", plot_filename.c_str() );
jack_log ( "JackNetMonitor::SetPlotFile - Saving GnuPlot '.plt' file to '%s'", plot_filename.c_str() );

fclose ( file );
return 0;


Loading…
Cancel
Save