Skip to content

Full read+write support for PCP archives for all sysstat tools - #459

Open
natoscott wants to merge 8 commits into
sysstat:masterfrom
natoscott:pcp-read-write
Open

natoscott wants to merge 8 commits into
sysstat:masterfrom
natoscott:pcp-read-write

Conversation

@natoscott

@natoscott natoscott commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

This PR extends the existing Performance Co-Pilot (PCP) support in sysstat, optionally allowing sadc to write PCP archives as well (previously, only sadf wrote PCP archives).

A new sadc -O option is added. This provides three modes of recording in sadc:

  -O sa (the default, no change, write native sysstat format)
  -O pcp (write PCP archive format instead)
  -O sa+pcp (write both native and PCP formats simultaneously)

You can switch between choices at any time, with no unexpected side-effects. Samples written to the PCP archives are recorded at sub-second precision (in nanoseconds).

A local-context mode of PCP sampling is introduced to extend sysstat metric coverage: any PCP shared library agent can supply groups of metrics (via a new configuration file), which sadc will then record along with the rest of its regular metrics.

Using this feature, recording of process metrics is enabled with -D XALL, as well as CIFS and tape metrics. 🎉

The pidstat, cifsstat, tapestat tools are updated to be able to replay these recorded metric groups. The mpstat and iostat tools are also updated to be able to report historical data from regular sadc CPU and disk activity groups. Hence, all sysstat tools can now replay recorded metrics.

The PCP code in sysstat is updated to use the more efficient handle-based PMI functions now.

This PR makes optional use of features recently added to PCP (version 7.2.0 or later) specifically to aid these sysstat features, which the ./configure process detects.

The core design here remains heavily based on discussions between @stevekay @sysstat and myself some time ago, however the local-context mode for recording additional PCP metrics is a more recent inspiration.

Resolves: #10, #11, #111, #220, #251, #407
Related: #93, #135, #251

@natoscott

Copy link
Copy Markdown
Contributor Author

CI/build failure for old versions of PCP - I'll fix that when I return from vacation.

@natoscott

Copy link
Copy Markdown
Contributor Author

Example showing sadc running with no PCP daemons required, and dstat reporting system and process metrics from an sadc archive. The highlighted "activites" are the local-context mode defaults from /etc/sysconfig/sysstat.pcpconf - incl. PROC for the process metrics.

Screenshot 2026-10-09 at 7 43 48 PM

Comment thread sadc.c Fixed
Comment thread pcp_pidstat.c Fixed
@natoscott
natoscott force-pushed the pcp-read-write branch 4 times, most recently from bebbcef to 73b12fe Compare November 9, 2026 02:17
Comment thread sadc.c
if (!WRITE_PCP_ONLY(flags)) {
/* Output path is chosen by the operator: not untrusted input. */
/* codeql[cpp/path-injection] */
open_ofile(&ofd, ofile, restart_mark);
@natoscott

Copy link
Copy Markdown
Contributor Author

@sysstat remaining CodeQL alerts are pre-existing false positives (bounded strcpy in add_list_item(); user supplied sadc -o path) and inline suppressions are ignored by the PR check - could you take a look and dismiss them, or should I make some code changes to avoid/workaround these?

Generic needs for PCP integration - time handling interface supporting
nanosecond precision and keep in-memory disk read/write/discard counts
for storing as individual PCP metrics (sadc normally aggregates them).

Header file preparation for additional PCP code under HAVE_PCP macro.
As a side-effect, use a single shared definition of dplaces_nr instead
of accessing it in common.c and redefining it across several tools.

Signed-off-by: Nathan Scott <[email protected]>
Implements PCP archive reading (sadf, sar, cifsiostat, iostat,
mpstat, pidstat and tapestat) and writing (sadc -O), including
a novel configurable local context PCP mechanism for sampling
metrics (by name, via sysstat.pcpconf) which allows per-process
metrics recording by sadc.

Refactors pcp_def_metrics for more efficient lookups - avoid the
string metric name mechanisms (linear search every time). Match
with PCP package kernel metric names more accurately, especially
relating to the disk/dm/md/zram naming convention. Implement new
metrics for sadc to write relating to sysstat details (version,
comments, interval, activities, and so on). Many more subtleties
relating to matching the PCP code in sysstat up with the code in
PCP itself improved - such as the load indoms matching exactly -
these things improve the use of sadc PCP archives with PCP tools
and grafana-pcp.

Signed-off-by: Nathan Scott <[email protected]>
PCP 7 bumped PMAPI to version 4, switching pmLogLabel, pmSetMode() and
pmResult timestamps from struct timeval to struct timespec, changed
pmiWrite() to take nanoseconds, and added PMI_APPEND plus a set of new
libpcp_import helpers.

Introduce pcp_compat.h, which aliases the high resolution PMAPI calls
(pmGetHighResArchiveLabel, pmSetModeHighRes, pmFetchHighRes,
pmFreeHighResResult) to the plain names when the headers predate
PMAPI_VERSION_4.  Those interfaces have always carried struct timespec
timestamps, so no timeval conversion is needed and archive contents are
identical on both generations.

Features that have no older equivalent stay behind HAVE_PMI_APPEND:
local PMDA metrics, volume rotation, pmiExtraUnits() and
pmiSetImportProgram().  On older libpcp:

  - pmiPutAtomValueHandle() is emulated with pmiPutValueHandle(), using
    a handle-to-type registry populated when handles are created;
  - __pmZoneinfo() is not exported, so pmimport.sadc.zoneinfo falls back
    to the timezone recorded in the sa header;
  - pmiWrite() is called with microsecond resolution.

pcp_write_uptime() no longer depends on HAVE_PMI_APPEND, so
sadf -O pcparchive keeps writing kernel.all.uptime and the derived
proc.psinfo.age/proc.hog.cpu metrics on PCP 6.2.

Also fix the IRQ handle wiring in pcp_def_irq_metrics(): slot numbers
must follow the item_list index (leaving a hole where "sum" is) to match
pcp_slot_for_item() in the write path; instance IDs stay dense.

Tests: PCP write tests are gated on HAVE_PMI_APPEND; 05616 writes
tests/pcpar-sadc for the read-only tests and 05628 removes it, instead
of leaving a PCP archive next to the native tests/sa18 where sar would
auto-select it.  Fix 05627, which checked a file that was never
created.  Add --from-code=UTF-8 to the xgettext invocation so the
UTF-8 comments in the PCP sources no longer abort the pot rule.

Signed-off-by: Nathan Scott <[email protected]>
The pot file was stale: it predated the PCP archive read/write changes,
which added a number of new translatable strings.  Regenerated with
xgettext, now using --from-code=UTF-8.

Signed-off-by: Nathan Scott <[email protected]>
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.

Ability to record performance data from servers/applications pidstat: why no binary output option? [RFE] include pidstat data in sa data files [RFE] Collect /proc/net/netstat [RFE] collect /proc/buddyinfo

2 participants