Documentation
¶
Overview ¶
Package isutools is an all-in-one profiling module for ISUCON-style tuning: wrap your SQL driver, download sorted reports.
Minimal integration (1 line):
db, _ := sqlx.Open(isutools.SQLDriverName("mysql"), dsn)
SQLDriverName also starts a small admin server (default 127.0.0.1:19191, override with ISUTOOLS_ADDR, disable with ISUTOOLS_ADDR=off) serving the report UI, snapshot export, and POST /reset — the control channel for bench scripts. It intentionally runs on its own port so the application router and reverse proxy never expose it.
ISUTOOLS=off disables everything: SQLDriverName then returns the raw driver name, so the application runs unproxied with zero overhead. The on/off decision is made once at startup; it is not dynamic.
Index ¶
- Constants
- Variables
- func AddCount(name string, delta int64)
- func Count(name string)
- func HTTP(next http.Handler) http.Handler
- func Handler() http.Handler
- func Off() bool
- func PeerHandler(options PeerOptions) (http.Handler, error)
- func ProfileRegion(ctx context.Context, region string, fn func(context.Context))
- func ProfileScenario(ctx context.Context, scenario string, fn func(context.Context))
- func RegisterDBInspector(targetID string, purpose sqlstats.Purpose, driverName, dsn string) error
- func RegisterDBTarget(id, driverName, dsn string) error
- func RegisterSQL(names ...string) error
- func SQLDriverName(name string) string
- func SerializeInitialize(ctx context.Context, fn func(context.Context) error) error
- func ServePeer(ctx context.Context, addr string, options PeerOptions) error
- func UnwatchDBPool(targetID string) error
- func WatchDBPool(targetID string, db *sql.DB) error
- type GlobalConfig
- type PeerOptions
- type StartResult
- type Validity
Constants ¶
const ( // ValidityValid means every collector contributed a complete interval. ValidityValid = runctl.ValidityValid // ValidityPartial means optional sections are missing but the interval is // usable. ValidityPartial = runctl.ValidityPartial // ValidityInvalid means the interval cannot be trusted and must not be // compared with other runs. ValidityInvalid = runctl.ValidityInvalid )
Validity values, re-exported for the same reason as the types above.
const ( EnvPeer = "ISUTOOLS_PEER" EnvPeerToken = "ISUTOOLS_PEER_TOKEN" )
Variables ¶
var ErrInitializeBusy = runctl.ErrInitializeBusy
ErrInitializeBusy reports that SerializeInitialize could not acquire the process-wide initialize guard in time.
var ErrPeerListenerNotLoopback = errors.New("isutools: peer listener must use a literal loopback address")
Functions ¶
func Count ¶ added in v0.7.0
func Count(name string)
Count increments a named user counter by 1 (e.g. cache hit/miss). Shown in the report's Counters section, reset per generation. No-op when off.
func HTTP ¶ added in v0.2.0
HTTP instruments inbound HTTP requests. When ISUTOOLS=off it returns next unchanged, avoiding request-path overhead. Path normalization rules can be injected via ISUTOOLS_PATH_RULES ("regex=replacement;..." — split on the last '=' of each pair).
func Handler ¶
Handler serves the report UI: GET / (dashboard with snapshot history), GET /snapshot.html (download), GET /json, GET /files/<name>, POST /reset, POST /collect, POST /finish, POST /abort, POST /save. /reset opens a measurement run and /finish or /save closes it; /collect stays a non-terminal flush of the buffered access log. Snapshot history persists to ISUTOOLS_DATA_DIR when set. The DB schema is inspected through the first DSN the application opened, using the raw driver so inspection queries never appear in the SQL statistics.
Every handler shares the process-wide measurement core, so two calls observe one run lifecycle and one process baseline rather than two unrelated ones.
func Off ¶
func Off() bool
Off reports the immutable process-start decision for ISUTOOLS. Accepted hard-off spellings are off, 0, false, no, and disabled (case-insensitive).
func PeerHandler ¶ added in v1.5.0
func PeerHandler(options PeerOptions) (http.Handler, error)
PeerHandler exposes the singleton run controller to a loopback-only peer listener. It intentionally does not create a second measurement lifecycle.
func ProfileRegion ¶ added in v1.4.0
ProfileRegion is the region counterpart to ProfileScenario.
func ProfileScenario ¶ added in v1.4.0
ProfileScenario binds a safe logical scenario to CPU samples taken while fn runs. The value is never written directly into the pprof string table; the active capture stores it behind an opaque tuple ID. Invalid values and an inactive profiler fail open and still invoke fn.
func RegisterDBInspector ¶ added in v1.2.0
RegisterDBInspector attaches a second credential to an existing target: a stats user for SHOW STATUS and performance_schema, or a least-privilege EXPLAIN user. The purpose is explicit and never falls back to the application credential, because an implicit downgrade to a credential holding DML rights would defeat the point of a restricted inspector.
For PurposeExplain it is the only registration path once a process has more than one target: with two databases registered, ISUTOOLS_EXPLAIN_DSN cannot say which one it belongs to, so it is refused and recorded in health rather than applied to a guess. A single-target process may use that variable (plus ISUTOOLS_EXPLAIN_DRIVER, default "mysql") instead of calling this function. Either way, EXPLAIN capture itself still requires ISUTOOLS_EXPLAIN=1.
It is re-exported from sqlstats so an application configures isutools through one package.
func RegisterDBTarget ¶ added in v1.2.0
RegisterDBTarget declares a logical database under a stable ID, so every collector that reports per-database numbers joins on the same key. Prefer it over an auto-derived ID whenever another API needs to name the target: derived IDs end in a hash and cannot be spelled out by hand.
It is re-exported from sqlstats so an application configures isutools through one package.
func RegisterSQL ¶
RegisterSQL wraps the named drivers ("mysql", "pgx", ...) and registers measuring variants under "<name>:isutools". Prefer SQLDriverName, which also resolves the on/off decision. No-op when disabled.
func SQLDriverName ¶
SQLDriverName registers a measuring wrapper for the named driver and returns the driver name the application should open. When disabled — or if registration fails — it returns the raw name unchanged, so measurement can never break application startup (fail-open). On success it also starts the admin server once.
func SerializeInitialize ¶ added in v1.2.0
SerializeInitialize runs fn as the only initialize in this process.
ResetNow fixes the boundary but cannot stop a second initialize from rebuilding the database into a run that has already started; only serializing the whole handler can. Wrap the entire initialize body — schema rebuild, fixture load, and the ResetNow call at its end — in this function.
The context handed to fn carries a guard marker, so a run opened inside it is distinguishable from one opened outside. Waiting for the guard is abandoned after runctl.InitializeGuardBudget with ErrInitializeBusy: hanging forever on a stuck initialize would be worse than reporting it.
The guard is process-local by construction. It cannot serialize initialize across processes or hosts.
Unlike the rest of this package it keeps working when ISUTOOLS=off. An application that serializes its initialize through this function must not silently lose that serialization because a measurement flag flipped, and the cost of the guard is one channel send.
func ServePeer ¶ added in v1.5.0
func ServePeer(ctx context.Context, addr string, options PeerOptions) error
ServePeer serves PeerHandler on a literal loopback listener until ctx ends.
func UnwatchDBPool ¶ added in v1.2.0
UnwatchDBPool stops reporting a pool and takes a final farewell sample at the moment of the call, so a pool retired mid-run still reports the part of the run it was present for. Call it before closing the *sql.DB: it also drops this package's last reference to the handle.
func WatchDBPool ¶ added in v1.2.0
WatchDBPool reports one *sql.DB's connection pool under an already registered TargetID, so pool waits can be lined up with the SQL statistics of the same database.
The pool joins the NEXT run, not the one in flight: giving it a baseline taken after the run started would report a fraction of the interval as if it were the whole of it.
The ID must already exist in the registry, compared byte for byte. Watch never creates a target, because a typo that silently created a second one would split a single database across two rows of every report. Obtain the ID from RegisterDBTarget, or look it up with sqlstats.TargetIDForDSN.
Types ¶
type GlobalConfig ¶ added in v1.5.0
GlobalConfig is the immutable process-wide enablement decision.
type PeerOptions ¶ added in v1.5.0
type StartResult ¶ added in v1.2.0
type StartResult = runctl.StartResult
StartResult is the immutable record of an opening boundary returned by ResetNow. It is an alias rather than a distinct type because the run lifecycle lives in an internal package that applications cannot import: without the alias a caller could read the value but never name its type.
func ResetNow ¶ added in v1.2.0
func ResetNow(ctx context.Context) (StartResult, error)
ResetNow opens a new measurement run immediately, preempting one already in flight so that the last initialize deterministically wins.
It is the initialize contract, and both halves of it matter:
- Call it BEFORE sending the initialize response. The benchmarker starts loading the moment it sees the response, and a boundary taken after that silently drops the opening seconds of the run.
- Treat a failure as a failure. If it returns an error, or a Validity of ValidityInvalid, the handler should answer 500 rather than measure a run it already knows is contaminated: an authoritative-looking wrong number is worse than a missing one.
Taking the boundary is not by itself enough. It serializes only the instant of the switch, so a second initialize rebuilding the database afterwards still pollutes this run. Wrap the whole handler in SerializeInitialize; a run opened with Reason "initialize" outside that guard is recorded as degraded health rather than silently trusted.
When measurement is disabled (ISUTOOLS=off) it reports a zero StartResult and no error, so an initialize handler needs no build tags or branches.
func ResetNowOpts ¶ added in v1.2.0
func ResetNowOpts(ctx context.Context, o runctl.StartRunOptions) (StartResult, error)
ResetNowOpts is ResetNow with explicit options, for callers that need a non-preempting start or a different trigger. Note that the zero options value does NOT preempt, so a start that collides with a run already in flight reports runctl.ErrRunActive instead of winning.
func ResetNowWithNonce ¶ added in v1.2.0
func ResetNowWithNonce(ctx context.Context, nonce string) (StartResult, error)
ResetNowWithNonce is ResetNow with a caller-supplied idempotency key. Repeating a call with the same nonce replays the original StartResult instead of opening a second run, which is what makes a retried initialize request safe.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package accesslog parses and aggregates explicitly configured nginx LTSV, flat JSON, Caddy native JSON, and explicit Apache JSON access logs.
|
Package accesslog parses and aggregates explicitly configured nginx LTSV, flat JSON, Caddy native JSON, and explicit Apache JSON access logs. |
|
adapters
|
|
|
chiv5
module
|
|
|
echov4
module
|
|
|
Package advisor detects well-known ISUCON-critical settings that are NOT configured (prepared-statement round trips, nginx gzip/keepalive, kernel limits, GOMAXPROCS vs CPU quota, MySQL sizing) and reports them so the dashboard always shows what standard lever has not been pulled yet.
|
Package advisor detects well-known ISUCON-critical settings that are NOT configured (prepared-statement round trips, nginx gzip/keepalive, kernel limits, GOMAXPROCS vs CPU quota, MySQL sizing) and reports them so the dashboard always shows what standard lever has not been pulled yet. |
|
Package buildinfo resolves the git revision and dirty state of the running binary: from Go's embedded VCS stamps when available, otherwise from ldflags-injected variables or environment variables.
|
Package buildinfo resolves the git revision and dirty state of the running binary: from Go's embedded VCS stamps when available, otherwise from ldflags-injected variables or environment variables. |
|
cmd
|
|
|
isutools-agent
command
Command isutools-agent serves a standalone, loopback-only multi-host peer.
|
Command isutools-agent serves a standalone, loopback-only multi-host peer. |
|
isutools-hub
command
Command isutools-hub coordinates loopback peers reached through SSH tunnels.
|
Command isutools-hub coordinates loopback peers reached through SSH tunnels. |
|
isutools-pprof
command
|
|
|
isutools-trajectory
command
Command isutools-trajectory turns adapter-produced NDJSON into a portable interactive trajectory report.
|
Command isutools-trajectory turns adapter-produced NDJSON into a portable interactive trajectory report. |
|
Package counters is the generic user-defined counter API: one line in application code (isutools.Count("cache_hit")) makes cache hit/miss and similar custom events visible per benchmark generation.
|
Package counters is the generic user-defined counter API: one line in application code (isutools.Count("cache_hit")) makes cache hit/miss and similar custom events visible per benchmark generation. |
|
Package dbcap publishes credential-free, per-target database capabilities.
|
Package dbcap publishes credential-free, per-target database capabilities. |
|
Package dbinspect captures the database schema state (tables, row counts, indexes) so every benchmark snapshot records what indexes existed BEFORE the run.
|
Package dbinspect captures the database schema state (tables, row counts, indexes) so every benchmark snapshot records what indexes existed BEFORE the run. |
|
Package dbpool reports database/sql connection-pool statistics for one measurement run.
|
Package dbpool reports database/sql connection-pool statistics for one measurement run. |
|
Package hoststats measures host resources over one measurement run and records the identity of the host the agent is actually looking at.
|
Package hoststats measures host resources over one measurement run and records the identity of the host the agent is actually looking at. |
|
Package httpstats provides bounded, in-memory HTTP request measurements.
|
Package httpstats provides bounded, in-memory HTTP request measurements. |
|
internal
|
|
|
agentconfig
Package agentconfig loads the standalone peer's secret-bearing files.
|
Package agentconfig loads the standalone peer's secret-bearing files. |
|
agg
Package agg is the shared aggregation core: a concurrency-safe, bounded key→latency table with log2-bucket histograms for approximate percentiles.
|
Package agg is the shared aggregation core: a concurrency-safe, bounded key→latency table with log2-bucket histograms for approximate percentiles. |
|
generation
Package generation provides atomic collector generation swaps.
|
Package generation provides atomic collector generation swaps. |
|
health
Package health records collector degradation without making failures fatal to the instrumented application.
|
Package health records collector degradation without making failures fatal to the instrumented application. |
|
hubconfig
Package hubconfig loads the secret-bearing multi-host peer list.
|
Package hubconfig loads the secret-bearing multi-host peer list. |
|
runctl
Package runctl owns the measurement run lifecycle: a single process-wide Controller decides when a run starts, when its boundaries are frozen, when its immutable snapshot may be published, and when it is aborted.
|
Package runctl owns the measurement run lifecycle: a single process-wide Controller decides when a run starts, when its boundaries are frozen, when its immutable snapshot may be published, and when it is aborted. |
|
sysinfo
Package sysinfo resolves static host facts (CPU model, core count, total memory, OS) shown in every report so measurements are always attributable to the hardware they ran on.
|
Package sysinfo resolves static host facts (CPU model, core count, total memory, OS) shown in every report so measurements are always attributable to the hardware they ran on. |
|
timeline
Package timeline records bounded, run-aligned measurements and derives transparent correlation signals.
|
Package timeline records bounded, run-aligned measurements and derives transparent correlation signals. |
|
Package multihost implements the evidence-bounded hub/peer protocol.
|
Package multihost implements the evidence-bounded hub/peer protocol. |
|
Package netstats reports network observations for a benchmark run: a TCP socket summary observed at each boundary and per-interface throughput, packet, error and drop counters accumulated between them.
|
Package netstats reports network observations for a benchmark run: a TCP socket summary observed at each boundary and per-interface throughput, packet, error and drop counters accumulated between them. |
|
Package procstats measures per-process CPU and RSS over a reset-to-snapshot interval using Linux procfs.
|
Package procstats measures per-process CPU and RSS over a reset-to-snapshot interval using Linux procfs. |
|
Package queryplan runs EXPLAIN against the statements that dominated a benchmark run and publishes the resulting plans.
|
Package queryplan runs EXPLAIN against the statements that dominated a benchmark run and publishes the resulting plans. |
|
Package sessionlabel provides a framework-neutral trusted edge adapter for pseudonymising an application session before nginx writes access logs.
|
Package sessionlabel provides a framework-neutral trusted edge adapter for pseudonymising an application session before nginx writes access logs. |
|
Package sqlrows measures per-digest row efficiency — rows examined against rows sent — over a benchmark run, by sampling performance_schema.events_statements_summary_by_digest at both run boundaries and reporting the difference.
|
Package sqlrows measures per-digest row efficiency — rows examined against rows sent — over a benchmark run, by sampling performance_schema.events_statements_summary_by_digest at both run boundaries and reporting the difference. |
|
Package sqlstats wraps database/sql drivers with a measuring proxy and aggregates every query into an in-memory table.
|
Package sqlstats wraps database/sql drivers with a measuring proxy and aggregates every query into an in-memory table. |
|
Package trajectoryviz renders bounded, application-agnostic agent/job trajectories as a self-contained HTML animation.
|
Package trajectoryviz renders bounded, application-agnostic agent/job trajectories as a self-contained HTML animation. |
|
Package web renders isutools measurements: a live report, a self-contained downloadable snapshot.html, machine-readable JSON, and a reset endpoint.
|
Package web renders isutools measurements: a live report, a self-contained downloadable snapshot.html, machine-readable JSON, and a reset endpoint. |




