[go: up one dir, main page]

File: ziomon_tools.c

package info (click to toggle)
s390-tools 1.16.0-2
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 4,332 kB
  • sloc: ansic: 46,620; sh: 8,560; cpp: 8,185; asm: 5,503; perl: 3,014; makefile: 886
file content (103 lines) | stat: -rw-r--r-- 2,240 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/*
 * FCP adapter trace facility
 *
 * Various shared utility functions and structs
 *
 * Copyright IBM Corp. 2008
 * Author(s): Stefan Raspl <raspl@linux.vnet.ibm.com>
 */

#include <stdio.h>
#include <stdint.h>
#include <assert.h>
#include <math.h>

#include "ziomon_tools.h"

extern int verbose;

void swap_abbrev_stat(struct abbrev_stat *var) {
	swap_64(var->min);
	swap_64(var->max);
	swap_64(var->sum);
	swap_64(var->sos);
}

double calc_avg(__u64 sum, __u64 count)
{
	assert(count > 0);
	return (sum / (double)count);
}

double calc_variance(__u64 sum, __u64 sos, __u64 count)
{
	assert(count > 0);
	return ((sos - ((sum * sum) / (double)count)) / (double)count);
}

double calc_std_dev(__u64 sum, __u64 sos, __u64 count)
{
	return sqrt(calc_variance(sum, sos, count));
}

void transform_abbrev_stat(struct abbrev_stat *stat,
				       __u64 old_count,
				       double new_count)
{
	stat->min = 0;
	stat->sum = (__u64)(calc_avg(stat->sum, old_count) * new_count);
	stat->sos = (__u64)(calc_avg(stat->sos, old_count) * new_count);
}

void print_abbrev_stat(struct abbrev_stat *stats, __u64 count)
{
	printf("\t\tmin      : %Lu\n", (long long)stats->min);
	printf("\t\tmax      : %Lu\n", (long long)stats->max);
	vverbose_msg("\t\tsum      : %Lu\n", (long long)stats->sum);
	vverbose_msg("\t\tsos      : %Lu\n", (long long)stats->sos);
	printf("\t\tavg      : %.1lf\n", calc_avg(stats->sum, count));
	printf("\t\tstd dev  : %.1lf\n", calc_std_dev(stats->sum, stats->sos,
						      count));
}

void aggregate_abbrev_stat(const struct abbrev_stat *src,
				    struct abbrev_stat *tgt)
{
	if (src->max > tgt->max)
		tgt->max = src->max;
	if (src->min < tgt->min)
		tgt->min = src->min;
	tgt->sum += src->sum;
	tgt->sos += src->sos;
}

void update_abbrev_stat(struct abbrev_stat *stat, __u64 val)
{
	if (val < stat->min)
		stat->min = val;
	if (val > stat->max)
		stat->max = val;
	stat->sum += val;
	stat->sos += (val * val);
}

void copy_abbrev_stat(struct abbrev_stat *tgt,
			const struct abbrev_stat *src)
{
	tgt->min = src->min;
	tgt->max = src->max;
	tgt->sum = src->sum;
	tgt->sos = src->sos;
}

void init_abbrev_stat(struct abbrev_stat *data)
{
	data->min = UINT64_MAX;
	data->max = 0;
	data->sum = 0;
	data->sos = 0;
}