Search Results for

    Show / Hide Table of Contents

    为 Lua 脚本采样

    中文 | English

    在仓库根目录运行以下命令,用本机 Unity MCP 回放本页示例。

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

    在包含 Miku LuaProfiler 的 SDK 工程中,打开 Window → Analysis → Lua Profiler。选择 local mode,需要展开 Lua 调用时启用 Deep Lua。

    点击展开 MCP 操作点击收起 MCP 操作
    [
      {
        "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"
        }
      }
    ]
    

    在可重复的游戏场景中采一小段样本。查看 self 耗时和调用次数,并结合每帧总预算定位常被调用的高耗时函数。旧教程以 0.1 ms 提醒关注高频调用,实际预算取决于设备和场景。

    客户端回放在独立 Lua 协程检查分析器的启停和累计值重置。SDK 的 Profiler 窗口与实机开销仍待采样。

    点击展开 MCP 操作点击收起 MCP 操作
    [
      {
        "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