From bed09539b72a690eb0d790cfdc85a100da812538 Mon Sep 17 00:00:00 2001 From: sletz Date: Fri, 20 Nov 2009 12:19:14 +0000 Subject: [PATCH] Use C++ isostream in JackEngineProfiling class. git-svn-id: http://subversion.jackaudio.org/jack/jack2/trunk/jackmp@3824 0c269be4-1314-0410-8aa9-9f06e86f4224 --- common/JackEngineProfiling.cpp | 285 ++++++++++++++++----------------- 1 file changed, 140 insertions(+), 145 deletions(-) diff --git a/common/JackEngineProfiling.cpp b/common/JackEngineProfiling.cpp index b0a1b441..cfe5d636 100644 --- a/common/JackEngineProfiling.cpp +++ b/common/JackEngineProfiling.cpp @@ -25,6 +25,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "JackGlobals.h" #include "JackTime.h" +#include +#include + namespace Jack { @@ -38,12 +41,10 @@ JackEngineProfiling::JackEngineProfiling():fAudioCycle(0),fMeasuredClient(0) JackEngineProfiling::~JackEngineProfiling() { - FILE* file = fopen("JackEngineProfiling.log", "w"); - char buffer[1024]; - + std::ofstream fStream("JackEngineProfiling.log", std::ios_base::ate); jack_info("Write server and clients timing data..."); - if (file == NULL) { + if (!fStream.is_open()) { jack_error("JackEngineProfiling::Save cannot open JackEngineProfiling.log file"); } else { @@ -58,7 +59,7 @@ JackEngineProfiling::~JackEngineProfiling() continue; // Skip non valid cycles // Print driver delta and end cycle - fprintf(file, "%ld \t %ld \t", d1, d2); + fStream << d1 << "\t" << d2 << "\t"; // For each measured client for (unsigned int j = 0; j < fMeasuredClient; j++) { @@ -71,220 +72,214 @@ JackEngineProfiling::~JackEngineProfiling() long d5 = long(fProfileTable[i].fClientTable[ref].fSignaledAt - fProfileTable[i - 1].fCurCycleBegin); long d6 = long(fProfileTable[i].fClientTable[ref].fAwakeAt - fProfileTable[i - 1].fCurCycleBegin); long d7 = long(fProfileTable[i].fClientTable[ref].fFinishedAt - fProfileTable[i - 1].fCurCycleBegin); - - // Print ref, signal, start, end, scheduling, duration, status - fprintf(file, "%d \t %ld \t %ld \t %ld \t %ld \t %ld \t %d \t", - ref, - ((d5 > 0) ? d5 : 0), - ((d6 > 0) ? d6 : 0), - ((d7 > 0) ? d7 : 0), - ((d6 > 0 && d5 > 0) ? (d6 - d5) : 0), - ((d7 > 0 && d6 > 0) ? (d7 - d6) : 0), - fProfileTable[i].fClientTable[ref].fStatus); - } else { // Print tabs - fprintf(file, "\t \t \t \t \t \t \t"); + + fStream << ref << "\t" ; + fStream << ((d5 > 0) ? d5 : 0) << "\t"; + fStream << ((d6 > 0) ? d6 : 0) << "\t" ; + fStream << ((d7 > 0) ? d7 : 0) << "\t"; + fStream << ((d6 > 0 && d5 > 0) ? (d6 - d5) : 0) << "\t" ; + fStream << ((d7 > 0 && d6 > 0) ? (d7 - d6) : 0) << "\t" ; + fStream << fProfileTable[i].fClientTable[ref].fStatus << "\t" ;; + + } else { // Print tabs + fStream << "\t \t \t \t \t \t \t"; } } // Terminate line - fprintf(file, "\n"); + fStream << std::endl; } } // Driver period - file = fopen("Timing1.plot", "w"); - - if (file == NULL) { + std::ofstream fStream1("Timing1.plot", std::ios_base::ate); + + if (!fStream1.is_open()) { jack_error("JackEngineProfiling::Save cannot open Timing1.log file"); } else { - fprintf(file, "set grid\n"); - fprintf(file, "set title \"Audio driver timing\"\n"); - fprintf(file, "set xlabel \"audio cycles\"\n"); - fprintf(file, "set ylabel \"usec\"\n"); - fprintf(file, "plot \"JackEngineProfiling.log\" using 1 title \"Audio period\" with lines \n"); - - fprintf(file, "set output 'Timing1.pdf\n"); - fprintf(file, "set terminal pdf\n"); - - fprintf(file, "set grid\n"); - fprintf(file, "set title \"Audio driver timing\"\n"); - fprintf(file, "set xlabel \"audio cycles\"\n"); - fprintf(file, "set ylabel \"usec\"\n"); - fprintf(file, "plot \"JackEngineProfiling.log\" using 1 title \"Audio period\" with lines \n"); - - fclose(file); + fStream1 << "set grid\n"; + fStream1 << "set title \"Audio driver timing\"\n"; + fStream1 << "set xlabel \"audio cycles\"\n"; + fStream1 << "set ylabel \"usec\"\n"; + fStream1 << "plot \"JackEngineProfiling.log\" using 1 title \"Audio period\" with lines \n"; + + fStream1 << "set output 'Timing1.pdf\n"; + fStream1 << "set terminal pdf\n"; + + fStream1 << "set grid\n"; + fStream1 << "set title \"Audio driver timing\"\n"; + fStream1 << "set xlabel \"audio cycles\"\n"; + fStream1 << "set ylabel \"usec\"\n"; + fStream1 << "plot \"JackEngineProfiling.log\" using 1 title \"Audio period\" with lines \n"; } // Driver end date - file = fopen("Timing2.plot", "w"); - - if (file == NULL) { + std::ofstream fStream2("Timing2.plot", std::ios_base::ate); + + if (!fStream2.is_open()) { jack_error("JackEngineProfiling::Save cannot open Timing2.log file"); } else { - fprintf(file, "set grid\n"); - fprintf(file, "set title \"Driver end date\"\n"); - fprintf(file, "set xlabel \"audio cycles\"\n"); - fprintf(file, "set ylabel \"usec\"\n"); - fprintf(file, "plot \"JackEngineProfiling.log\" using 2 title \"Driver end date\" with lines \n"); - - fprintf(file, "set output 'Timing2.pdf\n"); - fprintf(file, "set terminal pdf\n"); + fStream2 << "set grid\n"; + fStream2 << "set title \"Driver end date\"\n"; + fStream2 << "set xlabel \"audio cycles\"\n"; + fStream2 << "set ylabel \"usec\"\n"; + fStream2 << "plot \"JackEngineProfiling.log\" using 2 title \"Driver end date\" with lines \n"; - fprintf(file, "set grid\n"); - fprintf(file, "set title \"Driver end date\"\n"); - fprintf(file, "set xlabel \"audio cycles\"\n"); - fprintf(file, "set ylabel \"usec\"\n"); - fprintf(file, "plot \"JackEngineProfiling.log\" using 2 title \"Driver end date\" with lines \n"); + fStream2 << "set output 'Timing2.pdf\n"; + fStream2 << "set terminal pdf\n"; - fclose(file); + fStream2 << "set grid\n"; + fStream2 << "set title \"Driver end date\"\n"; + fStream2 << "set xlabel \"audio cycles\"\n"; + fStream2 << "set ylabel \"usec\"\n"; + fStream2 << "plot \"JackEngineProfiling.log\" using 2 title \"Driver end date\" with lines \n"; } // Clients end date if (fMeasuredClient > 0) { - file = fopen("Timing3.plot", "w"); - if (file == NULL) { + std::ofstream fStream3("Timing3.plot", std::ios_base::ate); + + if (!fStream3.is_open()) { jack_error("JackEngineProfiling::Save cannot open Timing3.log file"); } else { - fprintf(file, "set multiplot\n"); - fprintf(file, "set grid\n"); - fprintf(file, "set title \"Clients end date\"\n"); - fprintf(file, "set xlabel \"audio cycles\"\n"); - fprintf(file, "set ylabel \"usec\"\n"); - fprintf(file, "plot "); + fStream3 << "set multiplot\n"; + fStream3 << "set grid\n"; + fStream3 << "set title \"Clients end date\"\n"; + fStream3 << "set xlabel \"audio cycles\"\n"; + fStream3 << "set ylabel \"usec\"\n"; + fStream3 << "plot "; for (unsigned int i = 0; i < fMeasuredClient; i++) { if (i == 0) { if (i + 1 == fMeasuredClient) { // Last client - sprintf(buffer, "\"JackEngineProfiling.log\" using 1 title \"Audio period\" with lines,\"JackEngineProfiling.log\" using %d title \"%s\" with lines", - ((i + 1) * 7) - 1 , fIntervalTable[i].fName); - } else { - sprintf(buffer, "\"JackEngineProfiling.log\" using 1 title \"Audio period\" with lines,\"JackEngineProfiling.log\" using %d title \"%s\" with lines,", - ((i + 1) * 7) - 1 , fIntervalTable[i].fName); + fStream3 << "\"JackEngineProfiling.log\" using 1 title \"Audio period\" with lines,\"JackEngineProfiling.log\" using "; + fStream3 << ((i + 1) * 7) - 1; + fStream3 << " title \"" << fIntervalTable[i].fName << "\"with lines"; + } else { + fStream3 << "\"JackEngineProfiling.log\" using 1 title \"Audio period\" with lines,\"JackEngineProfiling.log\" using "; + fStream3 << ((i + 1) * 7) - 1; + fStream3 << " title \"" << fIntervalTable[i].fName << "\"with lines,"; } } else if (i + 1 == fMeasuredClient) { // Last client - sprintf(buffer, "\"JackEngineProfiling.log\" using %d title \"%s\" with lines", ((i + 1) * 7) - 1 , fIntervalTable[i].fName); + fStream3 << "\"JackEngineProfiling.log\" using " << ((i + 1) * 7) - 1 << " title \"" << fIntervalTable[i].fName << "\" with lines"; } else { - sprintf(buffer, "\"JackEngineProfiling.log\" using %d title \"%s\" with lines,", ((i + 1) * 7) - 1, fIntervalTable[i].fName); + fStream3 << "\"JackEngineProfiling.log\" using " << ((i + 1) * 7) - 1 << " title \"" << fIntervalTable[i].fName << "\" with lines,"; } - fprintf(file, buffer); } - fprintf(file, "\n unset multiplot\n"); - fprintf(file, "set output 'Timing3.pdf\n"); - fprintf(file, "set terminal pdf\n"); + fStream3 << "\n unset multiplot\n"; + fStream3 << "set output 'Timing3.pdf\n"; + fStream3 << "set terminal pdf\n"; - fprintf(file, "set multiplot\n"); - fprintf(file, "set grid\n"); - fprintf(file, "set title \"Clients end date\"\n"); - fprintf(file, "set xlabel \"audio cycles\"\n"); - fprintf(file, "set ylabel \"usec\"\n"); - fprintf(file, "plot "); + fStream3 << "set multiplot\n"; + fStream3 << "set grid\n"; + fStream3 << "set title \"Clients end date\"\n"; + fStream3 << "set xlabel \"audio cycles\"\n"; + fStream3 << "set ylabel \"usec\"\n"; + fStream3 << "plot "; for (unsigned int i = 0; i < fMeasuredClient; i++) { if (i == 0) { if ((i + 1) == fMeasuredClient) { // Last client - sprintf(buffer, "\"JackEngineProfiling.log\" using 1 title \"Audio period\" with lines,\"JackEngineProfiling.log\" using %d title \"%s\" with lines", - ((i + 1) * 7) - 1 , fIntervalTable[i].fName); + fStream3 << "\"JackEngineProfiling.log\" using 1 title \"Audio period\" with lines,\"JackEngineProfiling.log\" using "; + fStream3 << ((i + 1) * 7) - 1; + fStream3 << " title \"" << fIntervalTable[i].fName << "\"with lines"; } else { - sprintf(buffer, "\"JackEngineProfiling.log\" using 1 title \"Audio period\" with lines,\"JackEngineProfiling.log\" using %d title \"%s\" with lines,", - ((i + 1) * 7) - 1 , fIntervalTable[i].fName); + fStream3 << "\"JackEngineProfiling.log\" using 1 title \"Audio period\" with lines,\"JackEngineProfiling.log\" using "; + fStream3 << ((i + 1) * 7) - 1; + fStream3 << " title \"" << fIntervalTable[i].fName << "\"with lines,"; } } else if ((i + 1) == fMeasuredClient) { // Last client - sprintf(buffer, "\"JackEngineProfiling.log\" using %d title \"%s\" with lines", ((i + 1) * 7) - 1 , fIntervalTable[i].fName); + fStream3 << "\"JackEngineProfiling.log\" using " << ((i + 1) * 7) - 1 << " title \"" << fIntervalTable[i].fName << "\" with lines"; } else { - sprintf(buffer, "\"JackEngineProfiling.log\" using %d title \"%s\" with lines,", ((i + 1) * 7) - 1, fIntervalTable[i].fName); + fStream3 << "\"JackEngineProfiling.log\" using " << ((i + 1) * 7) - 1 << " title \"" << fIntervalTable[i].fName << "\" with lines,"; } - fprintf(file, buffer); } - - fclose(file); } } // Clients scheduling if (fMeasuredClient > 0) { - file = fopen("Timing4.plot", "w"); - - if (file == NULL) { + std::ofstream fStream4("Timing4.plot", std::ios_base::ate); + + if (!fStream4.is_open()) { jack_error("JackEngineProfiling::Save cannot open Timing4.log file"); } else { - fprintf(file, "set multiplot\n"); - fprintf(file, "set grid\n"); - fprintf(file, "set title \"Clients scheduling latency\"\n"); - fprintf(file, "set xlabel \"audio cycles\"\n"); - fprintf(file, "set ylabel \"usec\"\n"); - fprintf(file, "plot "); + fStream4 << "set multiplot\n"; + fStream4 << "set grid\n"; + fStream4 << "set title \"Clients scheduling latency\"\n"; + fStream4 << "set xlabel \"audio cycles\"\n"; + fStream4 << "set ylabel \"usec\"\n"; + fStream4 << "plot "; for (unsigned int i = 0; i < fMeasuredClient; i++) { - if ((i + 1) == fMeasuredClient) // Last client - sprintf(buffer, "\"JackEngineProfiling.log\" using %d title \"%s\" with lines", ((i + 1) * 7), fIntervalTable[i].fName); - else - sprintf(buffer, "\"JackEngineProfiling.log\" using %d title \"%s\" with lines,", ((i + 1) * 7), fIntervalTable[i].fName); - fprintf(file, buffer); + if ((i + 1) == fMeasuredClient) { // Last client + fStream4 << "\"JackEngineProfiling.log\" using " << ((i + 1) * 7) << " title \"" << fIntervalTable[i].fName << "\" with lines"; + } else { + fStream4 << "\"JackEngineProfiling.log\" using " << ((i + 1) * 7) << " title \"" << fIntervalTable[i].fName << "\" with lines,"; + } } - fprintf(file, "\n unset multiplot\n"); - fprintf(file, "set output 'Timing4.pdf\n"); - fprintf(file, "set terminal pdf\n"); + fStream4 << "\n unset multiplot\n"; + fStream4 << "set output 'Timing4.pdf\n"; + fStream4 << "set terminal pdf\n"; - fprintf(file, "set multiplot\n"); - fprintf(file, "set grid\n"); - fprintf(file, "set title \"Clients scheduling latency\"\n"); - fprintf(file, "set xlabel \"audio cycles\"\n"); - fprintf(file, "set ylabel \"usec\"\n"); - fprintf(file, "plot "); + fStream4 << "set multiplot\n"; + fStream4 << "set grid\n"; + fStream4 << "set title \"Clients scheduling latency\"\n"; + fStream4 << "set xlabel \"audio cycles\"\n"; + fStream4 << "set ylabel \"usec\"\n"; + fStream4 << "plot "; for (unsigned int i = 0; i < fMeasuredClient; i++) { - if ((i + 1) == fMeasuredClient) // Last client - sprintf(buffer, "\"JackEngineProfiling.log\" using %d title \"%s\" with lines", ((i + 1) * 7), fIntervalTable[i].fName); - else - sprintf(buffer, "\"JackEngineProfiling.log\" using %d title \"%s\" with lines,", ((i + 1) * 7), fIntervalTable[i].fName); - fprintf(file, buffer); + if ((i + 1) == fMeasuredClient) { // Last client + fStream4 << "\"JackEngineProfiling.log\" using " << ((i + 1) * 7) << " title \"" << fIntervalTable[i].fName << "\" with lines"; + } else { + fStream4 << "\"JackEngineProfiling.log\" using " << ((i + 1) * 7) << " title \"" << fIntervalTable[i].fName << "\" with lines,"; + } } - fclose(file); } } // Clients duration if (fMeasuredClient > 0) { - file = fopen("Timing5.plot", "w"); + std::ofstream fStream5("Timing5.plot", std::ios_base::ate); - if (file == NULL) { + if (!fStream5.is_open()) { jack_error("JackEngineProfiling::Save cannot open Timing5.log file"); } else { - fprintf(file, "set multiplot\n"); - fprintf(file, "set grid\n"); - fprintf(file, "set title \"Clients duration\"\n"); - fprintf(file, "set xlabel \"audio cycles\"\n"); - fprintf(file, "set ylabel \"usec\"\n"); - fprintf(file, "plot "); + fStream5 << "set multiplot\n"; + fStream5 << "set grid\n"; + fStream5 << "set title \"Clients duration\"\n"; + fStream5 << "set xlabel \"audio cycles\"\n"; + fStream5 << "set ylabel \"usec\"\n"; + fStream5 << "plot "; for (unsigned int i = 0; i < fMeasuredClient; i++) { - if ((i + 1) == fMeasuredClient) // Last client - sprintf(buffer, "\"JackEngineProfiling.log\" using %d title \"%s\" with lines", ((i + 1) * 7) + 1, fIntervalTable[i].fName); - else - sprintf(buffer, "\"JackEngineProfiling.log\" using %d title \"%s\" with lines,", ((i + 1) * 7) + 1, fIntervalTable[i].fName); - fprintf(file, buffer); + if ((i + 1) == fMeasuredClient) { // Last client + fStream5 << "\"JackEngineProfiling.log\" using " << ((i + 1) * 7) + 1 << " title \"" << fIntervalTable[i].fName << "\" with lines"; + } else { + fStream5 << "\"JackEngineProfiling.log\" using " << ((i + 1) * 7) + 1 << " title \"" << fIntervalTable[i].fName << "\" with lines,"; + } } - fprintf(file, "\n unset multiplot\n"); - fprintf(file, "set output 'Timing5.pdf\n"); - fprintf(file, "set terminal pdf\n"); + fStream5 << "\n unset multiplot\n"; + fStream5 << "set output 'Timing5.pdf\n"; + fStream5 << "set terminal pdf\n"; - fprintf(file, "set multiplot\n"); - fprintf(file, "set grid\n"); - fprintf(file, "set title \"Clients duration\"\n"); - fprintf(file, "set xlabel \"audio cycles\"\n"); - fprintf(file, "set ylabel \"usec\"\n"); - fprintf(file, "plot "); + fStream5 << "set multiplot\n"; + fStream5 << "set grid\n"; + fStream5 << "set title \"Clients duration\"\n"; + fStream5 << "set xlabel \"audio cycles\"\n"; + fStream5 << "set ylabel \"usec\"\n"; + fStream5 << "plot "; for (unsigned int i = 0; i < fMeasuredClient; i++) { - if ((i + 1) == fMeasuredClient) // Last client - sprintf(buffer, "\"JackEngineProfiling.log\" using %d title \"%s\" with lines", ((i + 1) * 7) + 1, fIntervalTable[i].fName); - else - sprintf(buffer, "\"JackEngineProfiling.log\" using %d title \"%s\" with lines,", ((i + 1) * 7) + 1, fIntervalTable[i].fName); - fprintf(file, buffer); + if ((i + 1) == fMeasuredClient) {// Last client + fStream5 << "\"JackEngineProfiling.log\" using " << ((i + 1) * 7) + 1 << " title \"" << fIntervalTable[i].fName << "\" with lines"; + } else { + fStream5 << "\"JackEngineProfiling.log\" using " << ((i + 1) * 7) + 1 << " title \"" << fIntervalTable[i].fName << "\" with lines,"; + } } - fclose(file); } } }