Skip to content

feat: multi-state profiler, portable CPU backend, cross-platform CI - #10

Merged
esrrhs merged 6 commits into
masterfrom
feature/multistate-crossplatform
Nov 3, 2026
Merged

esrrhs merged 6 commits into
masterfrom
feature/multistate-crossplatform

Conversation

@esrrhs

@esrrhs esrrhs commented Nov 3, 2026

Copy link
Copy Markdown
Owner

Summary

Implements the pLua multi-state / cross-platform roadmap on top of master @ 8d90e03.

P0

  • Multi lua_State: ProfilerSession per state; parallel CPU/mem sessions across states. Documented: multi-state ≠ multi-OS-thread safe.
  • Portable CPU sampling: POSIX ITIMER_PROF/SIGPROF (process-wide handler walks registered CPU sessions); LUA_MASKCOUNT fallback (default on Windows, optional via PLUA_CPU_BACKEND=count).
  • CI matrix: Ubuntu (build+test+examples), macOS (build+test), Windows (build / DLL artifact).

P1

  • Windows: CMake produces libplua.dll; POSIX isolated; CRT-style file IO; tests include ?.dll cpath; hookso marked unsupported.
  • macOS: .so suffix for Lua cpath; embed OK / hookso not supported in README.
  • Independent CPU vs mem: separate cpuRunning / memRunning (no shared exclusive gRunning).

P2

  • .pro v1: PLUA magic + version header; tools/plua accepts v1 and legacy; replaced deprecated ioutil.
  • Configurable rates: set_config / get_config + env PLUA_CPU_INTERVAL_MS, PLUA_CPU_HOOK_COUNT, PLUA_MEM_RATE, PLUA_CPU_BACKEND; optional 3rd args on start / start_mem.
  • Hardening: write error handling, clear string tables on stop, fix llog year (tm_year+1900), luaopen_plua alias.
  • Lua versions: honest docs — 5.2/5.3/5.4 only; 5.1/JIT not supported (compile-time check).

Tests

  • Extended C++ harness: two-state CPU, two-state mem, cross-mode, stop-one-leaves-other, same-state CPU+mem.
  • Lua unit tests: config API, magic header, platform cpath suffixes.
  • Verified locally on Linux: ctest + lua test_unit.lua green.

API compatibility

start / stop / start_mem / stop_mem unchanged for single-state use.

How to verify

cmake -B build -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=ON
cmake --build build
ctest --test-dir build --output-on-failure
cd test && lua test_unit.lua

Out of scope / deferred

  • Full Windows CI test execution (build-focused; Lua toolchain on windows-latest is best-effort).
  • Real Lua 5.1 / LuaJIT compatibility shims (documented as unsupported instead).
  • hookso on macOS/Windows (explicitly unsupported).

Notes

  • Do not merge from this bot unless requested.
  • No force-push; branch is feature/multistate-crossplatform.

- ProfilerSession per lua_State (map); parallel sessions across states
- Separate cpuRunning/memRunning (no shared gRunning mutex)
- POSIX ITIMER_PROF/SIGPROF walks all CPU sessions; LUA_MASKCOUNT fallback
  (default on Windows, optional via PLUA_CPU_BACKEND=count)
- .pro v1 header (PLUA magic + version); write error checks; clear string
  tables on stop; fix llog year (tm_year+1900)
- Configurable rates via set_config/get_config and env vars
- Windows/POSIX IO isolation; luaopen_plua alias; require Lua >= 5.2
Accept PLUA magic/version header while remaining compatible with legacy
profiles; use os.ReadFile/os.WriteFile.
- C++ harness: two-state CPU/mem, cross-mode, stop-one-leaves-other,
  independent CPU+mem on one state
- Lua unit tests: config API, PLUA magic, .dll/.dylib cpath candidates
Keep existing Ubuntu job with examples/visualization; macOS runs ctest;
Windows builds libplua.dll (tests optional/deferred when Lua toolchain
is incomplete).
Document that multi-state is not multi-OS-thread safe; hookso is Linux
only; Lua 5.1/JIT are unsupported; sample-rate API and env vars.
Chocolatey lua is 5.1.5 and lua.org FTP times out on GHA.
Fetch lua/lua v5.4.7, compile lua54.dll/lib with cl, point CMake at them.
@esrrhs
esrrhs merged commit 136185f into master Nov 3, 2026
6 checks passed
esrrhs added a commit that referenced this pull request Nov 3, 2026
Restore full Chinese README (was truncated after PR #10 merge) and polish
the English primary so both document platforms, multi-state limits,
set_config/env rates, embedding vs Linux-only hookso, .pro v1, and tools/plua.
@esrrhs
esrrhs deleted the feature/multistate-crossplatform branch November 4, 2026 06:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant