'\"macro stdmacro
.\"
.\" Copyright (c) 2021 Red Hat.
.\"
.\" This program is free software; you can redistribute it and/or modify it
.\" under the terms of the GNU General Public License as published by the
.\" Free Software Foundation; either version 2 of the License, or (at your
.\" option) any later version.
.\"
.\" This program is distributed in the hope that it will be useful, but
.\" WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
.\" or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
.\" for more details.
.\"
.\"
.TH PMWEBTIMERREGISTER 3 "PCP" "Performance Co-Pilot"
.SH NAME
\f3pmWebTimerRegister\f1,
\f3pmWebTimerRelease\f1,
\f3pmWebTimerSetMetricRegistry\f1 \- thread-safe timer list management
.SH "C SYNOPSIS"
.ft 3
#include <pcp/pmwebapi.h>
.sp
.ad l
.hy 0
.in +8n
.ti -8n
typedef void (*pmWebTimerCallBack)(void *\fIdata\fP);
.ti -8n
int pmWebTimerRegister(pmWebTimerCallBack \fIcallback\fP, void *\fIdata\fP);
.sp
.ti -8n
int pmWebTimerRelease(int \fIseq\fP);
.br
.ti -8n
int pmWebTimerSetMetricRegistry(struct mmv_registry *\fIregistry\fP);
.in
.hy
.ad
cc ... \-lpcp_web
.ft 1
.SH DESCRIPTION
The
.B pmWebTimerRegister
and related API functions provide a convenient thread-safe API for
applications to manage a list of timer driven callbacks.
On the first call to
.B pmWebTimerRegister
or
.BR pmWebTimerSetMetricRegistry ,
an internal timer is set up and initialized to fire every 1.0 seconds.
Each time the timer fires, all currently registered \fIcallback\fP functions
will be called serially with the opaque \fIdata\fP pointer that was supplied
when each function was registered.
The \fIpmWebTimerCallBack\fP typedef provides a suitable callback function prototype.
.PP
All registered \fIcallback\fP functions should be non-blocking
and execute quickly and synchronously.
Typical \fIcallback\fP functions include refreshing instrumentation,
calculating and updating performance metric values, periodic garbage
collection and any other local function that requires regular execution.
.PP
The
.B pmWebTimerSetMetricRegistry
function provides a convenient way for an application to pass in a pointer to an
.BR libpcp_mmv (3)
\fIregistry\fP that has been suitably initialized by the calling application.
This \fIregistry\fP will be used to dynamically create six server resource metrics named
\fINAME\fP\fB.mem.datasz\fP, \fINAME\fP\fB.mem.maxrss\fP, \fINAME\fP\fB.cpu.total\fP,
\fINAME\fP\fB.cpu.sys\fP, \fINAME\fP\fB.cpu.user\fP and \fINAME\fP\fB.pid\fP,
where
.I NAME
is the root PCP
.BR PMNS(5)
name set up by the calling application.
These metrics should be reasonably self explanatory; they provide resource usage metrics
from the calling application / server and use
.BR getrusage (2),
.BR times (2)
and
.BR getpid(2).
.SH RETURN VALUE
The
.B pmWebTimerRegister
function returns a positive integer handle that may be subsequently used
in a call to
.B pmWebTimerRelease
to remove a timer from the internal timer list.
When a timer is removed with a call to
.BR pmWebTimerRelease ,
the internal data structures are freed.
The caller however, is responsible for freeing the associated
.B data
(since it may or may not be dynamically allocated).
.SH DIAGNOSTICS
On failure a negative PMAPI error code is returned in all cases.
.SH SEE ALSO
.BR pmproxy (1),
.BR mmv_stats_registry (3),
.BR PMAPI (3)
and
.BR PMWEBAPI (3).