diff --git a/LICENSE.md b/LICENSE.md index e83793a5..2df04d8e 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -477,6 +477,55 @@ SOFTWARE. ******************************************************************************* +lua-profiler.lua + +******************************************************************************* + +Copyright (c) 2018-2020 Charles Mallah + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +=============================================================================== +[ lua-profiler is based on ProFi v1.3, which has this license statement: ] + +Copyright (c) 2012 Luke Perkin + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +******************************************************************************* + sha1.lua: ******************************************************************************* diff --git a/src/Modules/Profiler.lua b/runtime/lua/lua-profiler.lua similarity index 99% rename from src/Modules/Profiler.lua rename to runtime/lua/lua-profiler.lua index c0a6298d..10287b9d 100644 --- a/src/Modules/Profiler.lua +++ b/runtime/lua/lua-profiler.lua @@ -90,9 +90,9 @@ local config = { cW = 12, -- Width of the call count column reportSaved = "> Report saved to: ", -- Text for the file output confirmation } - + --[[ Locals ]]-- - + local module = {} local getTime = os.clock local string, debug, table = string, debug, table @@ -103,10 +103,10 @@ local config = { local stopTime = 0 local printFun = nil local verbosePrint = false - + local outputHeader, formatHeader, outputTitle, formatOutput, formatTotalTime local formatFunLine, formatFunTime, formatFunRelative, formatFunCount, divider, nilTime - + local function deepCopy(input) if type(input) == "table" then local output = {} @@ -118,7 +118,7 @@ local config = { return input end end - + local function charRepetition(n, character) local s = "" character = character or " " @@ -127,14 +127,14 @@ local config = { end return s end - + local function singleSearchReturn(inputString, search) for _ in string.gmatch(inputString, search) do -- luacheck: ignore return true end return false end - + local function rebuildColumnPatterns() local c = config local str = "s: %-" @@ -151,7 +151,7 @@ local config = { -- nilTime = "0."..charRepetition(c.tW - 3, "0") nilTime = "0.0000" end - + local function functionReport(information) local src = information.short_src if not src then @@ -180,7 +180,7 @@ local config = { end return report end - + local onDebugHook = function(hookType) local information = debug.getinfo(2, "nS") if hookType == "call" then @@ -194,9 +194,9 @@ local config = { end end end - + --[[ Functions ]]-- - + --[[Attach a print function to the profiler, to receive a single string parameter @param fn (function) @param verbose (boolean) @@ -205,7 +205,7 @@ local config = { printFun = fn verbosePrint = verbose or false end - + --[[Start the profiling ]] function module.start() @@ -219,14 +219,14 @@ local config = { stopTime = nil debug.sethook(onDebugHook, "cr", 0) end - + --[[Stop profiling ]] function module.stop() stopTime = getTime() debug.sethook() end - + --[[Writes the profile report to file (will stop profiling if not stopped already) @param filename (string) [File will be created and overwritten] ]] @@ -289,7 +289,7 @@ local config = { printFun(config.reportSaved.."'"..filename.."'") end end - + --[[Modify the configuration of this module programmatically; Provide a table with keys that share the same name as the configuration parameters: @param overrides (table) [Each key is from a valid name, the value is the override] @@ -306,6 +306,6 @@ local config = { end rebuildColumnPatterns() end - + --[[ End ]]-- - return module \ No newline at end of file + return module diff --git a/src/Modules/Common.lua b/src/Modules/Common.lua index ea1d057b..781c12ab 100644 --- a/src/Modules/Common.lua +++ b/src/Modules/Common.lua @@ -27,7 +27,7 @@ common.base64 = require("base64") common.sha1 = require("sha1") -- Uncomment if you need to perform in-depth profiling ---profiler = LoadModule("Modules/Profiler") +-- profiler = require("lua-profiler") -- Class library common.classes = { }