Search Results for

    Show / Hide Table of Contents

    Profile a Lua script

    δΈ­ζ–‡ | English

    Run this command at the repository root to replay the examples through the local Unity MCP.

    python Docs/Manual/manual/tools/tutorials.py run lua-profiler
    

    In an SDK project that includes Miku LuaProfiler, open Window β†’ Analysis β†’ Lua Profiler. Select local mode and enable Deep Lua when you need detailed Lua calls.

    Click to expand MCP actionsClick to collapse MCP actions
    [
      {
        "tool": "invoke",
        "arguments": {
          "path": "static:System.IO.File/ReadAllText",
          "args": [
            "../../../Panzer-War-Mod-SDK/Packages/Sdk/com.shanghaiwindy.middlelayer/ThirdLibs/Miku-LuaProfiler-4.0.2/LuaProfiler/Editor/Window/ProfilerWin/TreeView/LuaProfilerWindow.cs"
          ]
        },
        "expect": {
          "contains": "MenuItem(\"Window/Analysis/Lua Profiler"
        }
      }
    ]
    

    Capture a short sample in a repeatable game scene. Look at self time, call count and the frame budget together. The older guide flagged frequent calls above 0.1 ms. The working budget depends on the device and scene.

    The client replay tests start, stop and reset in an isolated Lua coroutine. Profiling with the SDK window and measuring actual game cost remain pending.

    Click to expand MCP actionsClick to collapse MCP actions
    [
      {
        "tool": "invoke",
        "arguments": {
          "path": "static:ShanghaiWindy.Core.AssetBundleManager/LuaEnv/DoString",
          "args": [
            "local E = setmetatable({ class = function() return {} end }, { __index = _G })\nlocal P = assert(loadfile(\"../LuaProject/frame/profiler.lua\", \"t\", E))()\nlocal p = setmetatable({}, { __index = P })\np:ctor()\nlocal work = coroutine.create(function()\n    p:EnableProfile()\n    assert(p.enableProfiler)\n    local function sample() return 7 end\n    for i = 1, 100 do assert(sample() == 7) end\n    p:DisableProfile()\n    assert(not p.enableProfiler and debug.gethook() == nil)\n    assert(p:OnProfile() >= 0)\n    assert(p:OnProfile() == 0)\nend)\nassert(coroutine.resume(work))\nreturn \"Profiler sample passed\"\n",
            "manual-lua-profile",
            "null"
          ]
        },
        "expect": {
          "contains": "Profiler sample passed"
        }
      }
    ]
    
    In this article
    Back to top Panzer War Document