1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-09-17 16:50:26 +02:00

Rewrite format of output in Benchmark.cpp...

... Note that %ld must replace %d in many formats to keep it working, because
wxWidgets does more type-checking inside TranslatableString::Translation(),
because we now capture arguments with type-smart modern C++ variadic templates,
rather than using the old C variadics.
This commit is contained in:
Paul Licameli 2019-12-26 21:03:17 -05:00
parent cf5c18b9b3
commit ced6221b57

View File

@ -62,7 +62,7 @@ private:
void OnClear( wxCommandEvent &event ); void OnClear( wxCommandEvent &event );
void OnClose( wxCommandEvent &event ); void OnClose( wxCommandEvent &event );
void Printf(const wxChar *format, ...); void Printf(const TranslatableString &str);
void HoldPrint(bool hold); void HoldPrint(bool hold);
void FlushPrint(); void FlushPrint();
@ -257,7 +257,7 @@ void BenchmarkDialog::OnSave( wxCommandEvent & WXUNUSED(event))
{ {
/* i18n-hint: Benchmark means a software speed test; /* i18n-hint: Benchmark means a software speed test;
leave untranslated file extension .txt */ leave untranslated file extension .txt */
wxString fName = _("benchmark.txt"); auto fName = XO("benchmark.txt").Translation();
fName = FileNames::SelectFile(FileNames::Operation::Export, fName = FileNames::SelectFile(FileNames::Operation::Export,
XO("Export Benchmark Data as:"), XO("Export Benchmark Data as:"),
@ -279,17 +279,12 @@ void BenchmarkDialog::OnClear(wxCommandEvent & WXUNUSED(event))
mText->Clear(); mText->Clear();
} }
void BenchmarkDialog::Printf(const wxChar *format, ...) void BenchmarkDialog::Printf(const TranslatableString &str)
{ {
va_list argptr; auto s = str.Translation();
va_start(argptr, format);
wxString s = wxString::FormatV(format, argptr);
mToPrint += s; mToPrint += s;
if (!mHoldPrint) if (!mHoldPrint)
FlushPrint(); FlushPrint();
va_end(argptr);
} }
void BenchmarkDialog::HoldPrint(bool hold) void BenchmarkDialog::HoldPrint(bool hold)
@ -385,8 +380,8 @@ void BenchmarkDialog::OnRun( wxCommandEvent & WXUNUSED(event))
// They are (and are supposed to be) a different size to // They are (and are supposed to be) a different size to
// the blocks that make the blockfiles. That way we get to // the blocks that make the blockfiles. That way we get to
// do some testing of when edit chunks cross blockfile boundaries. // do some testing of when edit chunks cross blockfile boundaries.
Printf(_("Using %d chunks of %d samples each, for a total of %.1f MB.\n"), Printf( XO("Using %ld chunks of %ld samples each, for a total of %.1f MB.\n")
nChunks, chunkSize, nChunks*chunkSize*sizeof(short)/1048576.0); .Format( nChunks, chunkSize, nChunks*chunkSize*sizeof(short)/1048576.0 ) );
int trials = numEdits; int trials = numEdits;
@ -394,7 +389,7 @@ void BenchmarkDialog::OnRun( wxCommandEvent & WXUNUSED(event))
Shorts small1{ nChunks }; Shorts small1{ nChunks };
Shorts block{ chunkSize }; Shorts block{ chunkSize };
Printf(_("Preparing...\n")); Printf( XO("Preparing...\n") );
wxTheApp->Yield(); wxTheApp->Yield();
FlushPrint(); FlushPrint();
@ -422,12 +417,15 @@ void BenchmarkDialog::OnRun( wxCommandEvent & WXUNUSED(event))
t->GetEndTime(); t->GetEndTime();
if (t->GetClipByIndex(0)->GetSequence()->GetNumSamples() != nChunks * chunkSize) { if (t->GetClipByIndex(0)->GetSequence()->GetNumSamples() != nChunks * chunkSize) {
Printf(_("Expected len %d, track len %lld.\n"), nChunks * chunkSize, Printf( XO("Expected len %ld, track len %lld.\n")
t->GetClipByIndex(0)->GetSequence()->GetNumSamples().as_long_long()); .Format(
nChunks * chunkSize,
t->GetClipByIndex(0)->GetSequence()->GetNumSamples()
.as_long_long() ) );
goto fail; goto fail;
} }
Printf(_("Performing %d edits...\n"), trials); Printf( XO("Performing %d edits...\n").Format( trials ) );
wxTheApp->Yield(); wxTheApp->Yield();
FlushPrint(); FlushPrint();
@ -441,18 +439,22 @@ void BenchmarkDialog::OnRun( wxCommandEvent & WXUNUSED(event))
// 1 <= xlen <= nChunks - x0 // 1 <= xlen <= nChunks - x0
const size_t xlen = 1 + (rand() % (nChunks - x0)); const size_t xlen = 1 + (rand() % (nChunks - x0));
if (mEditDetail) if (mEditDetail)
Printf(_("Cut: %d - %d \n"), x0 * chunkSize, (x0 + xlen) * chunkSize); Printf( XO("Cut: %ld - %ld \n")
.Format( x0 * chunkSize, (x0 + xlen) * chunkSize) );
Track::Holder tmp; Track::Holder tmp;
try { try {
tmp = t->Cut(double (x0 * chunkSize), double ((x0 + xlen) * chunkSize)); tmp = t->Cut(double (x0 * chunkSize), double ((x0 + xlen) * chunkSize));
} }
catch (const AudacityException&) { catch (const AudacityException&) {
Printf(_("Trial %d\n"), z); Printf( XO("Trial %d\n").Format( z ) );
Printf(_("Cut (%d, %d) failed.\n"), (x0 * chunkSize), Printf( XO("Cut (%ld, %ld) failed.\n")
(x0 + xlen) * chunkSize); .Format( (x0 * chunkSize), (x0 + xlen) * chunkSize) );
Printf(_("Expected len %d, track len %lld.\n"), nChunks * chunkSize, Printf( XO("Expected len %ld, track len %lld.\n")
t->GetClipByIndex(0)->GetSequence()->GetNumSamples().as_long_long()); .Format(
nChunks * chunkSize,
t->GetClipByIndex(0)->GetSequence()->GetNumSamples()
.as_long_long() ) );
goto fail; goto fail;
} }
@ -461,20 +463,23 @@ void BenchmarkDialog::OnRun( wxCommandEvent & WXUNUSED(event))
const size_t y0 = rand() % (nChunks - xlen + 1); const size_t y0 = rand() % (nChunks - xlen + 1);
if (mEditDetail) if (mEditDetail)
Printf(_("Paste: %d\n"), y0 * chunkSize); Printf( XO("Paste: %ld\n").Format( y0 * chunkSize ) );
try { try {
t->Paste((double)(y0 * chunkSize), tmp.get()); t->Paste((double)(y0 * chunkSize), tmp.get());
} }
catch (const AudacityException&) { catch (const AudacityException&) {
Printf(_("Trial %d\nFailed on Paste.\n"), z); Printf( XO("Trial %d\nFailed on Paste.\n").Format( z ) );
goto fail; goto fail;
} }
if (t->GetClipByIndex(0)->GetSequence()->GetNumSamples() != nChunks * chunkSize) { if (t->GetClipByIndex(0)->GetSequence()->GetNumSamples() != nChunks * chunkSize) {
Printf(_("Trial %d\n"), z); Printf( XO("Trial %d\n").Format( z ) );
Printf(_("Expected len %d, track len %lld.\n"), nChunks * chunkSize, Printf( XO("Expected len %ld, track len %lld.\n")
t->GetClipByIndex(0)->GetSequence()->GetNumSamples().as_long_long()); .Format(
nChunks * chunkSize,
t->GetClipByIndex(0)->GetSequence()->GetNumSamples()
.as_long_long() ) );
goto fail; goto fail;
} }
@ -492,19 +497,19 @@ void BenchmarkDialog::OnRun( wxCommandEvent & WXUNUSED(event))
seq->DebugPrintf(seq->GetBlockArray(), seq->GetNumSamples(), &tempStr); seq->DebugPrintf(seq->GetBlockArray(), seq->GetNumSamples(), &tempStr);
mToPrint += tempStr; mToPrint += tempStr;
} }
Printf(_("Time to perform %d edits: %ld ms\n"), trials, elapsed); Printf( XO("Time to perform %d edits: %ld ms\n").Format( trials, elapsed ) );
FlushPrint(); FlushPrint();
wxTheApp->Yield(); wxTheApp->Yield();
#if 0 #if 0
Printf(_("Checking file pointer leaks:\n")); Printf( XO("Checking file pointer leaks:\n") );
Printf(_("Track # blocks: %d\n"), t->GetBlockArray()->size()); Printf( XO("Track # blocks: %ld\n").Format( t->GetBlockArray()->size() ) );
Printf(_("Disk # blocks: \n")); Printf( XO("Disk # blocks: \n") );
system("ls .audacity_temp/* | wc --lines"); system("ls .audacity_temp/* | wc --lines");
#endif #endif
Printf(_("Doing correctness check...\n")); Printf( XO("Doing correctness check...\n") );
FlushPrint(); FlushPrint();
wxTheApp->Yield(); wxTheApp->Yield();
@ -517,19 +522,19 @@ void BenchmarkDialog::OnRun( wxCommandEvent & WXUNUSED(event))
if (block[b] != v) { if (block[b] != v) {
bad++; bad++;
if (bad < 10) if (bad < 10)
Printf(_("Bad: chunk %d sample %d\n"), i, b); Printf( XO("Bad: chunk %ld sample %ld\n").Format( i, b ) );
b = chunkSize; b = chunkSize;
} }
} }
if (bad == 0) if (bad == 0)
Printf(_("Passed correctness check!\n")); Printf( XO("Passed correctness check!\n") );
else else
Printf(_("Errors in %d/%d chunks\n"), bad, nChunks); Printf( XO("Errors in %d/%ld chunks\n").Format( bad, nChunks ) );
elapsed = timer.Time(); elapsed = timer.Time();
Printf(_("Time to check all data: %ld ms\n"), elapsed); Printf( XO("Time to check all data: %ld ms\n").Format( elapsed ) );
Printf(_("Reading data again...\n")); Printf( XO("Reading data again...\n") );
wxTheApp->Yield(); wxTheApp->Yield();
FlushPrint(); FlushPrint();
@ -546,20 +551,20 @@ void BenchmarkDialog::OnRun( wxCommandEvent & WXUNUSED(event))
elapsed = timer.Time(); elapsed = timer.Time();
Printf(_("Time to check all data (2): %ld ms\n"), elapsed); Printf( XO("Time to check all data (2): %ld ms\n").Format( elapsed ) );
Printf(_("At 44100 Hz, 16-bits per sample, the estimated number of\n simultaneous tracks that could be played at once: %.1f\n"), Printf( XO("At 44100 Hz, 16-bits per sample, the estimated number of\n simultaneous tracks that could be played at once: %.1f\n" )
(nChunks*chunkSize/44100.0)/(elapsed/1000.0)); .Format( (nChunks*chunkSize/44100.0)/(elapsed/1000.0) ) );
goto success; goto success;
fail: fail:
Printf(_("TEST FAILED!!!\n")); Printf( XO("TEST FAILED!!!\n") );
success: success:
dd.reset(); dd.reset();
Printf(_("Benchmark completed successfully.\n")); Printf( XO("Benchmark completed successfully.\n") );
HoldPrint(false); HoldPrint(false);
} }