samp.directory
← Scripts y librerías

imshooter/omp-profiler-component

An open.mp component that measures where a server spends its time in Pawn and writes an HTML report.

Plugin★ 0actualizado hace 5 díasMITC++
Abrir en GitHub

README.md

Profiler

An open.mp component that measures where a server spends its time in Pawn and writes the results to an HTML report. It loads from the components folder and is configured in config.json, so it needs no server.cfg.

What the report shows

  • Pawn time per second after the start up, with the worst tick of each second.
  • Slowest ticks, the ten server ticks with the most Pawn time and the publics that ran in each.
  • Publics with calls, total time, own time, average, worst call and when it happened, and how the calls spread over time ranges. Clicking a public lists the natives it calls.
  • Natives with the same figures. Clicking a native lists the publics that call it.
  • Functions, every function of a script compiled with -d2 or -d3, timed from its debug information.
  • Start up, the Pawn time before the first server tick, kept apart from the running server.
  • Stack and heap, the highest use seen at native calls.
  • Run time errors with the public, the last native and, when the script has debug information, the file, line and call chain. Errors inside CallLocalFunction, which the server does not log without crashdetect, are listed too.

Own time leaves out the natives, functions and other publics a call starts.

Installation

  1. Download the latest release from Releases.
  2. Place Profiler.dll in the components folder of the server.
  3. Start the server.

Tested with open.mp 1.6.7 on Windows. It works alongside legacy plugins that hook the same functions, such as crashdetect and PawnPlus. Only a Windows build is available for now.

Usage

A report is written when the server exits, when the main script unloads and on the profiler command. Reports go to profiler/<script>-<date>.html, and profiler/latest.html is always the newest one.

CommandAction
profilerWrites a report.
profiler resetClears what was measured.
profiler stopPauses the measuring.
profiler startResumes it.

Commands are read from the server console, from RCON and from SendRconCommand.

Configuration

Every setting is optional. These are the defaults:

"profiler": {
    "enable": true,
    "scripts": [],
    "natives": true,
    "callers": true,
    "functions": true,
    "errors": true,
    "output": "profiler"
}
KeyDescription
enableTurns the component on.
scriptsScripts to profile, named as in pawn.main_scripts and pawn.side_scripts. A side script also matches by its file name, such as "admin" for "filterscripts/admin". An empty list profiles every script.
nativesTimes every native call.
callersRecords which publics call each native.
functionsTimes every function of scripts compiled with -d2 or -d3.
errorsRecords run time errors.
outputFolder of the reports, relative to the server.

To profile only the gamemode:

"profiler": {
    "scripts": ["main"]
}

Overhead

The component estimates its own cost at about 20 ns per timed call and gives the total in the footer of the report. Timing functions also adds a check to every statement of a -d2 or -d3 build. With 50 bots in the stress example, a -d0 build used 11.8 ms of Pawn per second, a -d3 build 13.0 ms and a -d3 build with its functions timed 16.6 ms. Set functions to false when that cost matters.

Stress example

examples/stress-example.pwn keeps 50 bots busy for three minutes. They walk around, look up the zone they stand in, pick up coins, chat and use a command. One of them leaves and comes back every twenty seconds, and every bot is saved to a file every ten. The screenshot above is its report.

  1. Compile it with -d3, so the report also times its functions.
  2. In config.json, set max_players and max_bots to 50 or more and pawn.main_scripts to ["stress-example"].
  3. Start the server. It shuts down after three minutes and the report is in profiler/.

The bots need the NPC component of open.mp.

Building

Windows with Visual Studio 2022 or its Build Tools, and CMake 3.19 or later. CMake fetches the open.mp SDK and the Pawn headers.

cmake -S . -B build -A Win32
cmake --build build --config Release

The component is written to build/Release/Profiler.dll. The server is 32 bit, so the component must be too.

Tests

tests/profiler-test.pwn gives every part of the report something to show in four seconds, then shuts the server down. Compile it with -d3, run it as the main script and compare the report with what the file describes.

Thanks to

License

Released under the MIT License.

open-mppawnperformanceprofilersa-mp

Esta página se genera con lo que GitHub publica sobre el repositorio. samp.directory no aloja el código. Informar de un problema con esta ficha

imshooter/omp-profiler-component: Plugin de SA-MP | samp.directory