2 Copyright (C) 2006-2008 Grame
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as published by
6 the Free Software Foundation; either version 2.1 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26 #include <sys/types.h>
32 #include <sys/syslimits.h>
36 #include "driver_interface.h"
37 #include "JackCompilerDeps.h"
38 #include "JackError.h"
50 \brief Utility functions.
53 struct SERVER_EXPORT JackTools
58 static void KillServer();
60 static char* UserDir();
61 static char* ServerDir ( const char* server_name
, char* server_dir
);
62 static const char* DefaultServerName();
63 static void CleanupFiles ( const char* server_name
);
64 static int GetTmpdir();
65 static void RewriteName ( const char* name
, char* new_name
);
69 \brief Generic monitoring class. Saves data to GnuPlot files ('.plt' and '.log' datafile)
71 This template class allows to manipulate monitoring records, and automatically generate the GnuPlot config and data files.
72 Operations are RT safe because it uses fixed size data buffers.
73 You can set the number of measure points, and the number of records.
76 - create a JackGnuPlotMonitor, you can use the data type you want.
77 - create a temporary array for your measure
78 - once you have filled this array with 'measure points' value, call write() to add it to the record
79 - once you've done with your measurment, just call save() to save your data file
81 You can also call SetPlotFile() to automatically generate '.plt' file from an options list.
85 template <class T
> class JackGnuPlotMonitor
89 uint32_t fMeasurePoints
;
97 JackGnuPlotMonitor ( uint32_t measure_cnt
= 512, uint32_t measure_points
= 5, std::string name
= std::string ( "default" ) )
99 jack_log ( "JackGnuPlotMonitor::JackGnuPlotMonitor %u measure points - %u measures", measure_points
, measure_cnt
);
101 fMeasureCnt
= measure_cnt
;
102 fMeasurePoints
= measure_points
;
105 fCurrentMeasure
= new T
[fMeasurePoints
];
106 fMeasureTable
= new T
*[fMeasureCnt
];
107 for ( uint32_t cnt
= 0; cnt
< fMeasureCnt
; cnt
++ )
109 fMeasureTable
[cnt
] = new T
[fMeasurePoints
];
110 fill_n ( fMeasureTable
[cnt
], fMeasurePoints
, 0 );
114 ~JackGnuPlotMonitor()
116 jack_log ( "JackGnuPlotMonitor::~JackGnuPlotMonitor" );
118 for ( uint32_t cnt
= 0; cnt
< fMeasureCnt
; cnt
++ )
119 delete[] fMeasureTable
[cnt
];
120 delete[] fMeasureTable
;
121 delete[] fCurrentMeasure
;
124 T
AddNew ( T measure_point
)
127 return fCurrentMeasure
[fMeasureId
++] = measure_point
;
132 return fMeasureId
= 0;
135 T
Add ( T measure_point
)
137 return fCurrentMeasure
[fMeasureId
++] = measure_point
;
140 uint32_t AddLast ( T measure_point
)
142 fCurrentMeasure
[fMeasureId
] = measure_point
;
149 for ( uint32_t point
= 0; point
< fMeasurePoints
; point
++ )
150 fMeasureTable
[fTablePos
][point
] = fCurrentMeasure
[point
];
151 if ( ++fTablePos
== fMeasureCnt
)
156 int Save ( std::string name
= std::string ( "" ) )
158 std::string filename
= ( name
.empty() ) ? fName
: name
;
161 jack_log ( "JackGnuPlotMonitor::Save filename %s", filename
.c_str() );
163 std::ofstream
file ( filename
.c_str() );
165 for ( uint32_t cnt
= 0; cnt
< fMeasureCnt
; cnt
++ )
167 for ( uint32_t point
= 0; point
< fMeasurePoints
; point
++ )
168 file
<< fMeasureTable
[cnt
][point
] << " \t";
176 int SetPlotFile ( std::string
* options_list
= NULL
, uint32_t options_number
= 0,
177 std::string
* field_names
= NULL
, uint32_t field_number
= 0,
178 std::string name
= std::string ( "" ) )
180 std::string title
= ( name
.empty() ) ? fName
: name
;
181 std::string plot_filename
= title
+ ".plt";
182 std::string data_filename
= title
+ ".log";
184 std::ofstream
file ( plot_filename
.c_str() );
186 file
<< "set multiplot" << std::endl
;
187 file
<< "set grid" << std::endl
;
188 file
<< "set title \"" << title
<< "\"" << std::endl
;
190 for ( uint32_t i
= 0; i
< options_number
; i
++ )
191 file
<< options_list
[i
] << std::endl
;
194 for ( uint32_t row
= 1; row
<= field_number
; row
++ )
196 file
<< "\"" << data_filename
<< "\" using " << row
<< " title \"" << field_names
[row
-1] << "\" with lines";
197 file
<< ( ( row
< field_number
) ? ", " : "\n" );
200 jack_log ( "JackGnuPlotMonitor::SetPlotFile - Save GnuPlot file to '%s'", plot_filename
.c_str() );
207 void BuildClientPath(char* path_to_so
, int path_len
, const char* so_name
);
208 void PrintLoadError(const char* so_name
);