2005-02-16 14:16:40 +00:00
|
|
|
/* stats_tree.c
|
2006-05-28 19:49:07 +00:00
|
|
|
* API for a counter tree for Wireshark
|
2005-02-16 14:16:40 +00:00
|
|
|
* 2004, Luis E. G. Ontanon
|
|
|
|
*
|
2006-05-21 05:12:17 +00:00
|
|
|
* Wireshark - Network traffic analyzer
|
|
|
|
* By Gerald Combs <gerald@wireshark.org>
|
2005-02-16 14:16:40 +00:00
|
|
|
* Copyright 1998 Gerald Combs
|
2011-02-18 22:43:48 +00:00
|
|
|
*
|
2018-02-08 16:59:17 +00:00
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later
|
2005-02-16 14:16:40 +00:00
|
|
|
*/
|
|
|
|
|
2013-11-29 22:47:59 +00:00
|
|
|
/* stats_tree modifications by Deon van der Westhuysen, November 2013
|
|
|
|
* support for
|
|
|
|
* - sorting by column,
|
|
|
|
* - calculation of average values
|
|
|
|
* - calculation of burst rate
|
|
|
|
* - export to text, CSV or XML file
|
|
|
|
*/
|
|
|
|
|
2005-02-16 14:16:40 +00:00
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <glib.h>
|
2013-11-10 15:59:37 +00:00
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2005-02-16 14:16:40 +00:00
|
|
|
#include <epan/stats_tree_priv.h>
|
2013-11-29 22:47:59 +00:00
|
|
|
#include <epan/prefs.h>
|
|
|
|
#include <math.h>
|
2005-02-25 03:56:12 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
2013-12-07 19:46:05 +00:00
|
|
|
#include "strutil.h"
|
2005-08-20 16:19:22 +00:00
|
|
|
#include "stats_tree.h"
|
2021-06-18 18:21:42 +00:00
|
|
|
#include <wsutil/ws_assert.h>
|
2005-08-20 16:19:22 +00:00
|
|
|
|
2013-11-29 22:47:59 +00:00
|
|
|
enum _stat_tree_columns {
|
2014-10-06 18:03:47 +00:00
|
|
|
COL_NAME,
|
|
|
|
COL_COUNT,
|
|
|
|
COL_AVERAGE,
|
|
|
|
COL_MIN,
|
|
|
|
COL_MAX,
|
|
|
|
COL_RATE,
|
|
|
|
COL_PERCENT,
|
|
|
|
COL_BURSTRATE,
|
|
|
|
COL_BURSTTIME,
|
|
|
|
N_COLUMNS
|
2013-11-29 22:47:59 +00:00
|
|
|
};
|
2005-02-16 14:16:40 +00:00
|
|
|
|
|
|
|
/* used to contain the registered stat trees */
|
2008-07-11 21:13:39 +00:00
|
|
|
static GHashTable *registry = NULL;
|
2005-02-16 14:16:40 +00:00
|
|
|
|
|
|
|
/* a text representation of a node
|
|
|
|
if buffer is NULL returns a newly allocated string */
|
2008-07-11 21:13:39 +00:00
|
|
|
extern gchar*
|
|
|
|
stats_tree_node_to_str(const stat_node *node, gchar *buffer, guint len)
|
|
|
|
{
|
2014-10-06 18:03:47 +00:00
|
|
|
if (buffer) {
|
2021-12-16 18:06:18 +00:00
|
|
|
snprintf(buffer,len,"%s: %i",node->name, node->counter);
|
2014-10-06 18:03:47 +00:00
|
|
|
return buffer;
|
|
|
|
} else {
|
2021-12-16 18:06:18 +00:00
|
|
|
return ws_strdup_printf("%s: %i",node->name, node->counter);
|
2014-10-06 18:03:47 +00:00
|
|
|
}
|
2005-02-16 14:16:40 +00:00
|
|
|
}
|
|
|
|
|
2008-07-11 21:13:39 +00:00
|
|
|
extern guint
|
|
|
|
stats_tree_branch_max_namelen(const stat_node *node, guint indent)
|
|
|
|
{
|
2014-10-06 18:03:47 +00:00
|
|
|
stat_node *child;
|
|
|
|
guint maxlen = 0;
|
|
|
|
guint len;
|
|
|
|
|
|
|
|
indent = indent > INDENT_MAX ? INDENT_MAX : indent;
|
|
|
|
|
|
|
|
if (node->children) {
|
|
|
|
for (child = node->children; child; child = child->next ) {
|
|
|
|
len = stats_tree_branch_max_namelen(child,indent+1);
|
|
|
|
maxlen = len > maxlen ? len : maxlen;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (node->st_flags&ST_FLG_ROOTCHILD) {
|
2017-09-29 18:48:35 +00:00
|
|
|
gchar *display_name = stats_tree_get_displayname(node->name);
|
2014-10-06 18:03:47 +00:00
|
|
|
len = (guint) strlen(display_name) + indent;
|
|
|
|
g_free(display_name);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
len = (guint) strlen(node->name) + indent;
|
|
|
|
}
|
|
|
|
maxlen = len > maxlen ? len : maxlen;
|
|
|
|
|
|
|
|
return maxlen;
|
2005-02-25 03:56:12 +00:00
|
|
|
}
|
|
|
|
|
2005-02-16 14:16:40 +00:00
|
|
|
/* frees the resources allocated by a stat_tree node */
|
2008-07-11 21:13:39 +00:00
|
|
|
static void
|
|
|
|
free_stat_node(stat_node *node)
|
|
|
|
{
|
2014-10-06 18:03:47 +00:00
|
|
|
stat_node *child;
|
|
|
|
stat_node *next;
|
|
|
|
burst_bucket *bucket;
|
|
|
|
|
|
|
|
if (node->children) {
|
|
|
|
for (child = node->children; child; child = next ) {
|
|
|
|
/* child->next will be gone after free_stat_node, so cache it here */
|
|
|
|
next = child->next;
|
|
|
|
free_stat_node(child);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (node->hash) g_hash_table_destroy(node->hash);
|
|
|
|
|
|
|
|
while (node->bh) {
|
|
|
|
bucket = node->bh;
|
|
|
|
node->bh = bucket->next;
|
|
|
|
g_free(bucket);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free(node->rng);
|
|
|
|
g_free(node->name);
|
|
|
|
g_free(node);
|
2005-02-16 14:16:40 +00:00
|
|
|
}
|
|
|
|
|
2005-03-20 00:19:15 +00:00
|
|
|
/* destroys the whole tree instance */
|
2008-07-11 21:13:39 +00:00
|
|
|
extern void
|
|
|
|
stats_tree_free(stats_tree *st)
|
|
|
|
{
|
2014-10-06 18:03:47 +00:00
|
|
|
stat_node *child;
|
|
|
|
stat_node *next;
|
2011-02-18 22:43:48 +00:00
|
|
|
|
2015-08-20 15:56:04 +00:00
|
|
|
if (!st) return;
|
|
|
|
|
2014-10-06 18:03:47 +00:00
|
|
|
g_free(st->filter);
|
|
|
|
g_hash_table_destroy(st->names);
|
|
|
|
g_ptr_array_free(st->parents,TRUE);
|
|
|
|
g_free(st->display_name);
|
2011-02-18 22:43:48 +00:00
|
|
|
|
2014-10-06 18:03:47 +00:00
|
|
|
for (child = st->root.children; child; child = next ) {
|
|
|
|
/* child->next will be gone after free_stat_node, so cache it here */
|
|
|
|
next = child->next;
|
|
|
|
free_stat_node(child);
|
|
|
|
}
|
2011-02-18 22:43:48 +00:00
|
|
|
|
2014-10-06 18:03:47 +00:00
|
|
|
if (st->cfg->free_tree_pr)
|
|
|
|
st->cfg->free_tree_pr(st);
|
2011-02-18 22:43:48 +00:00
|
|
|
|
2014-10-06 18:03:47 +00:00
|
|
|
if (st->cfg->cleanup)
|
|
|
|
st->cfg->cleanup(st);
|
2011-02-18 22:43:48 +00:00
|
|
|
|
2014-10-06 18:03:47 +00:00
|
|
|
g_free(st);
|
2005-02-16 14:16:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* reset a node to its original state */
|
2008-07-11 21:13:39 +00:00
|
|
|
static void
|
|
|
|
reset_stat_node(stat_node *node)
|
|
|
|
{
|
2014-10-06 18:03:47 +00:00
|
|
|
stat_node *child;
|
|
|
|
burst_bucket *bucket;
|
|
|
|
|
|
|
|
node->counter = 0;
|
2018-12-27 19:47:02 +00:00
|
|
|
switch (node->datatype)
|
|
|
|
{
|
|
|
|
case STAT_DT_INT:
|
|
|
|
node->total.int_total = 0;
|
|
|
|
node->minvalue.int_min = G_MAXINT;
|
|
|
|
node->maxvalue.int_max = G_MININT;
|
|
|
|
break;
|
|
|
|
case STAT_DT_FLOAT:
|
|
|
|
node->total.float_total = 0;
|
|
|
|
node->minvalue.float_min = G_MAXFLOAT;
|
|
|
|
node->maxvalue.float_max = G_MINFLOAT;
|
|
|
|
break;
|
|
|
|
}
|
2014-10-06 18:03:47 +00:00
|
|
|
node->st_flags = 0;
|
|
|
|
|
|
|
|
while (node->bh) {
|
|
|
|
bucket = node->bh;
|
|
|
|
node->bh = bucket->next;
|
|
|
|
g_free(bucket);
|
|
|
|
}
|
2020-12-21 02:30:28 +00:00
|
|
|
node->bh = g_new0(burst_bucket, 1);
|
2014-10-06 18:03:47 +00:00
|
|
|
node->bt = node->bh;
|
|
|
|
node->bcount = 0;
|
|
|
|
node->max_burst = 0;
|
|
|
|
node->burst_time = -1.0;
|
|
|
|
|
|
|
|
if (node->children) {
|
|
|
|
for (child = node->children; child; child = child->next )
|
|
|
|
reset_stat_node(child);
|
|
|
|
}
|
2005-02-16 14:16:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* reset the whole stats_tree */
|
2008-07-11 21:13:39 +00:00
|
|
|
extern void
|
|
|
|
stats_tree_reset(void *p)
|
|
|
|
{
|
2014-10-06 18:03:47 +00:00
|
|
|
stats_tree *st = (stats_tree *)p;
|
2011-02-18 22:43:48 +00:00
|
|
|
|
2014-10-06 18:03:47 +00:00
|
|
|
st->start = -1.0;
|
|
|
|
st->elapsed = 0.0;
|
|
|
|
st->now = - 1.0;
|
2011-02-18 22:43:48 +00:00
|
|
|
|
2014-10-06 18:03:47 +00:00
|
|
|
reset_stat_node(&st->root);
|
2005-02-16 14:16:40 +00:00
|
|
|
}
|
|
|
|
|
2008-07-11 21:13:39 +00:00
|
|
|
extern void
|
|
|
|
stats_tree_reinit(void *p)
|
|
|
|
{
|
2014-10-06 18:03:47 +00:00
|
|
|
stats_tree *st = (stats_tree *)p;
|
|
|
|
stat_node *child;
|
|
|
|
stat_node *next;
|
|
|
|
|
|
|
|
for (child = st->root.children; child; child = next) {
|
|
|
|
/* child->next will be gone after free_stat_node, so cache it here */
|
|
|
|
next = child->next;
|
|
|
|
free_stat_node(child);
|
|
|
|
}
|
|
|
|
|
|
|
|
st->root.children = NULL;
|
|
|
|
st->root.counter = 0;
|
2018-12-27 19:47:02 +00:00
|
|
|
switch (st->root.datatype)
|
|
|
|
{
|
|
|
|
case STAT_DT_INT:
|
|
|
|
st->root.total.int_total = 0;
|
|
|
|
st->root.minvalue.int_min = G_MAXINT;
|
|
|
|
st->root.maxvalue.int_max = G_MININT;
|
|
|
|
break;
|
|
|
|
case STAT_DT_FLOAT:
|
|
|
|
st->root.total.float_total = 0;
|
|
|
|
st->root.minvalue.float_min = G_MAXFLOAT;
|
|
|
|
st->root.maxvalue.float_max = G_MINFLOAT;
|
|
|
|
break;
|
|
|
|
}
|
2014-10-06 18:03:47 +00:00
|
|
|
st->root.st_flags = 0;
|
|
|
|
|
2020-12-21 02:30:28 +00:00
|
|
|
st->root.bh = g_new0(burst_bucket, 1);
|
2014-10-06 18:03:47 +00:00
|
|
|
st->root.bt = st->root.bh;
|
|
|
|
st->root.bcount = 0;
|
|
|
|
st->root.max_burst = 0;
|
|
|
|
st->root.burst_time = -1.0;
|
|
|
|
|
|
|
|
/* No more stat_nodes left in tree - clean out hash, array */
|
|
|
|
g_hash_table_remove_all(st->names);
|
|
|
|
if (st->parents->len>1) {
|
|
|
|
g_ptr_array_remove_range(st->parents, 1, st->parents->len-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Do not update st_flags for the tree (sorting) - leave as was */
|
|
|
|
st->num_columns = N_COLUMNS;
|
|
|
|
g_free(st->display_name);
|
2017-09-29 18:48:35 +00:00
|
|
|
st->display_name = stats_tree_get_displayname(st->cfg->name);
|
2014-10-06 18:03:47 +00:00
|
|
|
|
|
|
|
if (st->cfg->init) {
|
|
|
|
st->cfg->init(st);
|
|
|
|
}
|
2005-02-20 17:43:38 +00:00
|
|
|
}
|
|
|
|
|
2017-02-20 13:32:42 +00:00
|
|
|
static void
|
2017-02-05 22:00:51 +00:00
|
|
|
stats_tree_cfg_free(gpointer p)
|
|
|
|
{
|
|
|
|
stats_tree_cfg* cfg = (stats_tree_cfg*)p;
|
|
|
|
g_free(cfg->tapname);
|
|
|
|
g_free(cfg->abbr);
|
|
|
|
g_free(cfg->name);
|
|
|
|
g_free(cfg);
|
|
|
|
}
|
|
|
|
|
2005-02-16 14:16:40 +00:00
|
|
|
/* register a new stats_tree */
|
2008-07-11 21:13:39 +00:00
|
|
|
extern void
|
2009-02-10 03:54:55 +00:00
|
|
|
stats_tree_register_with_group(const char *tapname, const char *abbr, const char *name,
|
2014-10-06 18:03:47 +00:00
|
|
|
guint flags,
|
|
|
|
stat_tree_packet_cb packet, stat_tree_init_cb init,
|
|
|
|
stat_tree_cleanup_cb cleanup, register_stat_group_t stat_group)
|
2008-07-11 21:13:39 +00:00
|
|
|
{
|
2020-12-22 20:21:37 +00:00
|
|
|
stats_tree_cfg *cfg = g_new0(stats_tree_cfg, 1);
|
2005-02-16 14:16:40 +00:00
|
|
|
|
2014-10-06 18:03:47 +00:00
|
|
|
/* at the very least the abbrev and the packet function should be given */
|
2021-06-18 18:21:42 +00:00
|
|
|
ws_assert( tapname && abbr && packet );
|
2005-02-16 14:16:40 +00:00
|
|
|
|
2014-10-06 18:03:47 +00:00
|
|
|
cfg->tapname = g_strdup(tapname);
|
|
|
|
cfg->abbr = g_strdup(abbr);
|
|
|
|
cfg->name = name ? g_strdup(name) : g_strdup(abbr);
|
|
|
|
cfg->stat_group = stat_group;
|
2011-02-18 22:43:48 +00:00
|
|
|
|
2014-10-06 18:03:47 +00:00
|
|
|
cfg->packet = packet;
|
|
|
|
cfg->init = init;
|
|
|
|
cfg->cleanup = cleanup;
|
2009-06-05 22:42:47 +00:00
|
|
|
|
2014-10-06 18:03:47 +00:00
|
|
|
cfg->flags = flags&~ST_FLG_MASK;
|
|
|
|
cfg->st_flags = flags&ST_FLG_MASK;
|
2011-02-18 22:43:48 +00:00
|
|
|
|
2017-02-05 22:00:51 +00:00
|
|
|
if (!registry) registry = g_hash_table_new_full(g_str_hash,g_str_equal,NULL,stats_tree_cfg_free);
|
2005-03-20 00:19:15 +00:00
|
|
|
|
2014-10-06 18:03:47 +00:00
|
|
|
g_hash_table_insert(registry,cfg->abbr,cfg);
|
2005-03-20 00:19:15 +00:00
|
|
|
}
|
|
|
|
|
2022-04-11 22:23:29 +00:00
|
|
|
/* register a new stats_tree with default group REGISTER_PACKET_STAT_GROUP_UNSORTED */
|
2009-02-10 03:54:55 +00:00
|
|
|
extern void
|
|
|
|
stats_tree_register(const char *tapname, const char *abbr, const char *name,
|
2014-10-06 18:03:47 +00:00
|
|
|
guint flags,
|
|
|
|
stat_tree_packet_cb packet, stat_tree_init_cb init,
|
|
|
|
stat_tree_cleanup_cb cleanup)
|
2009-02-10 03:54:55 +00:00
|
|
|
{
|
2014-10-06 18:03:47 +00:00
|
|
|
stats_tree_register_with_group(tapname, abbr, name,
|
|
|
|
flags,
|
|
|
|
packet, init,
|
2022-04-11 22:23:29 +00:00
|
|
|
cleanup, REGISTER_PACKET_STAT_GROUP_UNSORTED);
|
2009-02-10 03:54:55 +00:00
|
|
|
}
|
|
|
|
|
2022-04-11 22:23:29 +00:00
|
|
|
/* register a new stat_tree with default group REGISTER_PACKET_STAT_GROUP_UNSORTED from a plugin */
|
2012-07-15 16:24:35 +00:00
|
|
|
extern void
|
|
|
|
stats_tree_register_plugin(const char *tapname, const char *abbr, const char *name,
|
2014-10-06 18:03:47 +00:00
|
|
|
guint flags,
|
|
|
|
stat_tree_packet_cb packet, stat_tree_init_cb init,
|
|
|
|
stat_tree_cleanup_cb cleanup)
|
2012-07-15 16:24:35 +00:00
|
|
|
{
|
2014-10-06 18:03:47 +00:00
|
|
|
stats_tree_cfg *cfg;
|
|
|
|
|
|
|
|
stats_tree_register(tapname, abbr, name,
|
|
|
|
flags,
|
|
|
|
packet, init,
|
|
|
|
cleanup);
|
|
|
|
cfg = stats_tree_get_cfg_by_abbr(abbr);
|
|
|
|
cfg->plugin = TRUE;
|
2012-07-15 16:24:35 +00:00
|
|
|
}
|
|
|
|
|
2008-07-11 21:13:39 +00:00
|
|
|
extern stats_tree*
|
2010-03-26 23:40:48 +00:00
|
|
|
stats_tree_new(stats_tree_cfg *cfg, tree_pres *pr, const char *filter)
|
2008-07-11 21:13:39 +00:00
|
|
|
{
|
2020-12-21 02:30:28 +00:00
|
|
|
stats_tree *st = g_new0(stats_tree, 1);
|
2014-10-06 18:03:47 +00:00
|
|
|
|
|
|
|
st->cfg = cfg;
|
|
|
|
st->pr = pr;
|
|
|
|
|
|
|
|
st->names = g_hash_table_new(g_str_hash,g_str_equal);
|
|
|
|
st->parents = g_ptr_array_new();
|
|
|
|
st->filter = g_strdup(filter);
|
|
|
|
|
|
|
|
st->start = -1.0;
|
|
|
|
st->elapsed = 0.0;
|
|
|
|
|
2018-12-27 19:47:02 +00:00
|
|
|
switch (st->root.datatype)
|
|
|
|
{
|
|
|
|
case STAT_DT_INT:
|
|
|
|
st->root.minvalue.int_min = G_MAXINT;
|
|
|
|
st->root.maxvalue.int_max = G_MININT;
|
|
|
|
break;
|
|
|
|
case STAT_DT_FLOAT:
|
|
|
|
st->root.minvalue.float_min = G_MAXFLOAT;
|
|
|
|
st->root.maxvalue.float_max = G_MINFLOAT;
|
|
|
|
break;
|
|
|
|
}
|
2014-10-06 18:03:47 +00:00
|
|
|
|
2020-12-21 02:30:28 +00:00
|
|
|
st->root.bh = g_new0(burst_bucket, 1);
|
2014-10-06 18:03:47 +00:00
|
|
|
st->root.bt = st->root.bh;
|
|
|
|
st->root.burst_time = -1.0;
|
|
|
|
|
|
|
|
st->root.name = stats_tree_get_displayname(cfg->name);
|
|
|
|
st->root.st = st;
|
|
|
|
|
|
|
|
st->st_flags = st->cfg->st_flags;
|
|
|
|
|
|
|
|
if (!(st->st_flags&ST_FLG_SRTCOL_MASK)) {
|
|
|
|
/* No default sort specified - use preferences */
|
|
|
|
st->st_flags |= prefs.st_sort_defcolflag<<ST_FLG_SRTCOL_SHIFT;
|
|
|
|
if (prefs.st_sort_defdescending) {
|
|
|
|
st->st_flags |= ST_FLG_SORT_DESC;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
st->num_columns = N_COLUMNS;
|
2017-09-29 18:48:35 +00:00
|
|
|
st->display_name = stats_tree_get_displayname(st->cfg->name);
|
2014-10-06 18:03:47 +00:00
|
|
|
|
|
|
|
g_ptr_array_add(st->parents,&st->root);
|
|
|
|
|
|
|
|
return st;
|
2011-02-18 22:43:48 +00:00
|
|
|
}
|
2005-02-16 14:16:40 +00:00
|
|
|
|
|
|
|
/* will be the tap packet cb */
|
2019-01-01 03:36:12 +00:00
|
|
|
extern tap_packet_status
|
2022-06-09 15:47:35 +00:00
|
|
|
stats_tree_packet(void *p, packet_info *pinfo, epan_dissect_t *edt, const void *pri, tap_flags_t flags)
|
2008-07-11 21:13:39 +00:00
|
|
|
{
|
2014-10-06 18:03:47 +00:00
|
|
|
stats_tree *st = (stats_tree *)p;
|
2011-02-18 22:43:48 +00:00
|
|
|
|
2014-10-06 18:03:47 +00:00
|
|
|
st->now = nstime_to_msec(&pinfo->rel_ts);
|
|
|
|
if (st->start < 0.0) st->start = st->now;
|
2011-02-18 22:43:48 +00:00
|
|
|
|
2014-10-06 18:03:47 +00:00
|
|
|
st->elapsed = st->now - st->start;
|
2011-02-18 22:43:48 +00:00
|
|
|
|
2014-10-06 18:03:47 +00:00
|
|
|
if (st->cfg->packet)
|
2022-06-09 15:47:35 +00:00
|
|
|
return st->cfg->packet(st,pinfo,edt,pri, flags);
|
2014-10-06 18:03:47 +00:00
|
|
|
else
|
2019-01-01 03:36:12 +00:00
|
|
|
return TAP_PACKET_DONT_REDRAW;
|
2005-02-16 14:16:40 +00:00
|
|
|
}
|
|
|
|
|
2008-07-11 21:13:39 +00:00
|
|
|
extern stats_tree_cfg*
|
2013-11-21 01:28:17 +00:00
|
|
|
stats_tree_get_cfg_by_abbr(const char *abbr)
|
2008-07-11 21:13:39 +00:00
|
|
|
{
|
2015-06-05 20:17:13 +00:00
|
|
|
if (!abbr) return NULL;
|
2014-10-06 18:03:47 +00:00
|
|
|
return (stats_tree_cfg *)g_hash_table_lookup(registry,abbr);
|
2005-02-16 14:16:40 +00:00
|
|
|
}
|
|
|
|
|
2015-08-16 17:41:53 +00:00
|
|
|
static gint
|
|
|
|
compare_stat_menu_item(gconstpointer stat_a, gconstpointer stat_b)
|
|
|
|
{
|
2015-12-28 20:33:17 +00:00
|
|
|
const stats_tree_cfg* stat_cfg_a = (const stats_tree_cfg*)stat_a;
|
|
|
|
const stats_tree_cfg* stat_cfg_b = (const stats_tree_cfg*)stat_b;
|
2015-08-16 17:41:53 +00:00
|
|
|
|
|
|
|
return strcmp(stat_cfg_a->name, stat_cfg_b->name);
|
|
|
|
}
|
|
|
|
|
2012-07-15 16:24:35 +00:00
|
|
|
extern GList*
|
|
|
|
stats_tree_get_cfg_list(void)
|
|
|
|
{
|
2015-08-16 17:41:53 +00:00
|
|
|
GList* registry_list = g_hash_table_get_values(registry);
|
|
|
|
/* Now sort the list so they can show up in the
|
|
|
|
menu alphabetically */
|
|
|
|
return g_list_sort(registry_list, compare_stat_menu_item);
|
|
|
|
|
2012-07-15 16:24:35 +00:00
|
|
|
}
|
2005-02-16 14:16:40 +00:00
|
|
|
|
2005-03-20 00:19:15 +00:00
|
|
|
struct _stats_tree_pres_cbs {
|
2014-10-06 18:03:47 +00:00
|
|
|
void (*setup_node_pr)(stat_node*);
|
|
|
|
void (*free_tree_pr)(stats_tree*);
|
2005-02-16 14:16:40 +00:00
|
|
|
};
|
|
|
|
|
2008-07-11 21:13:39 +00:00
|
|
|
static void
|
|
|
|
setup_tree_presentation(gpointer k _U_, gpointer v, gpointer p)
|
|
|
|
{
|
2014-10-06 18:03:47 +00:00
|
|
|
stats_tree_cfg *cfg = (stats_tree_cfg *)v;
|
|
|
|
struct _stats_tree_pres_cbs *d = (struct _stats_tree_pres_cbs *)p;
|
|
|
|
|
|
|
|
cfg->setup_node_pr = d->setup_node_pr;
|
|
|
|
cfg->free_tree_pr = d->free_tree_pr;
|
2011-02-18 22:43:48 +00:00
|
|
|
|
2005-02-16 14:16:40 +00:00
|
|
|
}
|
|
|
|
|
2008-07-11 21:13:39 +00:00
|
|
|
extern void
|
|
|
|
stats_tree_presentation(void (*registry_iterator)(gpointer,gpointer,gpointer),
|
2014-10-06 18:03:47 +00:00
|
|
|
void (*setup_node_pr)(stat_node*),
|
|
|
|
void (*free_tree_pr)(stats_tree*),
|
|
|
|
void *data)
|
2008-07-11 21:13:39 +00:00
|
|
|
{
|
2014-10-06 18:03:47 +00:00
|
|
|
static struct _stats_tree_pres_cbs d;
|
2011-02-18 22:43:48 +00:00
|
|
|
|
2014-10-06 18:03:47 +00:00
|
|
|
d.setup_node_pr = setup_node_pr;
|
|
|
|
d.free_tree_pr = free_tree_pr;
|
2011-02-18 22:43:48 +00:00
|
|
|
|
2014-10-06 18:03:47 +00:00
|
|
|
if (registry) g_hash_table_foreach(registry,setup_tree_presentation,&d);
|
2011-02-18 22:43:48 +00:00
|
|
|
|
2014-10-06 18:03:47 +00:00
|
|
|
if (registry_iterator && registry)
|
|
|
|
g_hash_table_foreach(registry,registry_iterator,data);
|
2011-02-18 22:43:48 +00:00
|
|
|
|
2005-02-16 14:16:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* creates a stat_tree node
|
|
|
|
* name: the name of the stats_tree node
|
|
|
|
* parent_name: the name of the ALREADY REGISTERED parent
|
2013-02-26 02:19:57 +00:00
|
|
|
* with_hash: whether or not it should keep a hash with its children names
|
2005-02-16 14:16:40 +00:00
|
|
|
* as_named_node: whether or not it has to be registered in the root namespace
|
|
|
|
*/
|
2008-07-11 21:13:39 +00:00
|
|
|
static stat_node*
|
2018-12-27 19:47:02 +00:00
|
|
|
new_stat_node(stats_tree *st, const gchar *name, int parent_id, stat_node_datatype datatype,
|
2014-10-06 18:03:47 +00:00
|
|
|
gboolean with_hash, gboolean as_parent_node)
|
2008-07-11 21:13:39 +00:00
|
|
|
{
|
2007-03-26 06:10:52 +00:00
|
|
|
|
2020-12-21 02:30:28 +00:00
|
|
|
stat_node *node = g_new0(stat_node, 1);
|
2014-10-06 18:03:47 +00:00
|
|
|
stat_node *last_chld = NULL;
|
|
|
|
|
2018-12-27 19:47:02 +00:00
|
|
|
node->datatype = datatype;
|
|
|
|
switch (datatype)
|
|
|
|
{
|
|
|
|
case STAT_DT_INT:
|
|
|
|
node->minvalue.int_min = G_MAXINT;
|
|
|
|
node->maxvalue.int_max = G_MININT;
|
|
|
|
break;
|
|
|
|
case STAT_DT_FLOAT:
|
|
|
|
node->minvalue.float_min = G_MAXFLOAT;
|
|
|
|
node->maxvalue.float_max = G_MINFLOAT;
|
|
|
|
break;
|
|
|
|
}
|
2014-10-06 18:03:47 +00:00
|
|
|
node->st_flags = parent_id?0:ST_FLG_ROOTCHILD;
|
|
|
|
|
2020-12-21 02:30:28 +00:00
|
|
|
node->bh = g_new0(burst_bucket, 1);
|
2014-10-06 18:03:47 +00:00
|
|
|
node->bt = node->bh;
|
|
|
|
node->burst_time = -1.0;
|
|
|
|
|
|
|
|
node->name = g_strdup(name);
|
2019-01-03 16:53:42 +00:00
|
|
|
node->st = st;
|
2014-10-06 18:03:47 +00:00
|
|
|
node->hash = with_hash ? g_hash_table_new(g_str_hash,g_str_equal) : NULL;
|
|
|
|
|
|
|
|
if (as_parent_node) {
|
|
|
|
g_hash_table_insert(st->names,
|
|
|
|
node->name,
|
|
|
|
node);
|
|
|
|
|
|
|
|
g_ptr_array_add(st->parents,node);
|
|
|
|
|
|
|
|
node->id = st->parents->len - 1;
|
|
|
|
} else {
|
|
|
|
node->id = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (parent_id >= 0 && parent_id < (int) st->parents->len ) {
|
|
|
|
node->parent = (stat_node *)g_ptr_array_index(st->parents,parent_id);
|
|
|
|
} else {
|
|
|
|
/* ??? should we set the parent to be root ??? */
|
2021-06-18 18:21:42 +00:00
|
|
|
ws_assert_not_reached();
|
2014-10-06 18:03:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (node->parent->children) {
|
|
|
|
/* insert as last child */
|
|
|
|
|
|
|
|
for (last_chld = node->parent->children;
|
|
|
|
last_chld->next;
|
|
|
|
last_chld = last_chld->next ) ;
|
|
|
|
|
|
|
|
last_chld->next = node;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
/* insert as first child */
|
|
|
|
node->parent->children = node;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(node->parent->hash) {
|
2019-08-27 15:49:53 +00:00
|
|
|
g_hash_table_replace(node->parent->hash,node->name,node);
|
2014-10-06 18:03:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (st->cfg->setup_node_pr) {
|
|
|
|
st->cfg->setup_node_pr(node);
|
|
|
|
} else {
|
|
|
|
node->pr = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return node;
|
2005-02-16 14:16:40 +00:00
|
|
|
}
|
2005-03-20 00:19:15 +00:00
|
|
|
/***/
|
2005-02-16 14:16:40 +00:00
|
|
|
|
2008-07-11 21:13:39 +00:00
|
|
|
extern int
|
2018-12-27 19:47:02 +00:00
|
|
|
stats_tree_create_node(stats_tree *st, const gchar *name, int parent_id, stat_node_datatype datatype, gboolean with_hash)
|
2008-07-11 21:13:39 +00:00
|
|
|
{
|
2018-12-27 19:47:02 +00:00
|
|
|
stat_node *node = new_stat_node(st,name,parent_id,datatype,with_hash,TRUE);
|
2011-02-18 22:43:48 +00:00
|
|
|
|
2014-10-06 18:03:47 +00:00
|
|
|
if (node)
|
|
|
|
return node->id;
|
|
|
|
else
|
|
|
|
return 0;
|
2005-02-16 14:16:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* XXX: should this be a macro? */
|
2008-07-11 21:13:39 +00:00
|
|
|
extern int
|
|
|
|
stats_tree_create_node_by_pname(stats_tree *st, const gchar *name,
|
2018-12-27 19:47:02 +00:00
|
|
|
const gchar *parent_name, stat_node_datatype datatype, gboolean with_children)
|
2008-07-11 21:13:39 +00:00
|
|
|
{
|
2018-12-27 19:47:02 +00:00
|
|
|
return stats_tree_create_node(st,name,stats_tree_parent_id_by_name(st,parent_name),datatype,with_children);
|
2005-02-16 14:16:40 +00:00
|
|
|
}
|
|
|
|
|
2013-11-29 22:47:59 +00:00
|
|
|
/* Internal function to update the burst calculation data - add entry to bucket */
|
|
|
|
static void
|
|
|
|
update_burst_calc(stat_node *node, gint value)
|
|
|
|
{
|
2014-10-06 18:03:47 +00:00
|
|
|
double current_bucket;
|
|
|
|
double burstwin;
|
|
|
|
|
|
|
|
burst_bucket *bn;
|
|
|
|
|
|
|
|
if (!prefs.st_enable_burstinfo) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* NB thebucket list should always contain at least one node - even if it is */
|
|
|
|
/* the dummy created at init time. Head and tail should never be NULL! */
|
2017-09-29 18:48:35 +00:00
|
|
|
current_bucket = floor(node->st->now/prefs.st_burst_resolution);
|
|
|
|
burstwin = prefs.st_burst_windowlen/prefs.st_burst_resolution;
|
2014-10-06 18:03:47 +00:00
|
|
|
if (current_bucket>node->bt->bucket_no) {
|
|
|
|
/* Must add a new bucket at the burst list tail */
|
2020-12-21 02:30:28 +00:00
|
|
|
bn = g_new0(burst_bucket, 1);
|
2014-10-06 18:03:47 +00:00
|
|
|
bn->count = value;
|
|
|
|
bn->bucket_no = current_bucket;
|
|
|
|
bn->start_time = node->st->now;
|
|
|
|
bn->prev = node->bt;
|
|
|
|
node->bt->next = bn;
|
|
|
|
node->bt = bn;
|
|
|
|
/* And add value to the current burst count for node */
|
|
|
|
node->bcount += value;
|
|
|
|
/* Check if bucket list head is now too old and must be removed */
|
|
|
|
while (current_bucket>=(node->bh->bucket_no+burstwin)) {
|
|
|
|
/* off with its head! */
|
|
|
|
bn = node->bh;
|
|
|
|
node->bh = bn->next;
|
|
|
|
node->bh->prev = NULL;
|
|
|
|
node->bcount -= bn->count;
|
|
|
|
g_free(bn);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (current_bucket<node->bh->bucket_no) {
|
|
|
|
/* Packet must be added at head of burst list - check if not too old */
|
|
|
|
if ((current_bucket+burstwin)>node->bt->bucket_no) {
|
|
|
|
/* packet still within the window */
|
2020-12-21 02:30:28 +00:00
|
|
|
bn = g_new0(burst_bucket, 1);
|
2014-10-06 18:03:47 +00:00
|
|
|
bn->count = value;
|
|
|
|
bn->bucket_no = current_bucket;
|
|
|
|
bn->start_time = node->st->now;
|
|
|
|
bn->next = node->bh;
|
|
|
|
node->bh->prev = bn;
|
|
|
|
node->bh = bn;
|
|
|
|
/* And add value to the current burst count for node */
|
|
|
|
node->bcount += value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Somewhere in the middle... */
|
|
|
|
burst_bucket *search = node->bt;
|
|
|
|
while (current_bucket<search->bucket_no) {
|
|
|
|
search = search->prev;
|
|
|
|
}
|
|
|
|
if (current_bucket==search->bucket_no) {
|
|
|
|
/* found existing bucket, increase value */
|
|
|
|
search->count += value;
|
|
|
|
if (search->start_time>node->st->now) {
|
|
|
|
search->start_time = node->st->now;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* must add a new bucket after bn. */
|
2020-12-21 02:30:28 +00:00
|
|
|
bn = g_new0(burst_bucket, 1);
|
2014-10-06 18:03:47 +00:00
|
|
|
bn->count = value;
|
|
|
|
bn->bucket_no = current_bucket;
|
|
|
|
bn->start_time = node->st->now;
|
|
|
|
bn->prev = search;
|
|
|
|
bn->next = search->next;
|
|
|
|
search->next = bn;
|
|
|
|
bn->next->prev = bn;
|
|
|
|
}
|
|
|
|
node->bcount += value;
|
|
|
|
}
|
|
|
|
if (node->bcount>node->max_burst) {
|
|
|
|
/* new record burst */
|
|
|
|
node->max_burst = node->bcount;
|
|
|
|
node->burst_time = node->bh->start_time;
|
|
|
|
}
|
2013-11-29 22:47:59 +00:00
|
|
|
}
|
2005-02-16 14:16:40 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Increases by delta the counter of the node whose name is given
|
|
|
|
* if the node does not exist yet it's created (with counter=1)
|
|
|
|
* using parent_name as parent node.
|
|
|
|
* with_hash=TRUE to indicate that the created node will have a parent
|
|
|
|
*/
|
2018-12-27 19:47:02 +00:00
|
|
|
int
|
|
|
|
stats_tree_manip_node_int(manip_node_mode mode, stats_tree *st, const char *name,
|
2014-10-06 18:03:47 +00:00
|
|
|
int parent_id, gboolean with_hash, gint value)
|
2008-07-11 21:13:39 +00:00
|
|
|
{
|
2014-10-06 18:03:47 +00:00
|
|
|
stat_node *node = NULL;
|
|
|
|
stat_node *parent = NULL;
|
|
|
|
|
2021-06-18 18:21:42 +00:00
|
|
|
ws_assert( parent_id >= 0 && parent_id < (int) st->parents->len );
|
2014-10-06 18:03:47 +00:00
|
|
|
|
|
|
|
parent = (stat_node *)g_ptr_array_index(st->parents,parent_id);
|
|
|
|
|
|
|
|
if( parent->hash ) {
|
|
|
|
node = (stat_node *)g_hash_table_lookup(parent->hash,name);
|
|
|
|
} else {
|
|
|
|
node = (stat_node *)g_hash_table_lookup(st->names,name);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( node == NULL )
|
2018-12-27 19:47:02 +00:00
|
|
|
node = new_stat_node(st,name,parent_id,STAT_DT_INT,with_hash,with_hash);
|
2014-10-06 18:03:47 +00:00
|
|
|
|
|
|
|
switch (mode) {
|
|
|
|
case MN_INCREASE:
|
2016-01-20 19:39:54 +00:00
|
|
|
node->counter += value;
|
|
|
|
update_burst_calc(node, value);
|
|
|
|
break;
|
2018-12-27 19:47:02 +00:00
|
|
|
case MN_SET:
|
|
|
|
node->counter = value;
|
|
|
|
break;
|
2014-10-06 18:03:47 +00:00
|
|
|
case MN_AVERAGE:
|
2016-01-20 19:39:54 +00:00
|
|
|
node->counter++;
|
|
|
|
update_burst_calc(node, 1);
|
2017-03-11 15:41:00 +00:00
|
|
|
/* fall through */ /*to average code */
|
2014-10-06 18:03:47 +00:00
|
|
|
case MN_AVERAGE_NOTICK:
|
2018-12-27 19:47:02 +00:00
|
|
|
node->total.int_total += value;
|
|
|
|
if (node->minvalue.int_min > value) {
|
|
|
|
node->minvalue.int_min = value;
|
2016-01-20 19:39:54 +00:00
|
|
|
}
|
2018-12-27 19:47:02 +00:00
|
|
|
if (node->maxvalue.int_max < value) {
|
|
|
|
node->maxvalue.int_max = value;
|
2016-01-20 19:39:54 +00:00
|
|
|
}
|
|
|
|
node->st_flags |= ST_FLG_AVERAGE;
|
|
|
|
break;
|
2014-10-06 18:03:47 +00:00
|
|
|
case MN_SET_FLAGS:
|
2016-01-20 19:39:54 +00:00
|
|
|
node->st_flags |= value;
|
|
|
|
break;
|
2014-10-06 18:03:47 +00:00
|
|
|
case MN_CLEAR_FLAGS:
|
2016-01-20 19:39:54 +00:00
|
|
|
node->st_flags &= ~value;
|
|
|
|
break;
|
2014-10-06 18:03:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (node)
|
|
|
|
return node->id;
|
|
|
|
else
|
|
|
|
return -1;
|
2005-02-16 14:16:40 +00:00
|
|
|
}
|
|
|
|
|
2018-12-27 19:47:02 +00:00
|
|
|
/*
|
|
|
|
* Increases by delta the counter of the node whose name is given
|
|
|
|
* if the node does not exist yet it's created (with counter=1)
|
|
|
|
* using parent_name as parent node.
|
|
|
|
* with_hash=TRUE to indicate that the created node will have a parent
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
stats_tree_manip_node_float(manip_node_mode mode, stats_tree *st, const char *name,
|
|
|
|
int parent_id, gboolean with_hash, gfloat value)
|
|
|
|
{
|
|
|
|
stat_node *node = NULL;
|
|
|
|
stat_node *parent = NULL;
|
|
|
|
|
2021-06-18 18:21:42 +00:00
|
|
|
ws_assert(parent_id >= 0 && parent_id < (int)st->parents->len);
|
2018-12-27 19:47:02 +00:00
|
|
|
|
|
|
|
parent = (stat_node *)g_ptr_array_index(st->parents, parent_id);
|
|
|
|
|
|
|
|
if (parent->hash) {
|
|
|
|
node = (stat_node *)g_hash_table_lookup(parent->hash, name);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
node = (stat_node *)g_hash_table_lookup(st->names, name);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (node == NULL)
|
|
|
|
node = new_stat_node(st, name, parent_id, STAT_DT_FLOAT, with_hash, with_hash);
|
|
|
|
|
|
|
|
switch (mode) {
|
|
|
|
case MN_AVERAGE:
|
|
|
|
node->counter++;
|
|
|
|
update_burst_calc(node, 1);
|
|
|
|
/* fall through */ /*to average code */
|
|
|
|
case MN_AVERAGE_NOTICK:
|
|
|
|
node->total.float_total += value;
|
|
|
|
if (node->minvalue.float_min > value) {
|
|
|
|
node->minvalue.float_min = value;
|
|
|
|
}
|
|
|
|
if (node->maxvalue.float_max < value) {
|
|
|
|
node->maxvalue.float_max = value;
|
|
|
|
}
|
|
|
|
node->st_flags |= ST_FLG_AVERAGE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
//only average is currently supported
|
2021-06-18 18:21:42 +00:00
|
|
|
ws_assert_not_reached();
|
2018-12-27 19:47:02 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (node)
|
|
|
|
return node->id;
|
|
|
|
else
|
|
|
|
return -1;
|
|
|
|
}
|
2005-02-16 14:16:40 +00:00
|
|
|
|
2008-07-11 21:13:39 +00:00
|
|
|
extern char*
|
2013-08-14 00:41:02 +00:00
|
|
|
stats_tree_get_abbr(const char *opt_arg)
|
2008-07-11 21:13:39 +00:00
|
|
|
{
|
2014-10-06 18:03:47 +00:00
|
|
|
guint i;
|
2005-02-24 22:02:31 +00:00
|
|
|
|
2014-10-06 18:03:47 +00:00
|
|
|
/* XXX: this fails when tshark is given any options
|
|
|
|
after the -z */
|
2021-06-18 18:21:42 +00:00
|
|
|
ws_assert(opt_arg != NULL);
|
2011-02-18 22:43:48 +00:00
|
|
|
|
2014-10-06 18:03:47 +00:00
|
|
|
for (i=0; opt_arg[i] && opt_arg[i] != ','; i++);
|
2011-02-18 22:43:48 +00:00
|
|
|
|
2014-10-06 18:03:47 +00:00
|
|
|
if (opt_arg[i] == ',') {
|
|
|
|
return g_strndup(opt_arg,i);
|
|
|
|
} else {
|
|
|
|
return NULL;
|
|
|
|
}
|
2005-02-16 14:16:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-01-21 22:45:58 +00:00
|
|
|
/*
|
|
|
|
* This function accepts an input string which should define a long integer range.
|
|
|
|
* The normal result is a struct containing the floor and ceil value of this
|
|
|
|
* range.
|
|
|
|
*
|
|
|
|
* It is allowed to define a range string in the following ways :
|
|
|
|
*
|
|
|
|
* "0-10" -> { 0, 10 }
|
|
|
|
* "-0" -> { G_MININT, 0 }
|
|
|
|
* "0-" -> { 0, G_MAXINT }
|
|
|
|
* "-" -> { G_MININT, G_MAXINT }
|
|
|
|
*
|
|
|
|
* Note that this function is robust to buggy input string. If in some cases it
|
|
|
|
* returns NULL, it but may also return a pair with undefined values.
|
|
|
|
*
|
|
|
|
*/
|
2008-07-11 21:13:39 +00:00
|
|
|
static range_pair_t*
|
|
|
|
get_range(char *rngstr)
|
|
|
|
{
|
2014-10-06 18:03:47 +00:00
|
|
|
gchar **split;
|
|
|
|
range_pair_t *rng;
|
|
|
|
|
|
|
|
split = g_strsplit((gchar*)rngstr,"-",2);
|
|
|
|
|
|
|
|
/* empty string */
|
|
|
|
if (split[0] == NULL) {
|
|
|
|
g_strfreev(split);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2020-12-21 02:30:28 +00:00
|
|
|
rng = g_new(range_pair_t, 1);
|
2014-10-06 18:03:47 +00:00
|
|
|
|
|
|
|
if (split[1] == NULL) {
|
|
|
|
/* means we have a non empty string with no delimiter
|
|
|
|
* so it must be a single number */
|
|
|
|
rng->floor = (gint)strtol(split[0],NULL,10);
|
|
|
|
rng->ceil = rng->floor;
|
|
|
|
} else {
|
|
|
|
/* string == "X-?" */
|
|
|
|
if (*(split[0]) != '\0') {
|
|
|
|
rng->floor = (gint)strtol(split[0],NULL,10);
|
2015-12-01 14:09:27 +00:00
|
|
|
} else {
|
|
|
|
/* string == "-?" */
|
|
|
|
rng->floor = G_MININT;
|
|
|
|
}
|
2014-10-06 18:03:47 +00:00
|
|
|
|
|
|
|
/* string != "?-" */
|
2015-12-01 14:09:27 +00:00
|
|
|
if (*(split[1]) != '\0') {
|
2014-10-06 18:03:47 +00:00
|
|
|
rng->ceil = (gint)strtol(split[1],NULL,10);
|
2015-12-01 14:09:27 +00:00
|
|
|
} else {
|
|
|
|
/* string == "?-" */
|
|
|
|
rng->ceil = G_MAXINT;
|
|
|
|
}
|
2014-10-06 18:03:47 +00:00
|
|
|
}
|
|
|
|
g_strfreev(split);
|
|
|
|
|
|
|
|
return rng;
|
2005-02-16 14:16:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-11 21:13:39 +00:00
|
|
|
extern int
|
|
|
|
stats_tree_create_range_node(stats_tree *st, const gchar *name, int parent_id, ...)
|
|
|
|
{
|
2014-10-06 18:03:47 +00:00
|
|
|
va_list list;
|
|
|
|
gchar *curr_range;
|
2018-12-27 19:47:02 +00:00
|
|
|
stat_node *rng_root = new_stat_node(st, name, parent_id, STAT_DT_INT, FALSE, TRUE);
|
2014-10-06 18:03:47 +00:00
|
|
|
stat_node *range_node = NULL;
|
|
|
|
|
|
|
|
va_start( list, parent_id );
|
|
|
|
while (( curr_range = va_arg(list, gchar*) )) {
|
2018-12-27 19:47:02 +00:00
|
|
|
range_node = new_stat_node(st, curr_range, rng_root->id, STAT_DT_INT, FALSE, FALSE);
|
2014-10-06 18:03:47 +00:00
|
|
|
range_node->rng = get_range(curr_range);
|
|
|
|
}
|
|
|
|
va_end( list );
|
|
|
|
|
|
|
|
return rng_root->id;
|
2005-02-16 14:16:40 +00:00
|
|
|
}
|
|
|
|
|
2014-02-25 20:42:35 +00:00
|
|
|
extern int
|
2012-07-07 08:15:41 +00:00
|
|
|
stats_tree_create_range_node_string(stats_tree *st, const gchar *name,
|
2014-10-06 18:03:47 +00:00
|
|
|
int parent_id, int num_str_ranges,
|
|
|
|
gchar** str_ranges)
|
2012-07-07 08:15:41 +00:00
|
|
|
{
|
2014-10-06 18:03:47 +00:00
|
|
|
int i;
|
2018-12-27 19:47:02 +00:00
|
|
|
stat_node *rng_root = new_stat_node(st, name, parent_id, STAT_DT_INT, FALSE, TRUE);
|
2014-10-06 18:03:47 +00:00
|
|
|
stat_node *range_node = NULL;
|
2012-07-07 08:15:41 +00:00
|
|
|
|
2017-06-25 00:13:54 +00:00
|
|
|
for (i = 0; i < num_str_ranges - 1; i++) {
|
2018-12-27 19:47:02 +00:00
|
|
|
range_node = new_stat_node(st, str_ranges[i], rng_root->id, STAT_DT_INT, FALSE, FALSE);
|
2014-10-06 18:03:47 +00:00
|
|
|
range_node->rng = get_range(str_ranges[i]);
|
|
|
|
}
|
2018-12-27 19:47:02 +00:00
|
|
|
range_node = new_stat_node(st, str_ranges[i], rng_root->id, STAT_DT_INT, FALSE, FALSE);
|
2017-06-25 00:13:54 +00:00
|
|
|
range_node->rng = get_range(str_ranges[i]);
|
|
|
|
if (range_node->rng->floor == range_node->rng->ceil) {
|
|
|
|
range_node->rng->ceil = G_MAXINT;
|
|
|
|
}
|
2012-07-07 08:15:41 +00:00
|
|
|
|
2014-10-06 18:03:47 +00:00
|
|
|
return rng_root->id;
|
2012-07-07 08:15:41 +00:00
|
|
|
}
|
|
|
|
|
2005-03-20 00:19:15 +00:00
|
|
|
/****/
|
2008-07-11 21:13:39 +00:00
|
|
|
extern int
|
|
|
|
stats_tree_parent_id_by_name(stats_tree *st, const gchar *parent_name)
|
|
|
|
{
|
2014-10-06 18:03:47 +00:00
|
|
|
stat_node *node = (stat_node *)g_hash_table_lookup(st->names,parent_name);
|
2011-02-18 22:43:48 +00:00
|
|
|
|
2014-10-06 18:03:47 +00:00
|
|
|
if (node)
|
|
|
|
return node->id;
|
|
|
|
else
|
|
|
|
return 0; /* XXX: this is the root shoud we return -1 instead?*/
|
2005-02-16 14:16:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-11 21:13:39 +00:00
|
|
|
extern int
|
|
|
|
stats_tree_range_node_with_pname(stats_tree *st, const gchar *name,
|
2014-10-06 18:03:47 +00:00
|
|
|
const gchar *parent_name, ...)
|
2008-07-11 21:13:39 +00:00
|
|
|
{
|
2014-10-06 18:03:47 +00:00
|
|
|
va_list list;
|
|
|
|
gchar *curr_range;
|
|
|
|
stat_node *range_node = NULL;
|
|
|
|
int parent_id = stats_tree_parent_id_by_name(st,parent_name);
|
2018-12-27 19:47:02 +00:00
|
|
|
stat_node *rng_root = new_stat_node(st, name, parent_id, STAT_DT_INT, FALSE, TRUE);
|
2014-10-06 18:03:47 +00:00
|
|
|
|
|
|
|
va_start( list, parent_name );
|
|
|
|
while (( curr_range = va_arg(list, gchar*) )) {
|
2018-12-27 19:47:02 +00:00
|
|
|
range_node = new_stat_node(st, curr_range, rng_root->id, STAT_DT_INT, FALSE, FALSE);
|
2014-10-06 18:03:47 +00:00
|
|
|
range_node->rng = get_range(curr_range);
|
|
|
|
}
|
|
|
|
va_end( list );
|
|
|
|
|
|
|
|
return rng_root->id;
|
2011-02-18 22:43:48 +00:00
|
|
|
}
|
2005-02-16 14:16:40 +00:00
|
|
|
|
|
|
|
|
2008-07-11 21:13:39 +00:00
|
|
|
extern int
|
|
|
|
stats_tree_tick_range(stats_tree *st, const gchar *name, int parent_id,
|
2014-10-06 18:03:47 +00:00
|
|
|
int value_in_range)
|
2008-07-11 21:13:39 +00:00
|
|
|
{
|
2011-02-18 22:43:48 +00:00
|
|
|
|
2014-10-06 18:03:47 +00:00
|
|
|
stat_node *node = NULL;
|
|
|
|
stat_node *parent = NULL;
|
|
|
|
stat_node *child = NULL;
|
|
|
|
gint stat_floor, stat_ceil;
|
|
|
|
|
|
|
|
if (parent_id >= 0 && parent_id < (int) st->parents->len) {
|
|
|
|
parent = (stat_node *)g_ptr_array_index(st->parents,parent_id);
|
|
|
|
} else {
|
2021-06-18 18:21:42 +00:00
|
|
|
ws_assert_not_reached();
|
2014-10-06 18:03:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( parent->hash ) {
|
|
|
|
node = (stat_node *)g_hash_table_lookup(parent->hash,name);
|
|
|
|
} else {
|
|
|
|
node = (stat_node *)g_hash_table_lookup(st->names,name);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( node == NULL )
|
2021-06-18 18:21:42 +00:00
|
|
|
ws_assert_not_reached();
|
2014-10-06 18:03:47 +00:00
|
|
|
|
|
|
|
/* update stats for container node. counter should already be ticked so we only update total and min/max */
|
2018-12-27 19:47:02 +00:00
|
|
|
node->total.int_total += value_in_range;
|
|
|
|
if (node->minvalue.int_min > value_in_range) {
|
|
|
|
node->minvalue.int_min = value_in_range;
|
2014-10-06 18:03:47 +00:00
|
|
|
}
|
2018-12-27 19:47:02 +00:00
|
|
|
if (node->maxvalue.int_max < value_in_range) {
|
|
|
|
node->maxvalue.int_max = value_in_range;
|
2014-10-06 18:03:47 +00:00
|
|
|
}
|
|
|
|
node->st_flags |= ST_FLG_AVERAGE;
|
|
|
|
|
|
|
|
for ( child = node->children; child; child = child->next) {
|
|
|
|
stat_floor = child->rng->floor;
|
|
|
|
stat_ceil = child->rng->ceil;
|
|
|
|
|
|
|
|
if ( value_in_range >= stat_floor && value_in_range <= stat_ceil ) {
|
|
|
|
child->counter++;
|
2018-12-27 19:47:02 +00:00
|
|
|
child->total.int_total += value_in_range;
|
|
|
|
if (child->minvalue.int_min > value_in_range) {
|
|
|
|
child->minvalue.int_min = value_in_range;
|
2014-10-06 18:03:47 +00:00
|
|
|
}
|
2018-12-27 19:47:02 +00:00
|
|
|
if (child->maxvalue.int_max < value_in_range) {
|
|
|
|
child->maxvalue.int_max = value_in_range;
|
2014-10-06 18:03:47 +00:00
|
|
|
}
|
|
|
|
child->st_flags |= ST_FLG_AVERAGE;
|
|
|
|
update_burst_calc(child, 1);
|
|
|
|
return node->id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return node->id;
|
2005-02-16 14:16:40 +00:00
|
|
|
}
|
2005-02-24 22:02:31 +00:00
|
|
|
|
2008-07-11 21:13:39 +00:00
|
|
|
extern int
|
|
|
|
stats_tree_create_pivot(stats_tree *st, const gchar *name, int parent_id)
|
|
|
|
{
|
2018-12-27 19:47:02 +00:00
|
|
|
stat_node *node = new_stat_node(st,name,parent_id,STAT_DT_INT,TRUE,TRUE);
|
2011-02-18 22:43:48 +00:00
|
|
|
|
2014-10-06 18:03:47 +00:00
|
|
|
if (node)
|
|
|
|
return node->id;
|
|
|
|
else
|
|
|
|
return 0;
|
2005-02-24 22:02:31 +00:00
|
|
|
}
|
|
|
|
|
2008-07-11 21:13:39 +00:00
|
|
|
extern int
|
|
|
|
stats_tree_create_pivot_by_pname(stats_tree *st, const gchar *name,
|
2014-10-06 18:03:47 +00:00
|
|
|
const gchar *parent_name)
|
2008-07-11 21:13:39 +00:00
|
|
|
{
|
2014-10-06 18:03:47 +00:00
|
|
|
int parent_id = stats_tree_parent_id_by_name(st,parent_name);
|
|
|
|
stat_node *node;
|
2011-02-18 22:43:48 +00:00
|
|
|
|
2018-12-27 19:47:02 +00:00
|
|
|
node = new_stat_node(st,name,parent_id,STAT_DT_INT,TRUE,TRUE);
|
2011-02-18 22:43:48 +00:00
|
|
|
|
2014-10-06 18:03:47 +00:00
|
|
|
if (node)
|
|
|
|
return node->id;
|
|
|
|
else
|
|
|
|
return 0;
|
2005-02-24 22:02:31 +00:00
|
|
|
}
|
|
|
|
|
2008-07-11 21:13:39 +00:00
|
|
|
extern int
|
|
|
|
stats_tree_tick_pivot(stats_tree *st, int pivot_id, const gchar *pivot_value)
|
|
|
|
{
|
2014-10-06 18:03:47 +00:00
|
|
|
stat_node *parent = (stat_node *)g_ptr_array_index(st->parents,pivot_id);
|
2011-02-18 22:43:48 +00:00
|
|
|
|
2014-10-06 18:03:47 +00:00
|
|
|
parent->counter++;
|
|
|
|
update_burst_calc(parent, 1);
|
2018-12-27 19:47:02 +00:00
|
|
|
stats_tree_manip_node_int( MN_INCREASE, st, pivot_value, pivot_id, FALSE, 1);
|
2011-02-18 22:43:48 +00:00
|
|
|
|
2014-10-06 18:03:47 +00:00
|
|
|
return pivot_id;
|
2005-02-24 22:02:31 +00:00
|
|
|
}
|
|
|
|
|
2013-11-29 22:47:59 +00:00
|
|
|
extern gchar*
|
|
|
|
stats_tree_get_displayname (gchar* fullname)
|
|
|
|
{
|
2014-10-06 18:03:47 +00:00
|
|
|
gchar *buf = g_strdup(fullname);
|
|
|
|
gchar *sep;
|
|
|
|
|
|
|
|
if (prefs.st_sort_showfullname) {
|
|
|
|
return buf; /* unmodifed */
|
|
|
|
}
|
|
|
|
|
|
|
|
sep = buf;
|
|
|
|
while ((sep = strchr(sep,'/')) != NULL) {
|
|
|
|
if (*(++sep)=='/') { /* escapeded slash - two slash characters after each other */
|
|
|
|
memmove(sep,sep+1,strlen(sep));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* we got a new path separator */
|
|
|
|
memmove(buf,sep,strlen(sep)+1);
|
|
|
|
sep = buf;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return buf;
|
2013-11-29 22:47:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
extern gint
|
|
|
|
stats_tree_get_default_sort_col (stats_tree *st)
|
|
|
|
{
|
2014-10-06 18:03:47 +00:00
|
|
|
switch ((st->st_flags&ST_FLG_SRTCOL_MASK)>>ST_FLG_SRTCOL_SHIFT) {
|
2016-01-20 19:39:54 +00:00
|
|
|
case ST_SORT_COL_NAME:
|
|
|
|
return COL_NAME;
|
|
|
|
case ST_SORT_COL_COUNT:
|
|
|
|
return COL_COUNT;
|
|
|
|
case ST_SORT_COL_AVG:
|
|
|
|
return COL_AVERAGE;
|
|
|
|
case ST_SORT_COL_MIN:
|
|
|
|
return COL_MIN;
|
|
|
|
case ST_SORT_COL_MAX:
|
|
|
|
return COL_MAX;
|
|
|
|
case ST_SORT_COL_BURSTRATE:
|
|
|
|
return COL_BURSTRATE;
|
2014-10-06 18:03:47 +00:00
|
|
|
}
|
|
|
|
return COL_COUNT; /* nothing specific set */
|
2014-01-05 18:39:50 +00:00
|
|
|
}
|
2013-11-29 22:47:59 +00:00
|
|
|
|
|
|
|
extern gboolean
|
|
|
|
stats_tree_is_default_sort_DESC (stats_tree *st)
|
|
|
|
{
|
2014-10-06 18:03:47 +00:00
|
|
|
return st->st_flags&ST_FLG_SORT_DESC;
|
2013-11-29 22:47:59 +00:00
|
|
|
}
|
|
|
|
|
2013-11-30 00:02:46 +00:00
|
|
|
extern const gchar*
|
2013-11-29 23:54:12 +00:00
|
|
|
stats_tree_get_column_name (gint col_index)
|
2013-11-29 22:47:59 +00:00
|
|
|
{
|
2014-10-06 18:03:47 +00:00
|
|
|
switch (col_index) {
|
2016-01-20 19:39:54 +00:00
|
|
|
case COL_NAME:
|
|
|
|
return "Topic / Item";
|
|
|
|
case COL_COUNT:
|
|
|
|
return "Count";
|
|
|
|
case COL_AVERAGE:
|
|
|
|
return "Average";
|
|
|
|
case COL_MIN:
|
2019-12-31 23:35:50 +00:00
|
|
|
return "Min Val";
|
2016-01-20 19:39:54 +00:00
|
|
|
case COL_MAX:
|
2019-12-31 23:35:50 +00:00
|
|
|
return "Max Val";
|
2016-01-20 19:39:54 +00:00
|
|
|
case COL_RATE:
|
|
|
|
return "Rate (ms)";
|
|
|
|
case COL_PERCENT:
|
|
|
|
return "Percent";
|
|
|
|
case COL_BURSTRATE:
|
2019-12-31 23:35:50 +00:00
|
|
|
return prefs.st_burst_showcount ? "Burst Count" : "Burst Rate";
|
2016-01-20 19:39:54 +00:00
|
|
|
case COL_BURSTTIME:
|
2019-12-31 23:35:50 +00:00
|
|
|
return "Burst Start";
|
2016-01-20 19:39:54 +00:00
|
|
|
default:
|
|
|
|
return "(Unknown)";
|
2014-10-06 18:03:47 +00:00
|
|
|
}
|
2013-11-29 22:47:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
extern gint
|
2013-11-29 23:54:12 +00:00
|
|
|
stats_tree_get_column_size (gint col_index)
|
2013-11-29 22:47:59 +00:00
|
|
|
{
|
2014-10-06 18:03:47 +00:00
|
|
|
if (col_index==COL_NAME) {
|
|
|
|
return 36; /* but caller should really call stats_tree_branch_max_namelen() */
|
|
|
|
}
|
|
|
|
if (col_index<N_COLUMNS) {
|
|
|
|
return 12; /* all numerical values are this size */
|
|
|
|
}
|
|
|
|
return 0; /* invalid column */
|
2013-11-29 22:47:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
extern gchar**
|
|
|
|
stats_tree_get_values_from_node (const stat_node* node)
|
|
|
|
{
|
2014-10-06 18:03:47 +00:00
|
|
|
gchar **values = (gchar**) g_malloc0(sizeof(gchar*)*(node->st->num_columns));
|
|
|
|
|
2017-09-29 18:48:35 +00:00
|
|
|
values[COL_NAME] = (node->st_flags&ST_FLG_ROOTCHILD)?stats_tree_get_displayname(node->name):g_strdup(node->name);
|
2021-12-16 18:06:18 +00:00
|
|
|
values[COL_COUNT] = ws_strdup_printf("%u",node->counter);
|
2018-12-27 19:47:02 +00:00
|
|
|
if (((node->st_flags&ST_FLG_AVERAGE) || node->rng)) {
|
|
|
|
if (node->counter) {
|
|
|
|
switch (node->datatype)
|
|
|
|
{
|
|
|
|
case STAT_DT_INT:
|
2021-12-16 18:06:18 +00:00
|
|
|
values[COL_AVERAGE] = ws_strdup_printf("%.2f", ((float)node->total.int_total) / node->counter);
|
2018-12-27 19:47:02 +00:00
|
|
|
break;
|
|
|
|
case STAT_DT_FLOAT:
|
2021-12-16 18:06:18 +00:00
|
|
|
values[COL_AVERAGE] = ws_strdup_printf("%.2f", node->total.float_total / node->counter);
|
2018-12-27 19:47:02 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
values[COL_AVERAGE] = g_strdup("-");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
values[COL_AVERAGE] = g_strdup("");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (((node->st_flags&ST_FLG_AVERAGE) || node->rng)) {
|
|
|
|
if (node->counter) {
|
|
|
|
switch (node->datatype)
|
|
|
|
{
|
|
|
|
case STAT_DT_INT:
|
2021-12-16 18:06:18 +00:00
|
|
|
values[COL_MIN] = ws_strdup_printf("%d", node->minvalue.int_min);
|
2018-12-27 19:47:02 +00:00
|
|
|
break;
|
|
|
|
case STAT_DT_FLOAT:
|
2021-12-16 18:06:18 +00:00
|
|
|
values[COL_MIN] = ws_strdup_printf("%f", node->minvalue.float_min);
|
2018-12-27 19:47:02 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
values[COL_MIN] = g_strdup("-");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
values[COL_MIN] = g_strdup("");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (((node->st_flags&ST_FLG_AVERAGE) || node->rng)) {
|
|
|
|
if (node->counter) {
|
|
|
|
switch (node->datatype)
|
|
|
|
{
|
|
|
|
case STAT_DT_INT:
|
2021-12-16 18:06:18 +00:00
|
|
|
values[COL_MAX] = ws_strdup_printf("%d", node->maxvalue.int_max);
|
2018-12-27 19:47:02 +00:00
|
|
|
break;
|
|
|
|
case STAT_DT_FLOAT:
|
2021-12-16 18:06:18 +00:00
|
|
|
values[COL_MAX] = ws_strdup_printf("%f", node->maxvalue.float_max);
|
2018-12-27 19:47:02 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
values[COL_MAX] = g_strdup("-");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
values[COL_MAX] = g_strdup("");
|
|
|
|
}
|
|
|
|
|
2021-12-16 18:06:18 +00:00
|
|
|
values[COL_RATE] = (node->st->elapsed)?ws_strdup_printf("%.4f",((float)node->counter)/node->st->elapsed):g_strdup("");
|
2017-09-29 18:48:35 +00:00
|
|
|
values[COL_PERCENT] = ((node->parent)&&(node->parent->counter))?
|
2021-12-16 18:06:18 +00:00
|
|
|
ws_strdup_printf("%.2f%%",(node->counter*100.0)/node->parent->counter):
|
2014-10-06 18:03:47 +00:00
|
|
|
(node->parent==&(node->st->root)?g_strdup("100%"):g_strdup(""));
|
|
|
|
if (node->st->num_columns>COL_BURSTTIME) {
|
2017-09-29 18:48:35 +00:00
|
|
|
values[COL_BURSTRATE] = (!prefs.st_enable_burstinfo)?g_strdup(""):
|
2014-10-06 18:03:47 +00:00
|
|
|
(node->max_burst?(prefs.st_burst_showcount?
|
2021-12-16 18:06:18 +00:00
|
|
|
ws_strdup_printf("%d",node->max_burst):
|
|
|
|
ws_strdup_printf("%.4f",((double)node->max_burst)/prefs.st_burst_windowlen)):
|
2014-10-06 18:03:47 +00:00
|
|
|
g_strdup("-"));
|
2017-09-29 18:48:35 +00:00
|
|
|
values[COL_BURSTTIME] = (!prefs.st_enable_burstinfo)?g_strdup(""):
|
2021-12-16 18:06:18 +00:00
|
|
|
(node->max_burst?ws_strdup_printf("%.3f",(node->burst_time/1000.0)):g_strdup("-"));
|
2014-10-06 18:03:47 +00:00
|
|
|
}
|
|
|
|
return values;
|
2013-11-29 22:47:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
extern gint
|
|
|
|
stats_tree_sort_compare (const stat_node *a, const stat_node *b, gint sort_column,
|
2014-10-06 18:03:47 +00:00
|
|
|
gboolean sort_descending)
|
2013-11-29 22:47:59 +00:00
|
|
|
{
|
2014-10-06 18:03:47 +00:00
|
|
|
int result = 0;
|
2018-12-27 19:47:02 +00:00
|
|
|
float avg_a = 0, avg_b = 0;
|
2014-10-06 18:03:47 +00:00
|
|
|
|
|
|
|
if (prefs.st_sort_rng_nameonly&&(a->rng&&b->rng)) {
|
|
|
|
/* always sort ranges by range name */
|
|
|
|
result = a->rng->floor - b->rng->floor;
|
|
|
|
if (sort_descending&&(!prefs.st_sort_rng_fixorder)) {
|
2017-09-29 18:48:35 +00:00
|
|
|
result = -result;
|
2014-10-06 18:03:47 +00:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-01-20 19:39:54 +00:00
|
|
|
switch (sort_column) {
|
|
|
|
case COL_NAME:
|
|
|
|
if (a->rng&&b->rng) {
|
|
|
|
result = a->rng->floor - b->rng->floor;
|
|
|
|
}
|
|
|
|
else if (prefs.st_sort_casesensitve) {
|
|
|
|
result = strcmp(a->name,b->name);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
result = g_ascii_strcasecmp(a->name,b->name);
|
|
|
|
}
|
|
|
|
break;
|
2014-10-06 18:03:47 +00:00
|
|
|
|
|
|
|
case COL_RATE:
|
|
|
|
case COL_PERCENT:
|
2016-01-20 19:39:54 +00:00
|
|
|
case COL_COUNT:
|
|
|
|
result = a->counter - b->counter;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case COL_AVERAGE:
|
2018-12-27 19:47:02 +00:00
|
|
|
switch (a->datatype)
|
|
|
|
{
|
|
|
|
case STAT_DT_INT:
|
|
|
|
avg_a = a->counter ? ((float)a->total.int_total)/a->counter : 0;
|
|
|
|
avg_b = b->counter ? ((float)b->total.int_total)/b->counter : 0;
|
|
|
|
break;
|
|
|
|
case STAT_DT_FLOAT:
|
|
|
|
avg_a = a->counter ? ((float)a->total.float_total) / a->counter : 0;
|
|
|
|
avg_b = b->counter ? ((float)b->total.float_total) / b->counter : 0;
|
|
|
|
break;
|
|
|
|
}
|
2017-09-29 18:55:23 +00:00
|
|
|
result = (avg_a>avg_b) ? 1 : ( (avg_a<avg_b) ? -1 : 0);
|
2016-01-20 19:39:54 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case COL_MIN:
|
2018-12-27 19:47:02 +00:00
|
|
|
switch (a->datatype)
|
|
|
|
{
|
|
|
|
case STAT_DT_INT:
|
|
|
|
result = a->minvalue.int_min - b->minvalue.int_min;
|
|
|
|
break;
|
|
|
|
case STAT_DT_FLOAT:
|
|
|
|
result = (a->minvalue.float_min>b->minvalue.int_min) ? 1 : ((a->minvalue.float_min<b->minvalue.int_min) ? -1 : 0);
|
|
|
|
break;
|
|
|
|
}
|
2016-01-20 19:39:54 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case COL_MAX:
|
2018-12-27 19:47:02 +00:00
|
|
|
switch (a->datatype)
|
|
|
|
{
|
|
|
|
case STAT_DT_INT:
|
|
|
|
result = a->maxvalue.int_max - b->maxvalue.int_max;
|
|
|
|
break;
|
|
|
|
case STAT_DT_FLOAT:
|
|
|
|
result = (a->maxvalue.float_max>b->maxvalue.float_max) ? 1 : ((a->maxvalue.float_max<b->maxvalue.float_max) ? -1 : 0);
|
|
|
|
break;
|
|
|
|
}
|
2016-01-20 19:39:54 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case COL_BURSTRATE:
|
|
|
|
result = a->max_burst - b->max_burst;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case COL_BURSTTIME:
|
|
|
|
result = (a->burst_time>b->burst_time)?1:((a->burst_time<b->burst_time)?-1:0);
|
|
|
|
break;
|
2014-10-06 18:03:47 +00:00
|
|
|
|
|
|
|
default:
|
2016-01-20 19:39:54 +00:00
|
|
|
/* no sort comparison found for column - must update this switch statement */
|
2021-06-18 18:21:42 +00:00
|
|
|
ws_assert_not_reached();
|
2014-10-06 18:03:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* break tie between items with same primary search result */
|
|
|
|
if (!result) {
|
|
|
|
if (sort_column==COL_NAME) {
|
|
|
|
result = a->counter - b->counter;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (a->rng&&b->rng) {
|
|
|
|
result = a->rng->floor - b->rng->floor;
|
|
|
|
}
|
|
|
|
else if (prefs.st_sort_casesensitve) {
|
|
|
|
result = strcmp(a->name,b->name);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
result = g_ascii_strcasecmp(a->name,b->name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* take into account sort order */
|
|
|
|
if (sort_descending) {
|
2017-09-29 18:48:35 +00:00
|
|
|
result = -result;
|
2014-10-06 18:03:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((a->st_flags&ST_FLG_SORT_TOP)!=(b->st_flags&ST_FLG_SORT_TOP)) {
|
|
|
|
/* different sort groups top vs non-top */
|
2017-09-29 18:48:35 +00:00
|
|
|
result = (a->st_flags&ST_FLG_SORT_TOP)?-1:1;
|
2014-10-06 18:03:47 +00:00
|
|
|
}
|
|
|
|
return result;
|
2013-11-29 22:47:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
extern GString*
|
2013-11-29 23:54:12 +00:00
|
|
|
stats_tree_format_as_str(const stats_tree* st, st_format_type format_type,
|
2014-10-06 18:03:47 +00:00
|
|
|
gint sort_column, gboolean sort_descending)
|
2013-11-29 22:47:59 +00:00
|
|
|
{
|
2017-09-29 18:48:35 +00:00
|
|
|
int maxnamelen = stats_tree_branch_max_namelen(&st->root,0);
|
2014-10-06 18:03:47 +00:00
|
|
|
stat_node *child;
|
|
|
|
GString *s;
|
|
|
|
int count;
|
|
|
|
gchar *separator = NULL;
|
|
|
|
|
2016-01-20 19:39:54 +00:00
|
|
|
switch(format_type) {
|
|
|
|
case ST_FORMAT_YAML:
|
|
|
|
s = g_string_new("---\n");
|
|
|
|
break;
|
|
|
|
case ST_FORMAT_XML:
|
|
|
|
s = g_string_new("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
|
|
|
|
break;
|
|
|
|
case ST_FORMAT_CSV:
|
|
|
|
s = g_string_new("\"level\",\"parent\",");
|
|
|
|
for (count = 0; count<st->num_columns; count++) {
|
|
|
|
g_string_append_printf(s,"\"%s\",",stats_tree_get_column_name(count));
|
|
|
|
}
|
|
|
|
g_string_append (s,"\n");
|
|
|
|
break;
|
|
|
|
case ST_FORMAT_PLAIN:
|
2014-10-06 18:03:47 +00:00
|
|
|
{
|
2016-01-20 19:39:54 +00:00
|
|
|
char fmt[16];
|
|
|
|
int sep_length;
|
2014-10-06 18:03:47 +00:00
|
|
|
|
2017-09-29 18:48:35 +00:00
|
|
|
sep_length = maxnamelen;
|
2016-01-20 19:39:54 +00:00
|
|
|
for (count = 1; count<st->num_columns; count++) {
|
|
|
|
sep_length += stats_tree_get_column_size(count)+2;
|
|
|
|
}
|
|
|
|
separator = (gchar *)g_malloc(sep_length+1);
|
|
|
|
memset (separator, '=', sep_length);
|
|
|
|
separator[sep_length] = 0;
|
|
|
|
|
|
|
|
s = g_string_new("\n");
|
|
|
|
g_string_append(s,separator);
|
|
|
|
g_string_append_printf(s,"\n%s:\n",st->cfg->name);
|
2021-12-16 18:06:18 +00:00
|
|
|
snprintf (fmt,(gulong)sizeof(fmt),"%%-%us",maxnamelen);
|
2016-01-20 19:39:54 +00:00
|
|
|
g_string_append_printf(s,fmt,stats_tree_get_column_name(0));
|
|
|
|
for (count = 1; count<st->num_columns; count++) {
|
2021-12-16 18:06:18 +00:00
|
|
|
snprintf (fmt,(gulong)sizeof(fmt)," %%-%us",stats_tree_get_column_size(count)+1);
|
2016-01-20 19:39:54 +00:00
|
|
|
g_string_append_printf(s,fmt,stats_tree_get_column_name(count));
|
|
|
|
}
|
|
|
|
memset (separator, '-', sep_length);
|
|
|
|
g_string_append_printf(s,"\n%s\n",separator);
|
|
|
|
break;
|
2014-10-06 18:03:47 +00:00
|
|
|
}
|
2016-01-20 19:39:54 +00:00
|
|
|
default:
|
|
|
|
return g_string_new("unknown format for stats_tree\n");
|
2014-10-06 18:03:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (child = st->root.children; child; child = child->next ) {
|
|
|
|
stats_tree_format_node_as_str(child,s,format_type,0,"",maxnamelen,sort_column,sort_descending);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (format_type==ST_FORMAT_PLAIN) {
|
|
|
|
g_string_append_printf(s,"\n%s\n",separator);
|
|
|
|
g_free(separator);
|
|
|
|
}
|
|
|
|
|
|
|
|
return s;
|
2013-11-29 22:47:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct {
|
2014-10-06 18:03:47 +00:00
|
|
|
gint sort_column;
|
|
|
|
gboolean sort_descending;
|
|
|
|
} sortinfo;
|
2013-11-29 22:47:59 +00:00
|
|
|
|
|
|
|
/* Function to compare elements for child array sort. a and b are children, user_data
|
|
|
|
points to a st_flags value */
|
|
|
|
extern gint
|
|
|
|
stat_node_array_sortcmp (gconstpointer a, gconstpointer b, gpointer user_data)
|
|
|
|
{
|
2014-10-06 18:03:47 +00:00
|
|
|
/* user_data is *guint value to st_flags */
|
2016-01-20 02:09:57 +00:00
|
|
|
return stats_tree_sort_compare (*(const stat_node*const*)a,*(const stat_node*const*)b,
|
2014-10-06 18:03:47 +00:00
|
|
|
((sortinfo*)user_data)->sort_column,((sortinfo*)user_data)->sort_descending);
|
2013-12-02 09:30:31 +00:00
|
|
|
}
|
2013-11-29 22:47:59 +00:00
|
|
|
|
|
|
|
static gchar*
|
|
|
|
clean_for_xml_tag (gchar *str)
|
|
|
|
{
|
2014-10-06 18:03:47 +00:00
|
|
|
gchar *s = str;
|
|
|
|
while ((s=strpbrk(s,"!\"#$%%&'()*+,/;<=>?@[\\]^`{|}~ ")) != NULL) {
|
|
|
|
*(s++) = '-';
|
|
|
|
}
|
|
|
|
return str;
|
2013-11-29 22:47:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/** helper funcation to add note to formatted stats_tree */
|
2013-11-30 00:02:46 +00:00
|
|
|
WS_DLL_PUBLIC void stats_tree_format_node_as_str(const stat_node *node,
|
2014-10-06 18:03:47 +00:00
|
|
|
GString *s,
|
|
|
|
st_format_type format_type,
|
|
|
|
guint indent,
|
|
|
|
const gchar *path,
|
|
|
|
gint maxnamelen,
|
|
|
|
gint sort_column,
|
|
|
|
gboolean sort_descending)
|
2013-11-29 22:47:59 +00:00
|
|
|
{
|
2014-10-06 18:03:47 +00:00
|
|
|
int count;
|
2017-09-29 18:48:35 +00:00
|
|
|
int num_columns = node->st->num_columns;
|
|
|
|
gchar **values = stats_tree_get_values_from_node(node);
|
2014-10-06 18:03:47 +00:00
|
|
|
stat_node *child;
|
|
|
|
sortinfo si;
|
|
|
|
gchar *full_path;
|
2014-12-30 01:24:44 +00:00
|
|
|
char fmt[16] = "%s%s%s";
|
2014-10-06 18:03:47 +00:00
|
|
|
|
2016-01-20 19:39:54 +00:00
|
|
|
switch(format_type) {
|
|
|
|
case ST_FORMAT_YAML:
|
|
|
|
if (indent) {
|
2021-12-16 18:06:18 +00:00
|
|
|
snprintf(fmt, (gulong)sizeof(fmt), "%%%ds%%s%%s", indent*4-2);
|
2014-10-06 18:03:47 +00:00
|
|
|
}
|
2016-01-20 19:39:54 +00:00
|
|
|
g_string_append_printf(s, fmt, "", indent?"- ":"", "Description");
|
|
|
|
g_string_append_printf(s, ": \"%s\"\n", values[0]);
|
|
|
|
|
|
|
|
for (count = 1; count<num_columns; count++) {
|
|
|
|
if (*values[count]) {
|
|
|
|
g_string_append_printf(s, fmt, "", indent?" ":"",
|
|
|
|
stats_tree_get_column_name(count));
|
|
|
|
g_string_append_printf(s, ": %s\n", values[count]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (node->children) {
|
|
|
|
g_string_append_printf(s, fmt, "", indent?" ":"", "Items:\n");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ST_FORMAT_XML:
|
2014-10-06 18:03:47 +00:00
|
|
|
{
|
2016-01-20 19:39:54 +00:00
|
|
|
char *itemname = xml_escape(values[0]);
|
|
|
|
g_string_append_printf(s,"<stat-node name=\"%s\"%s>\n",itemname,
|
|
|
|
node->rng?" isrange=\"true\"":"");
|
|
|
|
g_free(itemname);
|
|
|
|
for (count = 1; count<num_columns; count++) {
|
2017-09-29 18:48:35 +00:00
|
|
|
gchar *colname = g_strdup(stats_tree_get_column_name(count));
|
2016-01-20 19:39:54 +00:00
|
|
|
g_string_append_printf(s,"<%s>",clean_for_xml_tag(colname));
|
|
|
|
g_string_append_printf(s,"%s</%s>\n",values[count],colname);
|
|
|
|
g_free(colname);
|
|
|
|
}
|
|
|
|
break;
|
2014-10-06 18:03:47 +00:00
|
|
|
}
|
2016-01-20 19:39:54 +00:00
|
|
|
case ST_FORMAT_CSV:
|
|
|
|
g_string_append_printf(s,"%d,\"%s\",\"%s\"",indent,path,values[0]);
|
|
|
|
for (count = 1; count<num_columns; count++) {
|
|
|
|
g_string_append_printf(s,",%s",values[count]);
|
|
|
|
}
|
|
|
|
g_string_append (s,"\n");
|
|
|
|
break;
|
|
|
|
case ST_FORMAT_PLAIN:
|
2021-12-16 18:06:18 +00:00
|
|
|
snprintf (fmt,(gulong)sizeof(fmt),"%%%ds%%-%us",indent,maxnamelen-indent);
|
2016-01-20 19:39:54 +00:00
|
|
|
g_string_append_printf(s,fmt,"",values[0]);
|
|
|
|
for (count = 1; count<num_columns; count++) {
|
2021-12-16 18:06:18 +00:00
|
|
|
snprintf (fmt,(gulong)sizeof(fmt)," %%-%us",stats_tree_get_column_size(count)+1);
|
2016-01-20 19:39:54 +00:00
|
|
|
g_string_append_printf(s,fmt,values[count]);
|
|
|
|
}
|
|
|
|
g_string_append (s,"\n");
|
|
|
|
break;
|
2014-10-06 18:03:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
indent++;
|
|
|
|
indent = indent > INDENT_MAX ? INDENT_MAX : indent;
|
2021-12-16 18:06:18 +00:00
|
|
|
full_path = ws_strdup_printf ("%s/%s",path,values[0]);
|
2014-10-06 18:03:47 +00:00
|
|
|
|
|
|
|
for (count = 0; count<num_columns; count++) {
|
|
|
|
g_free(values[count]);
|
|
|
|
}
|
|
|
|
g_free(values);
|
|
|
|
|
|
|
|
if (node->children) {
|
2017-09-29 18:48:35 +00:00
|
|
|
GArray *Children = g_array_new(FALSE,FALSE,sizeof(child));
|
2014-10-06 18:03:47 +00:00
|
|
|
for (child = node->children; child; child = child->next ) {
|
|
|
|
g_array_append_val(Children,child);
|
|
|
|
}
|
|
|
|
si.sort_column = sort_column;
|
|
|
|
si.sort_descending = sort_descending;
|
|
|
|
g_array_sort_with_data(Children,stat_node_array_sortcmp,&si);
|
|
|
|
for (count = 0; count<((int)Children->len); count++) {
|
|
|
|
stats_tree_format_node_as_str(g_array_index(Children,stat_node*,count), s, format_type,
|
|
|
|
indent, full_path, maxnamelen, sort_column, sort_descending);
|
|
|
|
}
|
2018-05-09 20:37:41 +00:00
|
|
|
g_array_free(Children, TRUE);
|
2014-10-06 18:03:47 +00:00
|
|
|
}
|
|
|
|
g_free(full_path);
|
|
|
|
|
|
|
|
if (format_type==ST_FORMAT_XML) {
|
|
|
|
g_string_append(s,"</stat-node>\n");
|
|
|
|
}
|
2013-11-29 22:47:59 +00:00
|
|
|
}
|
|
|
|
|
2017-02-05 22:00:51 +00:00
|
|
|
void stats_tree_cleanup(void)
|
|
|
|
{
|
|
|
|
g_hash_table_destroy(registry);
|
|
|
|
}
|
|
|
|
|
2014-01-05 18:39:50 +00:00
|
|
|
/*
|
2019-07-26 18:43:17 +00:00
|
|
|
* Editor modelines - https://www.wireshark.org/tools/modelines.html
|
2014-01-05 18:39:50 +00:00
|
|
|
*
|
2014-10-06 18:03:47 +00:00
|
|
|
* Local variables:
|
2014-01-05 18:39:50 +00:00
|
|
|
* c-basic-offset: 4
|
|
|
|
* tab-width: 8
|
2014-10-06 18:03:47 +00:00
|
|
|
* indent-tabs-mode: nil
|
2014-01-05 18:39:50 +00:00
|
|
|
* End:
|
|
|
|
*
|
2014-10-06 18:03:47 +00:00
|
|
|
* vi: set shiftwidth=4 tabstop=8 expandtab:
|
|
|
|
* :indentSize=4:tabSize=8:noTabs=true:
|
2014-01-05 18:39:50 +00:00
|
|
|
*/
|