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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
|
/* Copyright (C) 2021 Free Software Foundation, Inc.
Contributed by Oracle.
This file is part of GNU Binutils.
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 3, 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.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, 51 Franklin Street - Fifth Floor, Boston,
MA 02110-1301, USA. */
#include "config.h"
//#include <search.h> // For the tsearch stuff
#include <assert.h>
//#include <stdlib.h>
#include "Table.h"
#include "Sample.h"
#include "Stats_data.h"
#include "util.h"
#include "i18n.h"
//XXX: The fundamental problem with this package of routines is that
//XXX: they should look a lot more like overview data. The result
//XXX: is that it is not possible to share as much code as would
//XXX: otherwise be possible.
int
Stats_data::size ()
{
// Return the number of Stats_item values associated with "this".
if (stats_items == NULL)
return 0;
return stats_items->size ();
}
Stats_data::Stats_item
Stats_data::fetch (int index)
{
// Routine will return the "index"'th Stats_item associated with "this".
assert (index >= 0 && index < stats_items->size ());
return *(stats_items->fetch (index));
}
Stats_data::Stats_data ()
{
// this constructor for use with sum()
packets = NULL;
stats_items = NULL;
}
Stats_data::Stats_data (DataView *_packets)
{
packets = _packets;
stats_items = NULL;
compute_data (); // reads all data
}
Stats_data::~Stats_data ()
{
if (stats_items)
{
stats_items->destroy ();
delete stats_items;
}
}
void
Stats_data::sum (Stats_data *data)
{
int index;
Stats_item *stats_item, *data_item;
if (stats_items == NULL)
{
stats_items = new Vector<Stats_item*>;
Vec_loop (Stats_item*, data->stats_items, index, data_item)
{
stats_item = create_stats_item (data_item->value.ll, data_item->label);
stats_items->append (stats_item);
}
}
else
{
Vec_loop (Stats_item*, data->stats_items, index, data_item)
{
stats_items->fetch (index)->value.ll += data_item->value.ll;
}
}
}
Stats_data::Stats_item *
Stats_data::create_stats_item (long long v, char *l)
{
Stats_data::Stats_item *st_it;
st_it = new Stats_data::Stats_item;
st_it->label = l;
st_it->value.sign = false;
st_it->value.ll = v;
st_it->value.tag = VT_LLONG;
return st_it;
}
PrUsage *
Stats_data::fetchPrUsage (long index)
{
// Return the data values corresponding to the "index"'th sample.
PrUsage *prusage;
if (packets->getSize () > 0)
{
Sample* sample = (Sample*) packets->getObjValue (PROP_SMPLOBJ, index);
prusage = sample->get_usage ();
if (prusage != NULL)
return prusage;
}
return new PrUsage;
}
void
Stats_data::compute_data ()
{
Stats_data::Stats_item *stats_item;
PrUsage *tots, *temp;
stats_items = new Vector<Stats_data::Stats_item*>;
// Precomputation is needed.
long size = packets->getSize ();
tots = new PrUsage ();
for (long index = 0; index < size; index++)
{
temp = fetchPrUsage (index);
tots->pr_tstamp += temp->pr_tstamp;
tots->pr_create += temp->pr_create;
tots->pr_term += temp->pr_term;
tots->pr_rtime += temp->pr_rtime;
tots->pr_utime += temp->pr_utime;
tots->pr_stime += temp->pr_stime;
tots->pr_ttime += temp->pr_ttime;
tots->pr_tftime += temp->pr_tftime;
tots->pr_dftime += temp->pr_dftime;
tots->pr_kftime += temp->pr_kftime;
tots->pr_slptime += temp->pr_slptime;
tots->pr_ltime += temp->pr_ltime;
tots->pr_wtime += temp->pr_wtime;
tots->pr_stoptime += temp->pr_stoptime;
tots->pr_minf += temp->pr_minf;
tots->pr_majf += temp->pr_majf;
tots->pr_nswap += temp->pr_nswap;
tots->pr_inblk += temp->pr_inblk;
tots->pr_oublk += temp->pr_oublk;
tots->pr_msnd += temp->pr_msnd;
tots->pr_mrcv += temp->pr_mrcv;
tots->pr_sigs += temp->pr_sigs;
tots->pr_vctx += temp->pr_vctx;
tots->pr_ictx += temp->pr_ictx;
tots->pr_sysc += temp->pr_sysc;
tots->pr_ioch += temp->pr_ioch;
}
stats_item = create_stats_item ((long long) tots->pr_minf,
GTXT ("Minor Page Faults"));
stats_items->append (stats_item);
stats_item = create_stats_item ((long long) tots->pr_majf,
GTXT ("Major Page Faults"));
stats_items->append (stats_item);
stats_item = create_stats_item ((long long) tots->pr_nswap,
GTXT ("Process swaps"));
stats_items->append (stats_item);
stats_item = create_stats_item ((long long) tots->pr_inblk,
GTXT ("Input blocks"));
stats_items->append (stats_item);
stats_item = create_stats_item ((long long) tots->pr_oublk,
GTXT ("Output blocks"));
stats_items->append (stats_item);
stats_item = create_stats_item ((long long) tots->pr_msnd,
GTXT ("Messages sent"));
stats_items->append (stats_item);
stats_item = create_stats_item ((long long) tots->pr_mrcv,
GTXT ("Messages received"));
stats_items->append (stats_item);
stats_item = create_stats_item ((long long) tots->pr_sigs,
GTXT ("Signals handled"));
stats_items->append (stats_item);
stats_item = create_stats_item ((long long) tots->pr_vctx,
GTXT ("Voluntary context switches"));
stats_items->append (stats_item);
stats_item = create_stats_item ((long long) tots->pr_ictx,
GTXT ("Involuntary context switches"));
stats_items->append (stats_item);
stats_item = create_stats_item ((long long) tots->pr_sysc,
GTXT ("System calls"));
stats_items->append (stats_item);
stats_item = create_stats_item ((long long) tots->pr_ioch,
GTXT ("Characters of I/O"));
stats_items->append (stats_item);
delete tots;
}
|