git-svn-id: http://subversion.jackaudio.org/jack/jack2/trunk/jackmp@2719 0c269be4-1314-0410-8aa9-9f06e86f4224tags/1.90
@@ -33,6 +33,8 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |||||
namespace Jack | namespace Jack | ||||
{ | { | ||||
#ifdef JACK_MONITOR | #ifdef JACK_MONITOR | ||||
uint JackNetDriver::fMeasureCnt = 512; | |||||
uint JackNetDriver::fMeasurePoints = 5; | |||||
std::string JackNetDriver::fMonitorPlotOptions[] = | std::string JackNetDriver::fMonitorPlotOptions[] = | ||||
{ | { | ||||
std::string ( "set xlabel \"audio cycles\"" ), | std::string ( "set xlabel \"audio cycles\"" ), | ||||
@@ -63,6 +65,7 @@ namespace Jack | |||||
//monitor | //monitor | ||||
#ifdef JACK_MONITOR | #ifdef JACK_MONITOR | ||||
fMeasure = new jack_time_t[JackNetDriver::fMeasurePoints]; | |||||
std::string plot_file_name = std::string ( fParams.fName ); | std::string plot_file_name = std::string ( fParams.fName ); | ||||
fMonitor.SetPlotFile ( plot_file_name, JackNetDriver::fMonitorPlotOptions, 2, JackNetDriver::fMonitorFieldNames, 5 ); | fMonitor.SetPlotFile ( plot_file_name, JackNetDriver::fMonitorPlotOptions, 2, JackNetDriver::fMonitorFieldNames, 5 ); | ||||
#endif | #endif | ||||
@@ -81,6 +84,9 @@ namespace Jack | |||||
delete[] fMulticastIP; | delete[] fMulticastIP; | ||||
delete[] fMidiCapturePortList; | delete[] fMidiCapturePortList; | ||||
delete[] fMidiPlaybackPortList; | delete[] fMidiPlaybackPortList; | ||||
#ifdef JACK_MONITOR | |||||
delete[] fMeasure; | |||||
#endif | |||||
} | } | ||||
//*************************************initialization*********************************************************************** | //*************************************initialization*********************************************************************** | ||||
@@ -102,7 +108,7 @@ namespace Jack | |||||
#ifdef JACK_MONITOR | #ifdef JACK_MONITOR | ||||
int JackNetDriver::Close() | int JackNetDriver::Close() | ||||
{ | { | ||||
std::string filename = string ( fParams.fName ); | |||||
std::string filename = string ( fParams.fName ); | |||||
fMonitor.Save ( filename ); | fMonitor.Save ( filename ); | ||||
return JackDriver::Close(); | return JackDriver::Close(); | ||||
} | } | ||||
@@ -519,7 +525,7 @@ namespace Jack | |||||
#ifdef JACK_MONITOR | #ifdef JACK_MONITOR | ||||
fUsecCycleStart = GetMicroSeconds(); | fUsecCycleStart = GetMicroSeconds(); | ||||
fMeasure.fTable[0] = GetMicroSeconds() - fUsecCycleStart; | |||||
fMeasure[0] = GetMicroSeconds() - fUsecCycleStart; | |||||
#endif | #endif | ||||
//audio, midi or sync if driver is late | //audio, midi or sync if driver is late | ||||
@@ -562,7 +568,7 @@ namespace Jack | |||||
#ifdef JACK_MONITOR | #ifdef JACK_MONITOR | ||||
fMeasure.fTable[1] = GetMicroSeconds() - fUsecCycleStart; | |||||
fMeasure[1] = GetMicroSeconds() - fUsecCycleStart; | |||||
#endif | #endif | ||||
return 0; | return 0; | ||||
@@ -584,7 +590,7 @@ namespace Jack | |||||
fNetAudioPlaybackBuffer->SetBuffer(audio_port_index, GetOutputBuffer ( audio_port_index )); | fNetAudioPlaybackBuffer->SetBuffer(audio_port_index, GetOutputBuffer ( audio_port_index )); | ||||
#ifdef JACK_MONITOR | #ifdef JACK_MONITOR | ||||
fMeasure.fTable[2] = GetMicroSeconds() - fUsecCycleStart; | |||||
fMeasure[2] = GetMicroSeconds() - fUsecCycleStart; | |||||
#endif | #endif | ||||
//sync | //sync | ||||
@@ -596,7 +602,7 @@ namespace Jack | |||||
tx_bytes = Send ( fParams.fMtu, 0 ); | tx_bytes = Send ( fParams.fMtu, 0 ); | ||||
#ifdef JACK_MONITOR | #ifdef JACK_MONITOR | ||||
fMeasure.fTable[3] = GetMicroSeconds() - fUsecCycleStart; | |||||
fMeasure[3] = GetMicroSeconds() - fUsecCycleStart; | |||||
#endif | #endif | ||||
//midi | //midi | ||||
@@ -632,7 +638,7 @@ namespace Jack | |||||
} | } | ||||
#ifdef JACK_MONITOR | #ifdef JACK_MONITOR | ||||
fMeasure.fTable[4] = GetMicroSeconds() - fUsecCycleStart; | |||||
fMeasure[4] = GetMicroSeconds() - fUsecCycleStart; | |||||
fMonitor.Write ( fMeasure ); | fMonitor.Write ( fMeasure ); | ||||
#endif | #endif | ||||
@@ -62,11 +62,13 @@ namespace Jack | |||||
//monitoring | //monitoring | ||||
#ifdef JACK_MONITOR | #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; | NetMonitor<jack_time_t> fMonitor; | ||||
jack_time_t fUsecCycleStart; | |||||
#endif | #endif | ||||
bool Init(); | bool Init(); | ||||
@@ -28,6 +28,8 @@ namespace Jack | |||||
{ | { | ||||
//JackNetMaster****************************************************************************************************** | //JackNetMaster****************************************************************************************************** | ||||
#ifdef JACK_MONITOR | #ifdef JACK_MONITOR | ||||
uint JackNetMaster::fMeasureCnt = 512; | |||||
uint JackNetMaster::fMeasurePoints = 5; | |||||
std::string JackNetMaster::fMonitorPlotOptions[] = | std::string JackNetMaster::fMonitorPlotOptions[] = | ||||
{ | { | ||||
std::string ( "set xlabel \"audio cycles\"" ), | std::string ( "set xlabel \"audio cycles\"" ), | ||||
@@ -116,6 +118,7 @@ namespace Jack | |||||
//monitor | //monitor | ||||
#ifdef JACK_MONITOR | #ifdef JACK_MONITOR | ||||
fMeasure = new jack_nframes_t[JackNetMaster::fMeasurePoints]; | |||||
std::string plot_file_name = std::string ( fParams.fName ); | std::string plot_file_name = std::string ( fParams.fName ); | ||||
fMonitor.SetPlotFile ( plot_file_name, fMonitorPlotOptions, 2, fMonitorFieldNames, 5 ); | fMonitor.SetPlotFile ( plot_file_name, fMonitorPlotOptions, 2, fMonitorFieldNames, 5 ); | ||||
#endif | #endif | ||||
@@ -142,8 +145,9 @@ namespace Jack | |||||
delete[] fTxBuffer; | delete[] fTxBuffer; | ||||
delete[] fRxBuffer; | delete[] fRxBuffer; | ||||
#ifdef JACK_MONITOR | #ifdef JACK_MONITOR | ||||
std::string filename = string ( fParams.fName ); | |||||
std::string filename = string ( fParams.fName ); | |||||
fMonitor.Save ( filename ); | fMonitor.Save ( filename ); | ||||
delete[] fMeasure; | |||||
#endif | #endif | ||||
} | } | ||||
@@ -387,7 +391,7 @@ fail: | |||||
#ifdef JACK_MONITOR | #ifdef JACK_MONITOR | ||||
NetMeasure<jack_nframes_t> measure; | NetMeasure<jack_nframes_t> measure; | ||||
measure.fTable[0] = jack_frames_since_cycle_start( fJackClient ); | |||||
fMeasure[0] = jack_frames_since_cycle_start( fJackClient ); | |||||
#endif | #endif | ||||
//buffers | //buffers | ||||
@@ -421,7 +425,7 @@ fail: | |||||
return tx_bytes; | return tx_bytes; | ||||
#ifdef JACK_MONITOR | #ifdef JACK_MONITOR | ||||
measure.fTable[1] = jack_frames_since_cycle_start( fJackClient ); | |||||
fMeasure[1] = jack_frames_since_cycle_start( fJackClient ); | |||||
#endif | #endif | ||||
//midi | //midi | ||||
@@ -461,7 +465,7 @@ fail: | |||||
} | } | ||||
#ifdef JACK_MONITOR | #ifdef JACK_MONITOR | ||||
measure.fTable[2] = jack_frames_since_cycle_start( fJackClient ); | |||||
fMeasure[2] = jack_frames_since_cycle_start( fJackClient ); | |||||
#endif | #endif | ||||
//receive -------------------------------------------------------------------------------------------------------------------- | //receive -------------------------------------------------------------------------------------------------------------------- | ||||
@@ -475,7 +479,7 @@ fail: | |||||
while ( !rx_bytes && ( rx_head->fDataType != 's' ) ); | while ( !rx_bytes && ( rx_head->fDataType != 's' ) ); | ||||
#ifdef JACK_MONITOR | #ifdef JACK_MONITOR | ||||
measure.fTable[3] = jack_frames_since_cycle_start( fJackClient ); | |||||
fMeasure[3] = jack_frames_since_cycle_start( fJackClient ); | |||||
#endif | #endif | ||||
if ( fParams.fReturnMidiChannels || fParams.fReturnAudioChannels ) | if ( fParams.fReturnMidiChannels || fParams.fReturnAudioChannels ) | ||||
@@ -517,8 +521,8 @@ fail: | |||||
} | } | ||||
#ifdef JACK_MONITOR | #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 | #endif | ||||
return 0; | return 0; | ||||
} | } | ||||
@@ -80,8 +80,11 @@ namespace Jack | |||||
//monitoring | //monitoring | ||||
#ifdef JACK_MONITOR | #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; | NetMonitor<jack_nframes_t> fMonitor; | ||||
#endif | #endif | ||||
@@ -172,83 +172,68 @@ namespace Jack | |||||
void SetBuffer(int index, sample_t* buffer); | 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 ******************************************************************************** | // net monitor ******************************************************************************** | ||||
template <class T> class NetMonitor | template <class T> class NetMonitor | ||||
{ | { | ||||
private: | private: | ||||
uint fMeasureCnt; | |||||
uint fMeasurePoints; | |||||
NetMeasure<T>* fMeasureTable; | |||||
uint fMeasureCnt; | |||||
uint fMeasurePoints; | |||||
T** fMeasureTable; | |||||
uint fTablePos; | 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: | public: | ||||
NetMonitor ( uint measure_cnt = 512, uint measure_points = 5 ) | 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; | fTablePos = 0; | ||||
//allocate measure table | |||||
fMeasureTable = new T*[fMeasureCnt]; | |||||
for ( uint i = 0; i < fMeasureCnt; i++ ) | 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() | ~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 ) | if ( ++fTablePos == fMeasureCnt ) | ||||
fTablePos = 0; | fTablePos = 0; | ||||
//DisplayMeasure ( fMeasureTable[fTablePos] ); | |||||
return fTablePos; | return fTablePos; | ||||
} | } | ||||
@@ -256,16 +241,16 @@ namespace Jack | |||||
{ | { | ||||
filename += "_netmonitor.log"; | 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" ); | 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); | 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 ) | 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 plot_filename = title + ".plt"; | ||||
string data_filename = title + ".log"; | string data_filename = title + ".log"; | ||||
FILE* file = fopen ( plot_filename.c_str(), "w" ); | FILE* file = fopen ( plot_filename.c_str(), "w" ); | ||||
@@ -287,7 +273,7 @@ namespace Jack | |||||
//additional options | //additional options | ||||
for ( uint i = 0; i < options_number; i++ ) | 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() ); | fprintf ( file, "%s\n", options_list[i].c_str() ); | ||||
} | } | ||||
@@ -295,13 +281,13 @@ namespace Jack | |||||
fprintf ( file, "plot " ); | fprintf ( file, "plot " ); | ||||
for ( uint row = 1; row <= field_number; row++ ) | 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 ); | fclose ( file ); | ||||
return 0; | return 0; | ||||