Skip to content

Commit

Permalink
sadf: PCP: Add support for A_SERIAL activity
Browse files Browse the repository at this point in the history
Add metrics displayed by "sar -y" (serial lines statistics) to PCP
archive.

Signed-off-by: Sebastien GODARD <[email protected]>
  • Loading branch information
sysstat committed Mar 24, 2019
1 parent 1c711c1 commit 00cf117
Show file tree
Hide file tree
Showing 6 changed files with 140 additions and 0 deletions.
1 change: 1 addition & 0 deletions activity.c
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,7 @@ struct activity serial_act = {
.f_json_print = json_print_serial_stats,
.f_svg_print = NULL,
.f_raw_print = raw_print_serial_stats,
.f_pcp_print = pcp_print_serial_stats,
.f_count_new = NULL,
.item_list = NULL,
.desc = "TTY devices statistics",
Expand Down
51 changes: 51 additions & 0 deletions pcp_def_metrics.c
Original file line number Diff line number Diff line change
Expand Up @@ -547,3 +547,54 @@ void pcp_def_net_dev_metrics(struct activity *a)
}
#endif /* HAVE_PCP */
}

/*
***************************************************************************
* Define PCP metrics for serial lines statistics.
*
* IN:
* @a Activity structure with statistics.
***************************************************************************
*/
void pcp_def_serial_metrics(struct activity *a)
{
#ifdef HAVE_PCP
int i;
pmInDom indom;
char buf[64];

/* Create domain */
indom = pmInDom_build(0, PM_INDOM_SERIAL);

/* Create metrics */
pmiAddMetric("serial.in.interrupts",
PM_IN_NULL, PM_TYPE_FLOAT, indom, PM_SEM_INSTANT,
pmiUnits(0, -1, 1, 0, PM_TIME_SEC, PM_COUNT_ONE));

pmiAddMetric("serial.out.interrupts",
PM_IN_NULL, PM_TYPE_FLOAT, indom, PM_SEM_INSTANT,
pmiUnits(0, -1, 1, 0, PM_TIME_SEC, PM_COUNT_ONE));

pmiAddMetric("serial.frame",
PM_IN_NULL, PM_TYPE_FLOAT, indom, PM_SEM_INSTANT,
pmiUnits(0, -1, 1, 0, PM_TIME_SEC, PM_COUNT_ONE));

pmiAddMetric("serial.parity",
PM_IN_NULL, PM_TYPE_FLOAT, indom, PM_SEM_INSTANT,
pmiUnits(0, -1, 1, 0, PM_TIME_SEC, PM_COUNT_ONE));

pmiAddMetric("serial.breaks",
PM_IN_NULL, PM_TYPE_FLOAT, indom, PM_SEM_INSTANT,
pmiUnits(0, -1, 1, 0, PM_TIME_SEC, PM_COUNT_ONE));

pmiAddMetric("serial.overrun",
PM_IN_NULL, PM_TYPE_FLOAT, indom, PM_SEM_INSTANT,
pmiUnits(0, -1, 1, 0, PM_TIME_SEC, PM_COUNT_ONE));

for (i = 0; i < a->nr_ini; i++) {
/* Create instances */
sprintf(buf, "serial%d", i);
pmiAddInstance(indom, buf, i);
}
#endif /* HAVE_PCP */
}
2 changes: 2 additions & 0 deletions pcp_def_metrics.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ void pcp_def_io_metrics(void);
void pcp_def_memory_metrics(struct activity *);
void pcp_def_ktables_metrics(void);
void pcp_def_queue_metrics(void);
void pcp_def_serial_metrics(struct activity *);
void pcp_def_net_dev_metrics(struct activity *);

/* Define domains number */
#define PM_INDOM_CPU 0
#define PM_INDOM_QUEUE 1
#define PM_INDOM_NET_DEV 2
#define PM_INDOM_SERIAL 3


#endif /* _PCP_DEF_METRICS_H */
80 changes: 80 additions & 0 deletions pcp_stats.c
Original file line number Diff line number Diff line change
Expand Up @@ -712,3 +712,83 @@ __print_funct_t pcp_print_net_edev_stats(struct activity *a, int curr, unsigned
}
#endif /* HAVE_PCP */
}

/*
***************************************************************************
* Display serial lines statistics in PCP format.
*
* IN:
* @a Activity structure with statistics.
* @curr Index in array for current sample statistics.
* @itv Interval of time in 1/100th of a second.
* @record_hdr Record header for current sample.
***************************************************************************
*/
__print_funct_t pcp_print_serial_stats(struct activity *a, int curr, unsigned long long itv,
struct record_header *record_hdr)
{
#ifdef HAVE_PCP
int i, j, j0, found;
char buf[64], serialno[64];
struct stats_serial *ssc, *ssp;

for (i = 0; i < a->nr[curr]; i++) {

found = FALSE;

if (a->nr[!curr] > 0) {
ssc = (struct stats_serial *) ((char *) a->buf[curr] + i * a->msize);

/* Look for corresponding serial line in previous iteration */
j = i;

if (j >= a->nr[!curr]) {
j = a->nr[!curr] - 1;
}

j0 = j;

do {
ssp = (struct stats_serial *) ((char *) a->buf[!curr] + j * a->msize);
if (ssc->line == ssp->line) {
found = TRUE;
break;
}
if (++j >= a->nr[!curr]) {
j = 0;
}
}
while (j != j0);
}

if (!found)
continue;

sprintf(serialno, "serial%d", ssc->line);

snprintf(buf, sizeof(buf), "%f",
S_VALUE(ssp->rx, ssc->rx, itv));
pmiPutValue("serial.in.interrupts", serialno, buf);

snprintf(buf, sizeof(buf), "%f",
S_VALUE(ssp->tx, ssc->tx, itv));
pmiPutValue("serial.out.interrupts", serialno, buf);

snprintf(buf, sizeof(buf), "%f",
S_VALUE(ssp->frame, ssc->frame, itv));
pmiPutValue("serial.frame", serialno, buf);

snprintf(buf, sizeof(buf), "%f",
S_VALUE(ssp->parity, ssc->parity, itv));
pmiPutValue("serial.parity", serialno, buf);

snprintf(buf, sizeof(buf), "%f",
S_VALUE(ssp->brk, ssc->brk, itv));
pmiPutValue("serial.breaks", serialno, buf);

snprintf(buf, sizeof(buf), "%f",
S_VALUE(ssp->overrun, ssc->overrun, itv));
pmiPutValue("serial.overrun", serialno, buf);
}
#endif /* HAVE_PCP */
}
2 changes: 2 additions & 0 deletions pcp_stats.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ __print_funct_t pcp_print_ktables_stats
(struct activity *, int, unsigned long long, struct record_header *);
__print_funct_t pcp_print_queue_stats
(struct activity *, int, unsigned long long, struct record_header *);
__print_funct_t pcp_print_serial_stats
(struct activity *, int, unsigned long long, struct record_header *);
__print_funct_t pcp_print_net_dev_stats
(struct activity *, int, unsigned long long, struct record_header *);
__print_funct_t pcp_print_net_edev_stats
Expand Down
4 changes: 4 additions & 0 deletions sadf_misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,10 @@ __printf_funct_t print_pcp_statistics(int *tab, int action, struct activity *act
pcp_def_queue_metrics();
break;

case A_SERIAL:
pcp_def_serial_metrics(act[p]);
break;

case A_NET_DEV:
case A_NET_EDEV:
pcp_def_net_dev_metrics(act[p]);
Expand Down

0 comments on commit 00cf117

Please sign in to comment.