
* per-thread CPU usage (only those threads where the load is over 0.5%, if the sum of threads below that threshold exceeds 0.5%, it prints an aggregate for those threads); * also report RSS; * network load (only on request, as percentage of specified network bandwidth and actual bytes in/out, with the output suppressed if it is 0%); * publish CPU usage so a ddsperf instance can display CPU loads for its peers; * handle SIGXFSZ (file size exceeded) by displaying one last line of statistics before killing itself; this simply a debugging tool to make it easier to get a trace covering a high sample-rate start-up issue; * default topic changed to "KS" because that allows all the options to be used, this has a negative impact on performance (both latency and small-sample throughput) but it should be less surprising to users; * specifying a size is now done by appending "size N" (where N is the size in bytes) after a "ping" or "pub" command, rather than it having to set it via a command-line option; Note that some of this is platform-dependent -- SIGXFSZ is currently only on Linux and macOS, and CPU and network load reporting is currently only on Linux, macOS and Windows. Signed-off-by: Erik Boasson <eb@ilities.com>
116 lines
2.8 KiB
C
116 lines
2.8 KiB
C
/*
|
|
* Copyright(c) 2019 ADLINK Technology Limited and others
|
|
*
|
|
* This program and the accompanying materials are made available under the
|
|
* terms of the Eclipse Public License v. 2.0 which is available at
|
|
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
|
|
* v. 1.0 which is available at
|
|
* http://www.eclipse.org/org/documents/edl-v10.php.
|
|
*
|
|
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
|
|
*/
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <stdbool.h>
|
|
|
|
#include "dds/dds.h"
|
|
|
|
#include "dds/ddsrt/heap.h"
|
|
#include "dds/ddsrt/string.h"
|
|
#include "dds/ddsrt/netstat.h"
|
|
|
|
#include "netload.h"
|
|
|
|
#if DDSRT_HAVE_NETSTAT
|
|
|
|
struct record_netload_state {
|
|
struct ddsrt_netstat_control *ctrl;
|
|
char *name;
|
|
double bw;
|
|
bool errored;
|
|
bool data_valid;
|
|
dds_time_t tprev;
|
|
uint64_t ibytes;
|
|
uint64_t obytes;
|
|
};
|
|
|
|
void record_netload (struct record_netload_state *st, const char *prefix, dds_time_t tnow)
|
|
{
|
|
if (st && !st->errored)
|
|
{
|
|
struct ddsrt_netstat x;
|
|
dds_return_t ret = ddsrt_netstat_get (st->ctrl, &x);
|
|
st->errored = (ret == DDS_RETCODE_ERROR);
|
|
if (ret == DDS_RETCODE_OK)
|
|
{
|
|
if (st->data_valid)
|
|
{
|
|
/* interface speeds are in bits/s, so convert bytes to bits */
|
|
const double dx = 8 * (double) (x.obytes - st->obytes);
|
|
const double dr = 8 * (double) (x.ibytes - st->ibytes);
|
|
const double dt = (double) (tnow - st->tprev) / 1e9;
|
|
const double dxpct = 100.0 * dx / dt / st->bw;
|
|
const double drpct = 100.0 * dr / dt / st->bw;
|
|
if (dxpct >= 0.5 || drpct >= 0.5)
|
|
{
|
|
printf ("%s %s: xmit %.0f%% recv %.0f%% [%"PRIu64" %"PRIu64"]\n",
|
|
prefix, st->name, dxpct, drpct, x.obytes, x.ibytes);
|
|
}
|
|
}
|
|
st->obytes = x.obytes;
|
|
st->ibytes = x.ibytes;
|
|
st->tprev = tnow;
|
|
st->data_valid = true;
|
|
}
|
|
}
|
|
}
|
|
|
|
struct record_netload_state *record_netload_new (const char *dev, double bw)
|
|
{
|
|
struct record_netload_state *st = ddsrt_malloc (sizeof (*st));
|
|
if (ddsrt_netstat_new (&st->ctrl, dev) != DDS_RETCODE_OK)
|
|
{
|
|
ddsrt_free (st);
|
|
return NULL;
|
|
}
|
|
st->name = ddsrt_strdup (dev);
|
|
st->bw = bw;
|
|
st->data_valid = false;
|
|
st->errored = false;
|
|
record_netload (st, NULL, dds_time ());
|
|
return st;
|
|
}
|
|
|
|
void record_netload_free (struct record_netload_state *st)
|
|
{
|
|
if (st)
|
|
{
|
|
ddsrt_netstat_free (st->ctrl);
|
|
ddsrt_free (st->name);
|
|
ddsrt_free (st);
|
|
}
|
|
}
|
|
|
|
#else
|
|
|
|
void record_netload (struct record_netload_state *st, const char *prefix, dds_time_t tnow)
|
|
{
|
|
(void) st;
|
|
(void) prefix;
|
|
(void ) tnow;
|
|
}
|
|
|
|
struct record_netload_state *record_netload_new (const char *dev, double bw)
|
|
{
|
|
(void) dev;
|
|
(void) bw;
|
|
return NULL;
|
|
}
|
|
|
|
void record_netload_free (struct record_netload_state *st)
|
|
{
|
|
(void) st;
|
|
}
|
|
|
|
#endif
|