-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
tracy.LuaTracyPlot
and tracy.LuaTracyPlotConfig
- Loading branch information
Showing
9 changed files
with
168 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* This file is part of the Recoil engine (GPL v2 or later). */ | ||
|
||
#include "LuaInclude.h" | ||
#include "LuaUtils.h" | ||
|
||
#include "LuaTracyExtra.h" | ||
#include "System/Misc/TracyDefs.h" | ||
|
||
#include <tracy/Tracy.hpp> | ||
#include <common/TracyQueue.hpp> | ||
|
||
#include "System/Log/ILog.h" | ||
|
||
/****************************************************************************** | ||
* tracy extensions | ||
* @module TracyExtra | ||
* @see rts/Lua/LuaTracyExtra.cpp | ||
******************************************************************************/ | ||
|
||
bool LuaTracyExtra::PushEntries(lua_State* L) | ||
{ | ||
LuaPushNamedCFunc(L, "LuaTracyPlot" , LuaTracyPlot ); | ||
LuaPushNamedCFunc(L, "LuaTracyPlotConfig", LuaTracyPlotConfig); | ||
return true; | ||
} | ||
|
||
|
||
|
||
/*** Configure custom appearence for a Tracy plot for use in debugging or profiling | ||
* | ||
* @function tracy.LuaTracyPlotConfig | ||
* @string plotName which should be customized | ||
* @string[opt] plotFormatType "Number"|"Percentage"|"Memory", default "Number" | ||
* @bool[opt] step stepwise chart, default true is stepwise | ||
* @bool[opt] fill color fill, default false is no fill | ||
* @number[opt] color unit32 number as BGR color, default white | ||
* @treturn nil | ||
*/ | ||
|
||
int LuaTracyExtra::LuaTracyPlotConfig(lua_State* L) | ||
{ | ||
const auto plotName = luaL_checkstring(L, 1); | ||
const auto plotFormatTypeString = luaL_optstring(L, 2, ""); | ||
const auto step = luaL_optboolean(L, 3, true); // stepwise default | ||
const auto fill = luaL_optboolean(L, 4, false); // no fill default | ||
const uint32_t color = luaL_optint(L, 5, 0xFFFFFF); // white default | ||
|
||
tracy::PlotFormatType plotFormatType; | ||
switch (plotFormatTypeString[0]) { | ||
case 'p': case 'P': plotFormatType = tracy::PlotFormatType::Percentage; break; | ||
case 'm': case 'M': plotFormatType = tracy::PlotFormatType::Memory; break; | ||
default: plotFormatType = tracy::PlotFormatType::Number; break; | ||
} | ||
|
||
auto plot = tracyLuaPlots.find(plotName); | ||
if (plot == tracyLuaPlots.end()) | ||
plot = tracyLuaPlots.emplace(plotName).first; | ||
|
||
TracyPlotConfig(plot->c_str(), plotFormatType, step, fill, color); | ||
return 0; | ||
} | ||
|
||
|
||
/*** Update a Tracy Plot with a value | ||
* | ||
* @function tracy.LuaTracyPlot | ||
* @string plotName which LuaPlot should be updated | ||
* @number plotvalue the number to show on the Tracy plot | ||
* @treturn nil | ||
*/ | ||
int LuaTracyExtra::LuaTracyPlot(lua_State* L) | ||
{ | ||
const auto plotName = luaL_checkstring(L, 1); | ||
const auto plotValue = luaL_checkfloat(L, 2); | ||
|
||
auto plot = tracyLuaPlots.find(plotName); | ||
if (plot == tracyLuaPlots.end()) | ||
plot = tracyLuaPlots.emplace(plotName).first; | ||
|
||
TracyPlot(plot->c_str(), plotValue); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* This file is part of the Recoil engine (GPL v2 or later), see LICENSE.html */ | ||
|
||
#pragma once | ||
|
||
#include <functional> | ||
#include <set> | ||
#include <string> | ||
|
||
struct lua_State; | ||
|
||
class LuaTracyExtra { | ||
|
||
private: | ||
/* Tracy seems to want unique, unchanging strings to be passed to | ||
* its API, so we need to immanentize the ephemeral Lua strings | ||
* and store them. | ||
* | ||
* NB: strings here are never really cleaned up, but the use case assumes | ||
* that they live a long time and there's just a handful of them. */ | ||
inline static std::set <std::string, std::less<>> tracyLuaPlots; | ||
|
||
static int LuaTracyPlot(lua_State* L); | ||
static int LuaTracyPlotConfig(lua_State* L); | ||
public: | ||
static bool PushEntries(lua_State* L); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters