Improve usability of start/stop.
This commit is contained in:
parent
f9defa7b37
commit
b26552d74c
@ -31,7 +31,8 @@
|
|||||||
ProfileToolManager g_ProfileToolManager;
|
ProfileToolManager g_ProfileToolManager;
|
||||||
|
|
||||||
ProfileToolManager::ProfileToolManager()
|
ProfileToolManager::ProfileToolManager()
|
||||||
: active_(nullptr)
|
: active_(nullptr),
|
||||||
|
default_(nullptr)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,6 +71,28 @@ render_help(const char *fmt, ...)
|
|||||||
rootmenu->ConsolePrint("%s", buffer);
|
rootmenu->ConsolePrint("%s", buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ProfileToolManager::StartFromConsole(IProfilingTool *tool)
|
||||||
|
{
|
||||||
|
if (active_) {
|
||||||
|
rootmenu->ConsolePrint("A profile is already active using %s.", active_->Name());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
active_ = tool;
|
||||||
|
if (!active_->Start()) {
|
||||||
|
rootmenu->ConsolePrint("Failed to attach to or start %s.", active_->Name());
|
||||||
|
active_ = nullptr;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
g_pSourcePawn2->SetProfilingTool(active_);
|
||||||
|
g_pSourcePawn2->EnableProfiling();
|
||||||
|
rootmenu->ConsolePrint("Started profiling with %s.", active_->Name());
|
||||||
|
|
||||||
|
default_ = active_;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ProfileToolManager::OnRootConsoleCommand2(const char *cmdname, const ICommandArgs *args)
|
ProfileToolManager::OnRootConsoleCommand2(const char *cmdname, const ICommandArgs *args)
|
||||||
{
|
{
|
||||||
@ -96,10 +119,26 @@ ProfileToolManager::OnRootConsoleCommand2(const char *cmdname, const ICommandArg
|
|||||||
g_pSourcePawn2->DisableProfiling();
|
g_pSourcePawn2->DisableProfiling();
|
||||||
g_pSourcePawn2->SetProfilingTool(nullptr);
|
g_pSourcePawn2->SetProfilingTool(nullptr);
|
||||||
active_->Stop(render_help);
|
active_->Stop(render_help);
|
||||||
active_->RenderHelp(render_help);
|
active_ = nullptr;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (args->ArgC() < 4) {
|
||||||
|
if (strcmp(cmdname, "start") == 0) {
|
||||||
|
if (!default_) {
|
||||||
|
default_ = FindToolByName("vprof");
|
||||||
|
if (!default_ && tools_.length() > 0)
|
||||||
|
default_ = tools_[0];
|
||||||
|
if (!default_) {
|
||||||
|
rootmenu->ConsolePrint("Could not find any profiler to use.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
StartFromConsole(default_);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (args->ArgC() < 4) {
|
if (args->ArgC() < 4) {
|
||||||
rootmenu->ConsolePrint("You must specify a profiling tool name.");
|
rootmenu->ConsolePrint("You must specify a profiling tool name.");
|
||||||
return;
|
return;
|
||||||
@ -107,22 +146,12 @@ ProfileToolManager::OnRootConsoleCommand2(const char *cmdname, const ICommandArg
|
|||||||
|
|
||||||
const char *toolname = args->Arg(3);
|
const char *toolname = args->Arg(3);
|
||||||
if (strcmp(cmdname, "start") == 0) {
|
if (strcmp(cmdname, "start") == 0) {
|
||||||
if (active_) {
|
IProfilingTool *tool = FindToolByName(toolname);
|
||||||
rootmenu->ConsolePrint("A profile is already active using %s.", active_->Name());
|
if (!tool) {
|
||||||
return;
|
|
||||||
}
|
|
||||||
if ((active_ = FindToolByName(toolname)) == nullptr) {
|
|
||||||
rootmenu->ConsolePrint("No tool with the name \"%s\" was found.", toolname);
|
rootmenu->ConsolePrint("No tool with the name \"%s\" was found.", toolname);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!active_->Start()) {
|
StartFromConsole(tool);
|
||||||
rootmenu->ConsolePrint("Failed to attach to or start %s.", active_->Name());
|
|
||||||
active_ = nullptr;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
g_pSourcePawn2->SetProfilingTool(active_);
|
|
||||||
g_pSourcePawn2->EnableProfiling();
|
|
||||||
rootmenu->ConsolePrint("Started profiling with %s.", active_->Name());
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (strcmp(cmdname, "help") == 0) {
|
if (strcmp(cmdname, "help") == 0) {
|
||||||
|
@ -72,9 +72,13 @@ public:
|
|||||||
|
|
||||||
IProfilingTool *FindToolByName(const char *name);
|
IProfilingTool *FindToolByName(const char *name);
|
||||||
|
|
||||||
|
private:
|
||||||
|
void StartFromConsole(IProfilingTool *tool);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ke::Vector<IProfilingTool *> tools_;
|
ke::Vector<IProfilingTool *> tools_;
|
||||||
IProfilingTool *active_;
|
IProfilingTool *active_;
|
||||||
|
IProfilingTool *default_;
|
||||||
bool enabled_;
|
bool enabled_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user