Skip to main content
Glama

Cost of a hook's functions

perf_hook_cost
Read-only

Measures per-function time spent during a Garry's Mod hook event over a chosen duration, reporting calls, total/avg/max ms, and source lines sorted by cost.

Instructions

Measures over duration_s the time spent in each function of a hook event: every hook.Add function registered when it starts, and GAMEMODE:. Each one is wrapped with a timer for the measurement and put back afterwards (restored = how many hooks were put back; a hook replaced meanwhile is left alone). Waits the whole duration. Result: {event, duration_s, functions: [{id, calls, total_ms, avg_ms, max_ms, src {source, line}}] sorted by total_ms, most expensive first, restored}. The game runs at its real frame rate: on a light test client (20 fps) the number of calls is lower than in a normal game. Example: {"realm": "client", "event": "Think", "duration_s": 10} (event is required; the length is duration_s, not seconds).

Tool call template

Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.

{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "tools/call",
  "params": {
    "arguments": {
      "event": "<event>"
    },
    "name": "perf_hook_cost"
  }
}

Input Schema

NameRequiredDescriptionDefault
eventYesHook event name, e.g. 'Think', 'Tick', 'PlayerTick'.
realmNoDefault server.
instanceNoOptional. Instance identifier (see instances_list). If present and different from the local instance, the call is relayed by the coordinator to that instance.
duration_sNoMeasurement length in seconds (default 5).

Output Schema

NameRequiredDescriptionDefault
nextNo
noteNo
eventYes
warningNo
restoredNo
functionsYes
next_callNo
duration_sNo
answered_byNo
truncated_noteNo
version_warningNo

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv0.3.7

TDQS

A4.4/5.0
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Adds substantial behavior beyond the readOnlyHint annotation: each hook function is wrapped with a timer and restored afterwards, `restored` counts restorations, and a hook replaced mid-measurement is deliberately left alone. It also discloses that the call blocks for the whole duration and that measured call counts are frame-rate dependent — exactly the non-obvious traits an agent needs.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Front-loads the core operation, then mechanism, then result shape and caveat, with no filler sentences. It is dense and packs the result schema and caveats into one long block, which slightly hurts scannability but every clause carries information.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a blocking profiling tool with four parameters, the definition covers mechanism, mutation-and-restore semantics, blocking duration, result ordering, and the frame-rate caveat. An output schema exists, yet the inline result shape and the example call make the tool fully usable as defined.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is already 100%, so the baseline is 3; the description still earns more by clarifying that `event` is required and that duration is expressed via `duration_s` rather than a 'seconds' field, and by mentioning the realm context ('the game runs at its real frame rate'). It does not restate the enum values or the instance-relay behavior, which the schema covers.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

States a specific verb and resource: 'Measures over duration_s the time spent in each function of a hook event', and further scopes it to hook.Add callbacks plus GAMEMODE:<event>. This is distinguishable from a generic profiler (perf_snapshot) or an event tracer (hook_trace) without opening a schema.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Provides a concrete example invocation and warns that results depend on client frame rate (20 fps test client yields fewer calls), which guides interpretation. However it never states when to prefer this over hook_trace or hook_list, nor any preconditions such as needing the game running in the right realm; usage is implied rather than routed.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.