1 /* Copyright (C) 2021-2024 Free Software Foundation, Inc.
4 This file is part of GNU Binutils.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3, or (at your option)
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, 51 Franklin Street - Fifth Floor, Boston,
19 MA 02110-1301, USA. */
22 //#include <search.h> // For the tsearch stuff
27 #include "Stats_data.h"
31 //XXX: The fundamental problem with this package of routines is that
32 //XXX: they should look a lot more like overview data. The result
33 //XXX: is that it is not possible to share as much code as would
34 //XXX: otherwise be possible.
39 // Return the number of Stats_item values associated with "this".
40 if (stats_items
== NULL
)
42 return stats_items
->size ();
45 Stats_data::Stats_item
46 Stats_data::fetch (int index
)
48 // Routine will return the "index"'th Stats_item associated with "this".
49 assert (index
>= 0 && index
< stats_items
->size ());
50 return *(stats_items
->fetch (index
));
53 Stats_data::Stats_data ()
55 // this constructor for use with sum()
60 Stats_data::Stats_data (DataView
*_packets
)
64 compute_data (); // reads all data
67 Stats_data::~Stats_data ()
71 stats_items
->destroy ();
77 Stats_data::sum (Stats_data
*data
)
80 Stats_item
*stats_item
, *data_item
;
81 if (stats_items
== NULL
)
83 stats_items
= new Vector
<Stats_item
*>;
84 Vec_loop (Stats_item
*, data
->stats_items
, index
, data_item
)
86 stats_item
= create_stats_item (data_item
->value
.ll
, data_item
->label
);
87 stats_items
->append (stats_item
);
92 Vec_loop (Stats_item
*, data
->stats_items
, index
, data_item
)
94 stats_items
->fetch (index
)->value
.ll
+= data_item
->value
.ll
;
99 Stats_data::Stats_item
*
100 Stats_data::create_stats_item (long long v
, char *l
)
102 Stats_data::Stats_item
*st_it
;
103 st_it
= new Stats_data::Stats_item
;
105 st_it
->value
.sign
= false;
107 st_it
->value
.tag
= VT_LLONG
;
112 Stats_data::fetchPrUsage (long index
)
114 // Return the data values corresponding to the "index"'th sample.
116 if (packets
->getSize () > 0)
118 Sample
* sample
= (Sample
*) packets
->getObjValue (PROP_SMPLOBJ
, index
);
119 prusage
= sample
->get_usage ();
127 Stats_data::compute_data ()
129 Stats_data::Stats_item
*stats_item
;
130 PrUsage
*tots
, *temp
;
131 stats_items
= new Vector
<Stats_data::Stats_item
*>;
133 // Precomputation is needed.
134 long size
= packets
->getSize ();
135 tots
= new PrUsage ();
136 for (long index
= 0; index
< size
; index
++)
138 temp
= fetchPrUsage (index
);
139 tots
->pr_tstamp
+= temp
->pr_tstamp
;
140 tots
->pr_create
+= temp
->pr_create
;
141 tots
->pr_term
+= temp
->pr_term
;
142 tots
->pr_rtime
+= temp
->pr_rtime
;
143 tots
->pr_utime
+= temp
->pr_utime
;
144 tots
->pr_stime
+= temp
->pr_stime
;
145 tots
->pr_ttime
+= temp
->pr_ttime
;
146 tots
->pr_tftime
+= temp
->pr_tftime
;
147 tots
->pr_dftime
+= temp
->pr_dftime
;
148 tots
->pr_kftime
+= temp
->pr_kftime
;
149 tots
->pr_slptime
+= temp
->pr_slptime
;
150 tots
->pr_ltime
+= temp
->pr_ltime
;
151 tots
->pr_wtime
+= temp
->pr_wtime
;
152 tots
->pr_stoptime
+= temp
->pr_stoptime
;
153 tots
->pr_minf
+= temp
->pr_minf
;
154 tots
->pr_majf
+= temp
->pr_majf
;
155 tots
->pr_nswap
+= temp
->pr_nswap
;
156 tots
->pr_inblk
+= temp
->pr_inblk
;
157 tots
->pr_oublk
+= temp
->pr_oublk
;
158 tots
->pr_msnd
+= temp
->pr_msnd
;
159 tots
->pr_mrcv
+= temp
->pr_mrcv
;
160 tots
->pr_sigs
+= temp
->pr_sigs
;
161 tots
->pr_vctx
+= temp
->pr_vctx
;
162 tots
->pr_ictx
+= temp
->pr_ictx
;
163 tots
->pr_sysc
+= temp
->pr_sysc
;
164 tots
->pr_ioch
+= temp
->pr_ioch
;
166 stats_item
= create_stats_item ((long long) tots
->pr_minf
,
167 GTXT ("Minor Page Faults"));
168 stats_items
->append (stats_item
);
169 stats_item
= create_stats_item ((long long) tots
->pr_majf
,
170 GTXT ("Major Page Faults"));
171 stats_items
->append (stats_item
);
172 stats_item
= create_stats_item ((long long) tots
->pr_nswap
,
173 GTXT ("Process swaps"));
174 stats_items
->append (stats_item
);
175 stats_item
= create_stats_item ((long long) tots
->pr_inblk
,
176 GTXT ("Input blocks"));
177 stats_items
->append (stats_item
);
178 stats_item
= create_stats_item ((long long) tots
->pr_oublk
,
179 GTXT ("Output blocks"));
180 stats_items
->append (stats_item
);
181 stats_item
= create_stats_item ((long long) tots
->pr_msnd
,
182 GTXT ("Messages sent"));
183 stats_items
->append (stats_item
);
184 stats_item
= create_stats_item ((long long) tots
->pr_mrcv
,
185 GTXT ("Messages received"));
186 stats_items
->append (stats_item
);
187 stats_item
= create_stats_item ((long long) tots
->pr_sigs
,
188 GTXT ("Signals handled"));
189 stats_items
->append (stats_item
);
190 stats_item
= create_stats_item ((long long) tots
->pr_vctx
,
191 GTXT ("Voluntary context switches"));
192 stats_items
->append (stats_item
);
193 stats_item
= create_stats_item ((long long) tots
->pr_ictx
,
194 GTXT ("Involuntary context switches"));
195 stats_items
->append (stats_item
);
196 stats_item
= create_stats_item ((long long) tots
->pr_sysc
,
197 GTXT ("System calls"));
198 stats_items
->append (stats_item
);
199 stats_item
= create_stats_item ((long long) tots
->pr_ioch
,
200 GTXT ("Characters of I/O"));
201 stats_items
->append (stats_item
);