1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-06-16 16:10:06 +02:00

Add "tracing" of macro commands

At this time it's really just a debugging aid for us. It should
make it easier for us to better understand timing of various
commands.

Tracing is enabled by setting the "/EnableMacroTracing" preference
to 1 and disabled by setting it to 0.

Since the tracing is written to the log, this also adds a "SaveLog"
command that takes a filename. It can be used from within the macro
being traced to preserve the log in case the script intended to
exit Audacity.
This commit is contained in:
Leland Lucius 2020-08-11 00:14:56 -05:00
parent 9d749fef14
commit b6eaf5623e
5 changed files with 84 additions and 1 deletions

View File

@ -110,6 +110,19 @@ void AudacityLogger::DoLogText(const wxString & str)
}
}
bool AudacityLogger::SaveLog(const FilePath &fileName) const
{
wxFFile file(fileName, wxT("w"));
if (file.IsOpened()) {
file.Write(mBuffer);
file.Close();
return true;
}
return false;
}
void AudacityLogger::Show(bool show)
{
// Hide the frame if created, otherwise do nothing

View File

@ -33,6 +33,8 @@ class AudacityLogger final : public wxEvtHandler, public wxLog {
void Show(bool show = true);
bool SaveLog(const FilePath &fileName) const;
#if defined(EXPERIMENTAL_CRASH_REPORT)
wxString GetLog();
#endif

View File

@ -732,6 +732,9 @@ bool MacroCommands::ApplyMacro(
mAbort = false;
bool trace;
gPrefs->Read(wxT("/EnableMacroTracing"), &trace, false);
size_t i = 0;
for (; i < mCommandMacro.size(); i++) {
const auto &command = mCommandMacro[i];
@ -742,7 +745,23 @@ bool MacroCommands::ApplyMacro(
// in default of any better friendly name
Verbatim( command.GET() )
: iter->name.Msgid().Stripped();
if (!ApplyCommandInBatchMode(friendly, command, mParamsMacro[i]) || mAbort)
wxTimeSpan before;
if (trace) {
before = wxTimeSpan(0, 0, 0, wxGetUTCTimeMillis());
}
bool success = ApplyCommandInBatchMode(friendly, command, mParamsMacro[i]);
if (trace) {
auto after = wxTimeSpan(0, 0, 0, wxGetUTCTimeMillis());
wxLogMessage(wxT("Macro line #%ld \"%s\" took %s"),
i + 1,
command.GET(),
(after - before).Format(wxT("%H:%M:%S.%l")));
}
if (!success || mAbort)
break;
}

View File

@ -18,6 +18,7 @@
#include "OpenSaveCommands.h"
#include "LoadCommands.h"
#include "../AudacityLogger.h"
#include "../Project.h"
#include "../ProjectFileIO.h"
#include "../ProjectFileManager.h"
@ -132,3 +133,30 @@ bool SaveCopyCommand::Apply(const CommandContext &context)
auto &projectFileManager = ProjectFileManager::Get( context.project );
return projectFileManager.SaveCopy(mFileName);
}
const ComponentInterfaceSymbol SaveLogCommand::Symbol
{ XO("Save Log") };
namespace{ BuiltinCommandsModule::Registration< SaveLogCommand > reg4; }
bool SaveLogCommand::DefineParams( ShuttleParams & S ){
S.Define( mFileName, wxT("Filename"), "log.txt" );
return true;
}
void SaveLogCommand::PopulateOrExchange(ShuttleGui & S)
{
S.AddSpace(0, 5);
S.StartMultiColumn(2, wxALIGN_CENTER);
{
S.TieTextBox(XXO("File Name:"),mFileName);
}
S.EndMultiColumn();
}
bool SaveLogCommand::Apply(const CommandContext &context)
{
auto logger = AudacityLogger::Get();
return logger->SaveLog(mFileName);
}

View File

@ -19,6 +19,9 @@
\class SaveCopyCommand
\brief Command for saving a copy of currenty project
\class SaveLogCommand
\brief Command for saving the log contents
*//*******************************************************************/
#include "Command.h"
@ -81,3 +84,21 @@ public:
public:
wxString mFileName;
};
class SaveLogCommand : public AudacityCommand
{
public:
static const ComponentInterfaceSymbol Symbol;
// ComponentInterface overrides
ComponentInterfaceSymbol GetSymbol() override {return Symbol;};
TranslatableString GetDescription() override {return XO("Saves the log contents.");};
bool DefineParams( ShuttleParams & S ) override;
void PopulateOrExchange(ShuttleGui & S) override;
bool Apply(const CommandContext & context) override;
// AudacityCommand overrides
wxString ManualPage() override {return wxT("Extra_Menu:_Scriptables_II#save_log");};
public:
wxString mFileName;
};