PMWEBTIMERREGISTER(3)
PMWEBTIMERREGISTER π bestie edition
okay so this is a page from the PCP library manual, section 3 (that's the "library functions" shelf of the man-page library, iykyk), and it's about three lil besties that work together: pmWebTimerRegister, pmWebTimerRelease and pmWebTimerSetMetricRegistry β aka thread-safe timer list management. slay. β¨
πΈ NAME πΈ
pmWebTimerRegister, pmWebTimerRelease, pmWebTimerSetMetricRegistry β thread-safe timer list management π°οΈπ
π C SYNOPSIS π
like, include the header first, obviously:
#include <pcp/pmwebapi.h>
typedef void (*pmWebTimerCallBack)(void *data);
int pmWebTimerRegister(pmWebTimerCallBack callback, void *data);
int pmWebTimerRelease(int seq);
int pmWebTimerSetMetricRegistry(struct mmv_registry *registry);
cc ... -lpcp_web
and don't forget to link the library bestie, cc ... -lpcp_web π€
π DESCRIPTION π
so pmWebTimerRegister and its lil friend group give you a convenient, thread-safe API for managing a whole list of timer-driven callbacks. no cap. π§
the way it works: on the first call to either pmWebTimerRegister or pmWebTimerSetMetricRegistry, an internal timer gets set up and initialized to fire every 1.0 seconds. literally. β°
and every single time that timer fires, all currently registered callback functions get called serially β one after the other, no cutting the line β each one handed the opaque data pointer that was supplied back when that specific function was registered. the pmWebTimerCallBack typedef is right there giving you a suitable callback function prototype, so use it. π«Ά
β οΈ real talk: all registered callback functions should be non-blocking and should execute quickly and synchronously. don't be the one holding up the group chat. π
typical callback functions include:
- refreshing instrumentation π
- calculating and updating performance metric values π
- periodic garbage collection ποΈ
- and honestly, any other local function that requires regular execution β¨
π¦ the metric registry one π¦
pmWebTimerSetMetricRegistry is the convenient way for an app to pass in a pointer to a libpcp_mmv(3) registry that the calling application has suitably initialized already. (yes, you initialize it. it's not doing it for you. main character responsibilities. π)
that registry then gets used to dynamically create six server resource metrics, and here they are, exactly:
NAME.mem.dataszNAME.mem.maxrssNAME.cpu.totalNAME.cpu.sysNAME.cpu.userNAME.pid
where NAME is the root PCP PMNS(5) name that got set up by the calling application. π
these metrics should be reasonably self explanatory ngl β they provide resource usage metrics from the calling application / server, and under the hood they use getrusage(2), times(2) and getpid(2). iconic trio fr fr. π
π RETURN VALUE π
pmWebTimerRegister returns a positive integer handle β keep it safe bestie, you'll need it later β which may subsequently be used in a call to pmWebTimerRelease to remove a timer from the internal timer list. ποΈ
when a timer gets removed with a call to pmWebTimerRelease, the internal data structures are freed. π§Ή
π BUT β and this is the part everyone forgets β the caller is responsible for freeing the associated data, since it may or may not be dynamically allocated. so like, we can't know. that's on you. π
π DIAGNOSTICS π
on failure, a negative PMAPI error code is returned in all cases. every single one. no exceptions. π
π SEE ALSO π
go read those next, you're doing amazing. π«Άβ¨
Performance Co-Pilot Β· PCP Β· PMWEBTIMERREGISTER(3) β that's the whole vibe check, thanks for coming to my TED talk, ily, now go free your data pointer πππ¦
π¦ where this page comes from
- arch rolling: pcp 7.2.2-2 Β· GPL-2.0-or-later AND LGPL-2.1-or-later AND CC-BY-3.0
- centos-stream 10: pcp-doc 7.1.5-6.el10 Β· GPL-2.0-or-later AND CC-BY-3.0
- fedora 43: pcp-doc 7.0.1-1.fc43 Β· GPL-2.0-or-later AND CC-BY-3.0
- fedora 43: pcp-doc 7.2.1-1.fc43
- fedora 43: pcp-doc 7.2.2-1.fc43
- fedora 43: pcp-doc 7.2.2-2.fc43 Β· GPL-2.0-or-later AND CC-BY-3.0
- fedora 44: pcp-doc 7.1.0-6.fc44 Β· GPL-2.0-or-later AND CC-BY-3.0
- fedora 44: pcp-doc 7.2.1-1.fc44
- fedora 44: pcp-doc 7.2.2-1.fc44
- fedora 44: pcp-doc 7.2.2-2.fc44 Β· GPL-2.0-or-later AND CC-BY-3.0
- ubuntu resolute: libpcp4-dev 7.1.1-1
- ubuntu stonking: libpcp4-dev 7.2.1-2build1
- Copyright (c) 2021 Red Hat
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms