*/
struct activity cpu_act = {
.id = A_CPU,
- .options = AO_COLLECTED + AO_VOLATILE + AO_GLOBAL_ITV + AO_MULTIPLE_OUTPUTS +
+ .options = AO_COLLECTED + AO_VOLATILE + AO_MULTIPLE_OUTPUTS +
AO_GRAPH_PER_ITEM,
.magic = ACTIVITY_MAGIC_BASE,
.group = G_DEFAULT,
#endif
struct stats_cpu *st_cpu[2];
-unsigned long long uptime[2] = {0, 0};
unsigned long long uptime0[2] = {0, 0};
+unsigned long long tot_jiffies[2] = {0, 0};
struct io_stats *st_iodev[2];
struct io_hdr_stats *st_hdr_iodev;
struct io_dlist *st_dev_list;
*
* IN:
* @curr Index in array for current sample statistics.
- * @itv Interval of time.
+ * @deltot_jiffies
+ * Number of jiffies spent on the interval by all processors.
***************************************************************************
*/
-void write_plain_cpu_stat(int curr, unsigned long long itv)
+void write_plain_cpu_stat(int curr, unsigned long long deltot_jiffies)
{
printf("avg-cpu: %%user %%nice %%system %%iowait %%steal %%idle\n");
printf(" ");
cprintf_pc(DISPLAY_UNIT(flags), 6, 7, 2,
- ll_sp_value(st_cpu[!curr]->cpu_user, st_cpu[curr]->cpu_user, itv),
- ll_sp_value(st_cpu[!curr]->cpu_nice, st_cpu[curr]->cpu_nice, itv),
+ ll_sp_value(st_cpu[!curr]->cpu_user, st_cpu[curr]->cpu_user, deltot_jiffies),
+ ll_sp_value(st_cpu[!curr]->cpu_nice, st_cpu[curr]->cpu_nice, deltot_jiffies),
/*
* Time spent in system mode also includes time spent servicing
* hard and soft interrupts.
ll_sp_value(st_cpu[!curr]->cpu_sys + st_cpu[!curr]->cpu_softirq +
st_cpu[!curr]->cpu_hardirq,
st_cpu[curr]->cpu_sys + st_cpu[curr]->cpu_softirq +
- st_cpu[curr]->cpu_hardirq, itv),
- ll_sp_value(st_cpu[!curr]->cpu_iowait, st_cpu[curr]->cpu_iowait, itv),
- ll_sp_value(st_cpu[!curr]->cpu_steal, st_cpu[curr]->cpu_steal, itv),
+ st_cpu[curr]->cpu_hardirq, deltot_jiffies),
+ ll_sp_value(st_cpu[!curr]->cpu_iowait, st_cpu[curr]->cpu_iowait, deltot_jiffies),
+ ll_sp_value(st_cpu[!curr]->cpu_steal, st_cpu[curr]->cpu_steal, deltot_jiffies),
(st_cpu[curr]->cpu_idle < st_cpu[!curr]->cpu_idle) ?
0.0 :
- ll_sp_value(st_cpu[!curr]->cpu_idle, st_cpu[curr]->cpu_idle, itv));
+ ll_sp_value(st_cpu[!curr]->cpu_idle, st_cpu[curr]->cpu_idle, deltot_jiffies));
printf("\n\n");
}
* IN:
* @tab Number of tabs to print.
* @curr Index in array for current sample statistics.
- * @itv Interval of time.
+ * @deltot_jiffies
+ * Number of jiffies spent on the interval by all processors.
***************************************************************************
*/
-void write_json_cpu_stat(int tab, int curr, unsigned long long itv)
+void write_json_cpu_stat(int tab, int curr, unsigned long long deltot_jiffies)
{
xprintf0(tab, "\"avg-cpu\": {\"user\": %.2f, \"nice\": %.2f, \"system\": %.2f,"
" \"iowait\": %.2f, \"steal\": %.2f, \"idle\": %.2f}",
- ll_sp_value(st_cpu[!curr]->cpu_user, st_cpu[curr]->cpu_user, itv),
- ll_sp_value(st_cpu[!curr]->cpu_nice, st_cpu[curr]->cpu_nice, itv),
+ ll_sp_value(st_cpu[!curr]->cpu_user, st_cpu[curr]->cpu_user, deltot_jiffies),
+ ll_sp_value(st_cpu[!curr]->cpu_nice, st_cpu[curr]->cpu_nice, deltot_jiffies),
/*
* Time spent in system mode also includes time spent servicing
* hard and soft interrupts.
ll_sp_value(st_cpu[!curr]->cpu_sys + st_cpu[!curr]->cpu_softirq +
st_cpu[!curr]->cpu_hardirq,
st_cpu[curr]->cpu_sys + st_cpu[curr]->cpu_softirq +
- st_cpu[curr]->cpu_hardirq, itv),
- ll_sp_value(st_cpu[!curr]->cpu_iowait, st_cpu[curr]->cpu_iowait, itv),
- ll_sp_value(st_cpu[!curr]->cpu_steal, st_cpu[curr]->cpu_steal, itv),
+ st_cpu[curr]->cpu_hardirq, deltot_jiffies),
+ ll_sp_value(st_cpu[!curr]->cpu_iowait, st_cpu[curr]->cpu_iowait, deltot_jiffies),
+ ll_sp_value(st_cpu[!curr]->cpu_steal, st_cpu[curr]->cpu_steal, deltot_jiffies),
(st_cpu[curr]->cpu_idle < st_cpu[!curr]->cpu_idle) ?
0.0 :
- ll_sp_value(st_cpu[!curr]->cpu_idle, st_cpu[curr]->cpu_idle, itv));
+ ll_sp_value(st_cpu[!curr]->cpu_idle, st_cpu[curr]->cpu_idle, deltot_jiffies));
}
/*
*
* IN:
* @curr Index in array for current sample statistics.
- * @itv Interval of time.
* @tab Number of tabs to print (JSON format only).
***************************************************************************
*/
-void write_cpu_stat(int curr, unsigned long long itv, int tab)
+void write_cpu_stat(int curr, int tab)
{
+ unsigned long long deltot_jiffies;
+
+ /*
+ * Compute the total number of jiffies spent by all processors.
+ * NB: Don't add cpu_guest/cpu_guest_nice because cpu_user/cpu_nice
+ * already include them.
+ */
+ tot_jiffies[curr] = st_cpu[curr]->cpu_user + st_cpu[curr]->cpu_nice +
+ st_cpu[curr]->cpu_sys + st_cpu[curr]->cpu_idle +
+ st_cpu[curr]->cpu_iowait + st_cpu[curr]->cpu_hardirq +
+ st_cpu[curr]->cpu_steal + st_cpu[curr]->cpu_softirq;
+
+ /* Total number of jiffies spent on the interval */
+ deltot_jiffies = get_interval(tot_jiffies[!curr], tot_jiffies[curr]);
+
+#ifdef DEBUG
+ if (DISPLAY_DEBUG(flags)) {
+ /* Debug output */
+ fprintf(stderr, "deltot_jiffies=%llu st_cpu[curr]{ cpu_user=%llu cpu_nice=%llu "
+ "cpu_sys=%llu cpu_idle=%llu cpu_iowait=%llu cpu_steal=%llu "
+ "cpu_hardirq=%llu cpu_softirq=%llu cpu_guest=%llu "
+ "cpu_guest_nice=%llu }\n",
+ deltot_jiffies,
+ st_cpu[curr]->cpu_user,
+ st_cpu[curr]->cpu_nice,
+ st_cpu[curr]->cpu_sys,
+ st_cpu[curr]->cpu_idle,
+ st_cpu[curr]->cpu_iowait,
+ st_cpu[curr]->cpu_steal,
+ st_cpu[curr]->cpu_hardirq,
+ st_cpu[curr]->cpu_softirq,
+ st_cpu[curr]->cpu_guest,
+ st_cpu[curr]->cpu_guest_nice);
+ }
+#endif
+
if (DISPLAY_JSON_OUTPUT(flags)) {
- write_json_cpu_stat(tab, curr, itv);
+ write_json_cpu_stat(tab, curr, deltot_jiffies);
}
else {
- write_plain_cpu_stat(curr, itv);
+ write_plain_cpu_stat(curr, deltot_jiffies);
}
}
#endif
}
- /* Interval is multiplied by the number of processors */
- itv = get_interval(uptime[!curr], uptime[curr]);
-
if (DISPLAY_CPU(flags)) {
-#ifdef DEBUG
- if (DISPLAY_DEBUG(flags)) {
- /* Debug output */
- fprintf(stderr, "itv=%llu st_cpu[curr]{ cpu_user=%llu cpu_nice=%llu "
- "cpu_sys=%llu cpu_idle=%llu cpu_iowait=%llu cpu_steal=%llu "
- "cpu_hardirq=%llu cpu_softirq=%llu cpu_guest=%llu "
- "cpu_guest_nice=%llu }\n",
- itv,
- st_cpu[curr]->cpu_user,
- st_cpu[curr]->cpu_nice,
- st_cpu[curr]->cpu_sys,
- st_cpu[curr]->cpu_idle,
- st_cpu[curr]->cpu_iowait,
- st_cpu[curr]->cpu_steal,
- st_cpu[curr]->cpu_hardirq,
- st_cpu[curr]->cpu_softirq,
- st_cpu[curr]->cpu_guest,
- st_cpu[curr]->cpu_guest_nice);
- }
-#endif
-
/* Display CPU utilization */
- write_cpu_stat(curr, itv, tab);
+ write_cpu_stat(curr, tab);
if (DISPLAY_JSON_OUTPUT(flags)) {
if (DISPLAY_DISK(flags)) {
}
}
- if (cpu_nr > 1) {
- /* On SMP machines, reduce itv to one processor (see note above) */
- itv = get_interval(uptime0[!curr], uptime0[curr]);
- }
+ /* Calculate time interval in jiffies */
+ itv = get_interval(uptime0[!curr], uptime0[curr]);
if (DISPLAY_DISK(flags)) {
struct io_stats *ioi, *ioj;
setbuf(stdout, NULL);
do {
- if (cpu_nr > 1) {
- /* Read system uptime (only for SMP machines) */
- read_uptime(&(uptime0[curr]));
- }
+ /* Read system uptime (only for SMP machines) */
+ read_uptime(&(uptime0[curr]));
- /* Read stats for CPU "all" and system uptime in jiffies */
- read_stat_cpu(st_cpu[curr], 1, &(uptime[curr]));
+ /* Read stats for CPU "all" */
+ read_stat_cpu(st_cpu[curr], 1);
if (dlist_idx) {
/*
* @a Activity structure with statistics.
* @curr Index in array for current sample statistics.
* @tab Indentation in output.
- * @g_itv Interval of time in jiffies mutliplied by the number of
- * processors.
+ * @itv Interval of time in jiffies (independent of the number of
+ * processors). Unused here.
***************************************************************************
*/
__print_funct_t json_print_cpu_stats(struct activity *a, int curr, int tab,
- unsigned long long g_itv)
+ unsigned long long itv)
{
int i, cpu_offline;
int sep = FALSE;
+ unsigned long long tot_jiffies[3];
+ unsigned long long deltot_jiffies;
struct stats_cpu *scc, *scp;
char cpuno[8];
/* No */
continue;
- /* Yes: Display current CPU stats */
+ /*
+ * Yes: Compute the total number of jiffies spent by current processor.
+ * NB: Don't add cpu_guest/cpu_guest_nice because cpu_user/cpu_nice
+ * already include them.
+ */
+ tot_jiffies[curr] = scc->cpu_user + scc->cpu_nice +
+ scc->cpu_sys + scc->cpu_idle +
+ scc->cpu_iowait + scc->cpu_hardirq +
+ scc->cpu_steal + scc->cpu_softirq;
+ tot_jiffies[!curr] = scp->cpu_user + scp->cpu_nice +
+ scp->cpu_sys + scp->cpu_idle +
+ scp->cpu_iowait + scp->cpu_hardirq +
+ scp->cpu_steal + scp->cpu_softirq;
+
+ /* Total number of jiffies spent on the interval */
+ deltot_jiffies = get_interval(tot_jiffies[!curr], tot_jiffies[curr]);
if (sep) {
printf(",\n");
* (Remember that guest/guest_nice times are already included in
* user/nice modes.)
*/
- if ((scc->cpu_user + scc->cpu_nice + scc->cpu_sys +
- scc->cpu_iowait + scc->cpu_idle + scc->cpu_steal +
- scc->cpu_hardirq + scc->cpu_softirq) == 0) {
+ if (tot_jiffies[curr] == 0) {
/*
* Set current struct fields (which have been set to zero)
* to values from previous iteration. Hence their values won't
*/
*scc = *scp;
- g_itv = 0;
+ deltot_jiffies = 0;
cpu_offline = TRUE;
}
else {
* Recalculate interval for current proc.
* If result is 0 then current CPU is a tickless one.
*/
- g_itv = get_per_cpu_interval(scc, scp);
+ deltot_jiffies = get_per_cpu_interval(scc, scp);
cpu_offline = FALSE;
}
- if (!g_itv) {
+ if (!deltot_jiffies) {
/* Current CPU is offline or tickless */
if (DISPLAY_CPU_DEF(a->opt_flags)) {
xprintf0(tab, "{\"cpu\": \"%d\", "
"\"steal\": %.2f, "
"\"idle\": %.2f}",
cpuno,
- ll_sp_value(scp->cpu_user, scc->cpu_user, g_itv),
- ll_sp_value(scp->cpu_nice, scc->cpu_nice, g_itv),
+ ll_sp_value(scp->cpu_user, scc->cpu_user, deltot_jiffies),
+ ll_sp_value(scp->cpu_nice, scc->cpu_nice, deltot_jiffies),
ll_sp_value(scp->cpu_sys + scp->cpu_hardirq + scp->cpu_softirq,
scc->cpu_sys + scc->cpu_hardirq + scc->cpu_softirq,
- g_itv),
- ll_sp_value(scp->cpu_iowait, scc->cpu_iowait, g_itv),
- ll_sp_value(scp->cpu_steal, scc->cpu_steal, g_itv),
+ deltot_jiffies),
+ ll_sp_value(scp->cpu_iowait, scc->cpu_iowait, deltot_jiffies),
+ ll_sp_value(scp->cpu_steal, scc->cpu_steal, deltot_jiffies),
scc->cpu_idle < scp->cpu_idle ?
0.0 :
- ll_sp_value(scp->cpu_idle, scc->cpu_idle, g_itv));
+ ll_sp_value(scp->cpu_idle, scc->cpu_idle, deltot_jiffies));
}
else if (DISPLAY_CPU_ALL(a->opt_flags)) {
xprintf0(tab, "{\"cpu\": \"%s\", "
(scc->cpu_user - scc->cpu_guest) < (scp->cpu_user - scp->cpu_guest) ?
0.0 :
ll_sp_value(scp->cpu_user - scp->cpu_guest,
- scc->cpu_user - scc->cpu_guest, g_itv),
+ scc->cpu_user - scc->cpu_guest, deltot_jiffies),
(scc->cpu_nice - scc->cpu_guest_nice) < (scp->cpu_nice - scp->cpu_guest_nice) ?
0.0 :
ll_sp_value(scp->cpu_nice - scp->cpu_guest_nice,
- scc->cpu_nice - scc->cpu_guest_nice, g_itv),
- ll_sp_value(scp->cpu_sys, scc->cpu_sys, g_itv),
- ll_sp_value(scp->cpu_iowait, scc->cpu_iowait, g_itv),
- ll_sp_value(scp->cpu_steal, scc->cpu_steal, g_itv),
- ll_sp_value(scp->cpu_hardirq, scc->cpu_hardirq, g_itv),
- ll_sp_value(scp->cpu_softirq, scc->cpu_softirq, g_itv),
- ll_sp_value(scp->cpu_guest, scc->cpu_guest, g_itv),
- ll_sp_value(scp->cpu_guest_nice, scc->cpu_guest_nice, g_itv),
+ scc->cpu_nice - scc->cpu_guest_nice, deltot_jiffies),
+ ll_sp_value(scp->cpu_sys, scc->cpu_sys, deltot_jiffies),
+ ll_sp_value(scp->cpu_iowait, scc->cpu_iowait, deltot_jiffies),
+ ll_sp_value(scp->cpu_steal, scc->cpu_steal, deltot_jiffies),
+ ll_sp_value(scp->cpu_hardirq, scc->cpu_hardirq, deltot_jiffies),
+ ll_sp_value(scp->cpu_softirq, scc->cpu_softirq, deltot_jiffies),
+ ll_sp_value(scp->cpu_guest, scc->cpu_guest, deltot_jiffies),
+ ll_sp_value(scp->cpu_guest_nice, scc->cpu_guest_nice, deltot_jiffies),
scc->cpu_idle < scp->cpu_idle ?
0.0 :
- ll_sp_value(scp->cpu_idle, scc->cpu_idle, g_itv));
+ ll_sp_value(scp->cpu_idle, scc->cpu_idle, deltot_jiffies));
}
}
char *sccsid(void) { return (SCCSID); }
#endif
-unsigned long long uptime[3] = {0, 0, 0};
+unsigned long long tot_jiffies[3] = {0, 0, 0};
unsigned long long uptime0[3] = {0, 0, 0};
/* NOTE: Use array of _char_ for bitmaps to avoid endianness problems...*/
*
* IN:
* @dis TRUE if a header line must be printed.
- * @g_itv Interval value in jiffies multiplied by the number of CPU.
+ * @deltot_jiffies
+ * Number of jiffies spent on the interval by all processors.
* @prev Position in array where statistics used as reference are.
* Stats used as reference may be the previous ones read, or
* the very first ones when calculating the average.
* when displaying average stats.
***************************************************************************
*/
-void write_plain_cpu_stats(int dis, unsigned long long g_itv, int prev, int curr,
+void write_plain_cpu_stats(int dis, unsigned long long deltot_jiffies, int prev, int curr,
char *prev_string, char *curr_string)
{
struct stats_cpu *scc, *scp;
0.0 :
ll_sp_value(st_cpu[prev]->cpu_user - st_cpu[prev]->cpu_guest,
st_cpu[curr]->cpu_user - st_cpu[curr]->cpu_guest,
- g_itv),
+ deltot_jiffies),
(st_cpu[curr]->cpu_nice - st_cpu[curr]->cpu_guest_nice) <
(st_cpu[prev]->cpu_nice - st_cpu[prev]->cpu_guest_nice) ?
0.0 :
ll_sp_value(st_cpu[prev]->cpu_nice - st_cpu[prev]->cpu_guest_nice,
st_cpu[curr]->cpu_nice - st_cpu[curr]->cpu_guest_nice,
- g_itv),
+ deltot_jiffies),
ll_sp_value(st_cpu[prev]->cpu_sys,
st_cpu[curr]->cpu_sys,
- g_itv),
+ deltot_jiffies),
ll_sp_value(st_cpu[prev]->cpu_iowait,
st_cpu[curr]->cpu_iowait,
- g_itv),
+ deltot_jiffies),
ll_sp_value(st_cpu[prev]->cpu_hardirq,
st_cpu[curr]->cpu_hardirq,
- g_itv),
+ deltot_jiffies),
ll_sp_value(st_cpu[prev]->cpu_softirq,
st_cpu[curr]->cpu_softirq,
- g_itv),
+ deltot_jiffies),
ll_sp_value(st_cpu[prev]->cpu_steal,
st_cpu[curr]->cpu_steal,
- g_itv),
+ deltot_jiffies),
ll_sp_value(st_cpu[prev]->cpu_guest,
st_cpu[curr]->cpu_guest,
- g_itv),
+ deltot_jiffies),
ll_sp_value(st_cpu[prev]->cpu_guest_nice,
st_cpu[curr]->cpu_guest_nice,
- g_itv),
+ deltot_jiffies),
(st_cpu[curr]->cpu_idle < st_cpu[prev]->cpu_idle) ?
0.0 :
ll_sp_value(st_cpu[prev]->cpu_idle,
st_cpu[curr]->cpu_idle,
- g_itv));
+ deltot_jiffies));
printf("\n");
}
*
* IN:
* @tab Number of tabs to print.
- * @g_itv Interval value in jiffies multiplied by the number of CPU.
+ * @deltot_jiffies
+ * Number of jiffies spent on the interval by all processors.
* @prev Position in array where statistics used as reference are.
* Stats used as reference may be the previous ones read, or
* the very first ones when calculating the average.
* @curr Position in array where current statistics will be saved.
***************************************************************************
*/
-void write_json_cpu_stats(int tab, unsigned long long g_itv, int prev, int curr)
+void write_json_cpu_stats(int tab, unsigned long long deltot_jiffies, int prev, int curr)
{
struct stats_cpu *scc, *scp;
unsigned long long pc_itv;
0.0 :
ll_sp_value(st_cpu[prev]->cpu_user - st_cpu[prev]->cpu_guest,
st_cpu[curr]->cpu_user - st_cpu[curr]->cpu_guest,
- g_itv),
+ deltot_jiffies),
(st_cpu[curr]->cpu_nice - st_cpu[curr]->cpu_guest_nice) <
(st_cpu[prev]->cpu_nice - st_cpu[prev]->cpu_guest_nice) ?
0.0 :
ll_sp_value(st_cpu[prev]->cpu_nice - st_cpu[prev]->cpu_guest_nice,
st_cpu[curr]->cpu_nice - st_cpu[curr]->cpu_guest_nice,
- g_itv),
+ deltot_jiffies),
ll_sp_value(st_cpu[prev]->cpu_sys,
st_cpu[curr]->cpu_sys,
- g_itv),
+ deltot_jiffies),
ll_sp_value(st_cpu[prev]->cpu_iowait,
st_cpu[curr]->cpu_iowait,
- g_itv),
+ deltot_jiffies),
ll_sp_value(st_cpu[prev]->cpu_hardirq,
st_cpu[curr]->cpu_hardirq,
- g_itv),
+ deltot_jiffies),
ll_sp_value(st_cpu[prev]->cpu_softirq,
st_cpu[curr]->cpu_softirq,
- g_itv),
+ deltot_jiffies),
ll_sp_value(st_cpu[prev]->cpu_steal,
st_cpu[curr]->cpu_steal,
- g_itv),
+ deltot_jiffies),
ll_sp_value(st_cpu[prev]->cpu_guest,
st_cpu[curr]->cpu_guest,
- g_itv),
+ deltot_jiffies),
ll_sp_value(st_cpu[prev]->cpu_guest_nice,
st_cpu[curr]->cpu_guest_nice,
- g_itv),
+ deltot_jiffies),
(st_cpu[curr]->cpu_idle < st_cpu[prev]->cpu_idle) ?
0.0 :
ll_sp_value(st_cpu[prev]->cpu_idle,
st_cpu[curr]->cpu_idle,
- g_itv));
+ deltot_jiffies));
}
for (cpu = 1; cpu <= cpu_nr; cpu++) {
*
* IN:
* @dis TRUE if a header line must be printed.
- * @g_itv Interval value in jiffies multiplied by the number of CPU.
+ * @deltot_jiffies
+ * Number of jiffies spent on the interval by all processors.
* @prev Position in array where statistics used as reference are.
* Stats used as reference may be the previous ones read, or
* the very first ones when calculating the average.
* only).
***************************************************************************
*/
-void write_cpu_stats(int dis, unsigned long long g_itv, int prev, int curr,
+void write_cpu_stats(int dis, unsigned long long deltot_jiffies, int prev, int curr,
char *prev_string, char *curr_string, int tab, int *next)
{
if (DISPLAY_JSON_OUTPUT(flags)) {
printf(",\n");
}
*next = TRUE;
- write_json_cpu_stats(tab, g_itv, prev, curr);
+ write_json_cpu_stats(tab, deltot_jiffies, prev, curr);
}
else {
- write_plain_cpu_stats(dis, g_itv, prev, curr, prev_string, curr_string);
+ write_plain_cpu_stats(dis, deltot_jiffies, prev, curr, prev_string, curr_string);
}
}
*
* IN:
* @dis TRUE if a header line must be printed.
- * @g_itv Interval value in jiffies multiplied by the number of CPU.
+ * @deltot_jiffies
+ * Number of jiffies spent on the interval by all processors.
* @itv Interval value.
* @prev Position in array where statistics used as reference are.
* Stats used as reference may be the previous ones read, or
* when displaying average stats.
***************************************************************************
*/
-void write_plain_node_stats(int dis, unsigned long long g_itv, unsigned long long itv,
+void write_plain_node_stats(int dis, unsigned long long deltot_jiffies, unsigned long long itv,
int prev, int curr, char *prev_string, char *curr_string)
{
struct stats_cpu *snc, *snp;
0.0 :
ll_sp_value(st_cpu[prev]->cpu_user - st_cpu[prev]->cpu_guest,
st_cpu[curr]->cpu_user - st_cpu[curr]->cpu_guest,
- g_itv),
+ deltot_jiffies),
(st_cpu[curr]->cpu_nice - st_cpu[curr]->cpu_guest_nice) <
(st_cpu[prev]->cpu_nice - st_cpu[prev]->cpu_guest_nice) ?
0.0 :
ll_sp_value(st_cpu[prev]->cpu_nice - st_cpu[prev]->cpu_guest_nice,
st_cpu[curr]->cpu_nice - st_cpu[curr]->cpu_guest_nice,
- g_itv),
+ deltot_jiffies),
ll_sp_value(st_cpu[prev]->cpu_sys,
st_cpu[curr]->cpu_sys,
- g_itv),
+ deltot_jiffies),
ll_sp_value(st_cpu[prev]->cpu_iowait,
st_cpu[curr]->cpu_iowait,
- g_itv),
+ deltot_jiffies),
ll_sp_value(st_cpu[prev]->cpu_hardirq,
st_cpu[curr]->cpu_hardirq,
- g_itv),
+ deltot_jiffies),
ll_sp_value(st_cpu[prev]->cpu_softirq,
st_cpu[curr]->cpu_softirq,
- g_itv),
+ deltot_jiffies),
ll_sp_value(st_cpu[prev]->cpu_steal,
st_cpu[curr]->cpu_steal,
- g_itv),
+ deltot_jiffies),
ll_sp_value(st_cpu[prev]->cpu_guest,
st_cpu[curr]->cpu_guest,
- g_itv),
+ deltot_jiffies),
ll_sp_value(st_cpu[prev]->cpu_guest_nice,
st_cpu[curr]->cpu_guest_nice,
- g_itv),
+ deltot_jiffies),
(st_cpu[curr]->cpu_idle < st_cpu[prev]->cpu_idle) ?
0.0 :
ll_sp_value(st_cpu[prev]->cpu_idle,
st_cpu[curr]->cpu_idle,
- g_itv));
+ deltot_jiffies));
printf("\n");
}
*
* IN:
* @tab Number of tabs to print.
- * @g_itv Interval value in jiffies multiplied by the number of CPU.
+ * @deltot_jiffies
+ * Number of jiffies spent on the interval by all processors.
* @itv Interval value.
* @prev Position in array where statistics used as reference are.
* Stats used as reference may be the previous ones read, or
* @curr Position in array where current statistics will be saved.
***************************************************************************
*/
-void write_json_node_stats(int tab, unsigned long long g_itv, unsigned long long itv,
+void write_json_node_stats(int tab, unsigned long long deltot_jiffies, unsigned long long itv,
int prev, int curr)
{
struct stats_cpu *snc, *snp;
0.0 :
ll_sp_value(st_cpu[prev]->cpu_user - st_cpu[prev]->cpu_guest,
st_cpu[curr]->cpu_user - st_cpu[curr]->cpu_guest,
- g_itv),
+ deltot_jiffies),
(st_cpu[curr]->cpu_nice - st_cpu[curr]->cpu_guest_nice) <
(st_cpu[prev]->cpu_nice - st_cpu[prev]->cpu_guest_nice) ?
0.0 :
ll_sp_value(st_cpu[prev]->cpu_nice - st_cpu[prev]->cpu_guest_nice,
st_cpu[curr]->cpu_nice - st_cpu[curr]->cpu_guest_nice,
- g_itv),
+ deltot_jiffies),
ll_sp_value(st_cpu[prev]->cpu_sys,
st_cpu[curr]->cpu_sys,
- g_itv),
+ deltot_jiffies),
ll_sp_value(st_cpu[prev]->cpu_iowait,
st_cpu[curr]->cpu_iowait,
- g_itv),
+ deltot_jiffies),
ll_sp_value(st_cpu[prev]->cpu_hardirq,
st_cpu[curr]->cpu_hardirq,
- g_itv),
+ deltot_jiffies),
ll_sp_value(st_cpu[prev]->cpu_softirq,
st_cpu[curr]->cpu_softirq,
- g_itv),
+ deltot_jiffies),
ll_sp_value(st_cpu[prev]->cpu_steal,
st_cpu[curr]->cpu_steal,
- g_itv),
+ deltot_jiffies),
ll_sp_value(st_cpu[prev]->cpu_guest,
st_cpu[curr]->cpu_guest,
- g_itv),
+ deltot_jiffies),
ll_sp_value(st_cpu[prev]->cpu_guest_nice,
st_cpu[curr]->cpu_guest_nice,
- g_itv),
+ deltot_jiffies),
(st_cpu[curr]->cpu_idle < st_cpu[prev]->cpu_idle) ?
0.0 :
ll_sp_value(st_cpu[prev]->cpu_idle,
st_cpu[curr]->cpu_idle,
- g_itv));
+ deltot_jiffies));
}
for (node = 0; node <= node_nr; node++) {
*
* IN:
* @dis TRUE if a header line must be printed.
- * @g_itv Interval value in jiffies multiplied by the number of CPU.
+ * @deltot_jiffies
+ * Number of jiffies spent on the interval by all processors.
* @itv Interval value.
* @prev Position in array where statistics used as reference are.
* Stats used as reference may be the previous ones read, or
* only).
***************************************************************************
*/
-void write_node_stats(int dis, unsigned long long g_itv, unsigned long long itv,
+void write_node_stats(int dis, unsigned long long deltot_jiffies, unsigned long long itv,
int prev, int curr, char *prev_string, char *curr_string,
int tab, int *next)
{
printf(",\n");
}
*next = TRUE;
- write_json_node_stats(tab, g_itv, itv, prev, curr);
+ write_json_node_stats(tab, deltot_jiffies, itv, prev, curr);
}
else {
- write_plain_node_stats(dis, g_itv, itv, prev, curr, prev_string, curr_string);
+ write_plain_node_stats(dis, deltot_jiffies, itv, prev, curr,
+ prev_string, curr_string);
}
}
char *prev_string, char *curr_string)
{
struct stats_cpu *scc, *scp;
- unsigned long long itv, g_itv;
+ unsigned long long itv, deltot_jiffies;
int cpu, tab = 4, next = FALSE;
/* Test stdout */
xprintf(tab, "\"timestamp\": \"%s\",", curr_string);
}
- /* Compute time interval */
- g_itv = get_interval(uptime[prev], uptime[curr]);
+ /*
+ * Compute the total number of jiffies spent by all processors.
+ * NB: Don't add cpu_guest/cpu_guest_nice because cpu_user/cpu_nice
+ * already include them.
+ */
+ tot_jiffies[curr] = st_cpu[curr]->cpu_user + st_cpu[curr]->cpu_nice +
+ st_cpu[curr]->cpu_sys + st_cpu[curr]->cpu_idle +
+ st_cpu[curr]->cpu_iowait + st_cpu[curr]->cpu_hardirq +
+ st_cpu[curr]->cpu_steal + st_cpu[curr]->cpu_softirq;
+ /* Total number of jiffies spent on the interval */
+ deltot_jiffies = get_interval(tot_jiffies[prev], tot_jiffies[curr]);
- /* Reduce interval value to one processor */
- if (cpu_nr > 1) {
- itv = get_interval(uptime0[prev], uptime0[curr]);
- }
- else {
- itv = g_itv;
- }
+ /* Get time interval */
+ itv = get_interval(uptime0[prev], uptime0[curr]);
/* Print CPU stats */
if (DISPLAY_CPU(actflags)) {
- write_cpu_stats(dis, g_itv, prev, curr, prev_string, curr_string,
- tab, &next);
+ write_cpu_stats(dis, deltot_jiffies, prev, curr, prev_string,
+ curr_string, tab, &next);
}
/* Print node CPU stats */
if (DISPLAY_NODE(actflags)) {
- write_node_stats(dis, g_itv, itv, prev, curr, prev_string, curr_string,
- tab, &next);
+ write_node_stats(dis, deltot_jiffies, itv, prev, curr, prev_string,
+ curr_string, tab, &next);
}
/* Print total number of interrupts per processor */
/* Dont buffer data if redirected to a pipe */
setbuf(stdout, NULL);
- /* Read uptime and CPU stats */
- if (cpu_nr > 1) {
- /* Read system uptime (only for SMP machines) */
- read_uptime(&(uptime0[0]));
- }
- read_stat_cpu(st_cpu[0], cpu_nr + 1, &(uptime[0]));
+ /* Read system uptime and CPU stats */
+ read_uptime(&(uptime0[0]));
+ read_stat_cpu(st_cpu[0], cpu_nr + 1);
+ tot_jiffies[0] = st_cpu[0]->cpu_user + st_cpu[0]->cpu_nice +
+ st_cpu[0]->cpu_sys + st_cpu[0]->cpu_idle +
+ st_cpu[0]->cpu_iowait + st_cpu[0]->cpu_hardirq +
+ st_cpu[0]->cpu_steal + st_cpu[0]->cpu_softirq;
if (DISPLAY_NODE(actflags)) {
set_node_cpu_stats(st_node[0], st_cpu[0]);
}
/* Save the first stats collected. Will be used to compute the average */
mp_tstamp[2] = mp_tstamp[0];
- uptime[2] = uptime[0];
+ tot_jiffies[2] = tot_jiffies[0];
uptime0[2] = uptime0[0];
memcpy(st_cpu[2], st_cpu[0], STATS_CPU_SIZE * (cpu_nr + 1));
memcpy(st_node[2], st_node[0], STATS_CPU_SIZE * (cpu_nr + 1));
get_localtime(&(mp_tstamp[curr]), 0);
/* Read uptime and CPU stats */
- if (cpu_nr > 1) {
- read_uptime(&(uptime0[curr]));
- }
- read_stat_cpu(st_cpu[curr], cpu_nr + 1, &(uptime[curr]));
+ read_uptime(&(uptime0[curr]));
+ read_stat_cpu(st_cpu[curr], cpu_nr + 1);
if (DISPLAY_NODE(actflags)) {
set_node_cpu_stats(st_node[curr], st_cpu[curr]);
}
char *sccsid(void) { return (SCCSID); }
#endif
-unsigned long long uptime[3] = {0, 0, 0};
+unsigned long long tot_jiffies[3] = {0, 0, 0};
unsigned long long uptime0[3] = {0, 0, 0};
struct pid_stats *st_pid_list[3] = {NULL, NULL, NULL};
unsigned int *pid_array = NULL;
perror("malloc");
exit(4);
}
- /* Read statistics for CPUs "all" and system uptime (in jiffies) */
- read_stat_cpu(st_cpu, 1, &uptime[curr]);
+ /* Read statistics for CPUs "all" */
+ read_stat_cpu(st_cpu, 1);
+
+ /*
+ * Compute the total number of jiffies spent by all processors.
+ * NB: Don't add cpu_guest/cpu_guest_nice because cpu_user/cpu_nice
+ * already include them.
+ */
+ tot_jiffies[curr] = st_cpu->cpu_user + st_cpu->cpu_nice +
+ st_cpu->cpu_sys + st_cpu->cpu_idle +
+ st_cpu->cpu_iowait + st_cpu->cpu_hardirq +
+ st_cpu->cpu_steal + st_cpu->cpu_softirq;
free(st_cpu);
if (DISPLAY_ALL_PID(pidflag)) {
* @curr_string String displayed at the beginning of current sample stats.
* This is the timestamp of the current sample.
* @itv Interval of time in jiffies.
- * @g_itv Interval of time in jiffies multiplied by the number of
- * processors.
+ * @deltot_jiffies
+ * Number of jiffies spent on the interval by all processors.
*
* RETURNS:
* 0 if all the processes to display have terminated.
int write_pid_task_all_stats(int prev, int curr, int dis,
char *prev_string, char *curr_string,
unsigned long long itv,
- unsigned long long g_itv)
+ unsigned long long deltot_jiffies)
{
struct pid_stats *pstc, *pstp;
char dstr[32];
/* User time already includes guest time */
IRIX_MODE_OFF(pidflag) ?
SP_VALUE_100(pstp->utime + pstp->stime,
- pstc->utime + pstc->stime, g_itv) :
+ pstc->utime + pstc->stime, deltot_jiffies) :
SP_VALUE_100(pstp->utime + pstp->stime,
pstc->utime + pstc->stime, itv));
* This is the timestamp of the current sample, or "Average"
* when displaying average stats.
* @itv Interval of time in jiffies.
- * @g_itv Interval of time in jiffies multiplied by the number of
- * processors.
+ * @deltot_jiffies
+ * Number of jiffies spent on the interval by all processors.
*
* RETURNS:
* 0 if all the processes to display have terminated.
int write_pid_task_cpu_stats(int prev, int curr, int dis, int disp_avg,
char *prev_string, char *curr_string,
unsigned long long itv,
- unsigned long long g_itv)
+ unsigned long long deltot_jiffies)
{
struct pid_stats *pstc, *pstp;
unsigned int p;
/* User time already includes guest time */
IRIX_MODE_OFF(pidflag) ?
SP_VALUE_100(pstp->utime + pstp->stime,
- pstc->utime + pstc->stime, g_itv) :
+ pstc->utime + pstc->stime, deltot_jiffies) :
SP_VALUE_100(pstp->utime + pstp->stime,
pstc->utime + pstc->stime, itv));
int write_stats_core(int prev, int curr, int dis, int disp_avg,
char *prev_string, char *curr_string)
{
- unsigned long long itv, g_itv;
+ unsigned long long itv, deltot_jiffies;
int again = 0;
/* Test stdout */
TEST_STDOUT(STDOUT_FILENO);
- /* g_itv is multiplied by the number of processors */
- g_itv = get_interval(uptime[prev], uptime[curr]);
+ /* Total number of jiffies spent on the interval */
+ deltot_jiffies = get_interval(tot_jiffies[prev], tot_jiffies[curr]);
- if (cpu_nr > 1) {
- /* SMP machines */
- itv = get_interval(uptime0[prev], uptime0[curr]);
- }
- else {
- /* UP machines */
- itv = g_itv;
- }
+ itv = get_interval(uptime0[prev], uptime0[curr]);
if (PROCESS_STRING(pidflag)) {
/* Reset "show threads" flag */
if (DISPLAY_ONELINE(pidflag)) {
if (DISPLAY_TASK_STATS(tskflag)) {
again += write_pid_task_all_stats(prev, curr, dis, prev_string, curr_string,
- itv, g_itv);
+ itv, deltot_jiffies);
}
if (DISPLAY_CHILD_STATS(tskflag)) {
again += write_pid_child_all_stats(prev, curr, dis, prev_string, curr_string,
if (DISPLAY_TASK_STATS(tskflag)) {
again += write_pid_task_cpu_stats(prev, curr, dis, disp_avg,
prev_string, curr_string,
- itv, g_itv);
+ itv, deltot_jiffies);
}
if (DISPLAY_CHILD_STATS(tskflag)) {
again += write_pid_child_cpu_stats(prev, curr, dis, disp_avg,
/* Don't buffer data if redirected to a pipe */
setbuf(stdout, NULL);
- if (cpu_nr > 1) {
- /* Read system uptime (only for SMP machines) */
- read_uptime(&uptime0[0]);
- }
+ /* Read system uptime */
+ read_uptime(&uptime0[0]);
read_stats(0);
if (DISPLAY_MEM(actflag)) {
/* Save the first stats collected. Will be used to compute the average */
ps_tstamp[2] = ps_tstamp[0];
- uptime[2] = uptime[0];
+ tot_jiffies[2] = tot_jiffies[0];
uptime0[2] = uptime0[0];
memcpy(st_pid_list[2], st_pid_list[0], PID_STATS_SIZE * pid_nr);
/* Get time */
get_localtime(&ps_tstamp[curr], 0);
- if (cpu_nr > 1) {
- /* Read system uptime (only for SMP machines) */
- read_uptime(&(uptime0[curr]));
- }
+ /* Read system uptime */
+ read_uptime(&(uptime0[curr]));
/* Read stats */
read_stats(curr);
/*
***************************************************************************
* Display CPU statistics.
+ * NB: The stats are only calculated over the part of the time interval when
+ * the CPU was online. As a consequence, the sum (%user + %nice + ... + %idle)
+ * will always be 100% on the time interval even if the CPU has been offline
+ * most of the time.
*
* IN:
* @a Activity structure with statistics.
* @prev Index in array where stats used as reference are.
* @curr Index in array for current sample statistics.
- * @g_itv Interval of time in jiffies multiplied by the number
- * of processors.
+ * @itv Interval of time in jiffies (independent of the number of
+ * processors). Unused here.
***************************************************************************
*/
__print_funct_t print_cpu_stats(struct activity *a, int prev, int curr,
- unsigned long long g_itv)
+ unsigned long long itv)
{
int i;
+ unsigned long long tot_jiffies[3];
+ unsigned long long deltot_jiffies;
struct stats_cpu *scc, *scp;
if (dis) {
/* No */
continue;
- /* Yes: Display it */
+ /*
+ * Yes: Compute the total number of jiffies spent by current processor.
+ * NB: Don't add cpu_guest/cpu_guest_nice because cpu_user/cpu_nice
+ * already include them.
+ */
+ tot_jiffies[curr] = scc->cpu_user + scc->cpu_nice +
+ scc->cpu_sys + scc->cpu_idle +
+ scc->cpu_iowait + scc->cpu_hardirq +
+ scc->cpu_steal + scc->cpu_softirq;
+ tot_jiffies[prev] = scp->cpu_user + scp->cpu_nice +
+ scp->cpu_sys + scp->cpu_idle +
+ scp->cpu_iowait + scp->cpu_hardirq +
+ scp->cpu_steal + scp->cpu_softirq;
+
+ /* Total number of jiffies spent on the interval */
+ deltot_jiffies = get_interval(tot_jiffies[prev], tot_jiffies[curr]);
+
printf("%-11s", timestamp[curr]);
if (!i) {
* (Remember that guest/guest_nice times are already included in
* user/nice modes.)
*/
- if ((scc->cpu_user + scc->cpu_nice + scc->cpu_sys +
- scc->cpu_iowait + scc->cpu_idle + scc->cpu_steal +
- scc->cpu_hardirq + scc->cpu_softirq) == 0) {
+ if (tot_jiffies[curr] == 0) {
/*
* Set current struct fields (which have been set to zero)
* to values from previous iteration. Hence their values won't
}
/* Recalculate interval for current proc */
- g_itv = get_per_cpu_interval(scc, scp);
+ deltot_jiffies = get_per_cpu_interval(scc, scp);
- if (!g_itv) {
+ if (!deltot_jiffies) {
/*
* If the CPU is tickless then there is no change in CPU values
* but the sum of values is not zero.
if (DISPLAY_CPU_DEF(a->opt_flags)) {
cprintf_pc(DISPLAY_UNIT(flags), 6, 9, 2,
- ll_sp_value(scp->cpu_user, scc->cpu_user, g_itv),
- ll_sp_value(scp->cpu_nice, scc->cpu_nice, g_itv),
+ ll_sp_value(scp->cpu_user, scc->cpu_user, deltot_jiffies),
+ ll_sp_value(scp->cpu_nice, scc->cpu_nice, deltot_jiffies),
ll_sp_value(scp->cpu_sys + scp->cpu_hardirq + scp->cpu_softirq,
scc->cpu_sys + scc->cpu_hardirq + scc->cpu_softirq,
- g_itv),
- ll_sp_value(scp->cpu_iowait, scc->cpu_iowait, g_itv),
- ll_sp_value(scp->cpu_steal, scc->cpu_steal, g_itv),
+ deltot_jiffies),
+ ll_sp_value(scp->cpu_iowait, scc->cpu_iowait, deltot_jiffies),
+ ll_sp_value(scp->cpu_steal, scc->cpu_steal, deltot_jiffies),
scc->cpu_idle < scp->cpu_idle ?
0.0 :
- ll_sp_value(scp->cpu_idle, scc->cpu_idle, g_itv));
+ ll_sp_value(scp->cpu_idle, scc->cpu_idle, deltot_jiffies));
printf("\n");
}
else if (DISPLAY_CPU_ALL(a->opt_flags)) {
(scc->cpu_user - scc->cpu_guest) < (scp->cpu_user - scp->cpu_guest) ?
0.0 :
ll_sp_value(scp->cpu_user - scp->cpu_guest,
- scc->cpu_user - scc->cpu_guest, g_itv),
+ scc->cpu_user - scc->cpu_guest, deltot_jiffies),
(scc->cpu_nice - scc->cpu_guest_nice) < (scp->cpu_nice - scp->cpu_guest_nice) ?
0.0 :
ll_sp_value(scp->cpu_nice - scp->cpu_guest_nice,
- scc->cpu_nice - scc->cpu_guest_nice, g_itv),
- ll_sp_value(scp->cpu_sys, scc->cpu_sys, g_itv),
- ll_sp_value(scp->cpu_iowait, scc->cpu_iowait, g_itv),
- ll_sp_value(scp->cpu_steal, scc->cpu_steal, g_itv),
- ll_sp_value(scp->cpu_hardirq, scc->cpu_hardirq, g_itv),
- ll_sp_value(scp->cpu_softirq, scc->cpu_softirq, g_itv),
- ll_sp_value(scp->cpu_guest, scc->cpu_guest, g_itv),
- ll_sp_value(scp->cpu_guest_nice, scc->cpu_guest_nice, g_itv),
+ scc->cpu_nice - scc->cpu_guest_nice, deltot_jiffies),
+ ll_sp_value(scp->cpu_sys, scc->cpu_sys, deltot_jiffies),
+ ll_sp_value(scp->cpu_iowait, scc->cpu_iowait, deltot_jiffies),
+ ll_sp_value(scp->cpu_steal, scc->cpu_steal, deltot_jiffies),
+ ll_sp_value(scp->cpu_hardirq, scc->cpu_hardirq, deltot_jiffies),
+ ll_sp_value(scp->cpu_softirq, scc->cpu_softirq, deltot_jiffies),
+ ll_sp_value(scp->cpu_guest, scc->cpu_guest, deltot_jiffies),
+ ll_sp_value(scp->cpu_guest_nice, scc->cpu_guest_nice, deltot_jiffies),
scc->cpu_idle < scp->cpu_idle ?
0.0 :
- ll_sp_value(scp->cpu_idle, scc->cpu_idle, g_itv));
+ ll_sp_value(scp->cpu_idle, scc->cpu_idle, deltot_jiffies));
printf("\n");
}
}
/*
***************************************************************************
- * Read CPU statistics and machine uptime.
+ * Read CPU statistics.
*
* IN:
* @st_cpu Structure where stats will be saved.
*
* OUT:
* @st_cpu Structure with statistics.
- * @uptime Machine uptime multiplied by the number of processors.
***************************************************************************
*/
-void read_stat_cpu(struct stats_cpu *st_cpu, int nbr, unsigned long long *uptime)
+void read_stat_cpu(struct stats_cpu *st_cpu, int nbr)
{
FILE *fp;
struct stats_cpu *st_cpu_i;
&st_cpu->cpu_steal,
&st_cpu->cpu_guest,
&st_cpu->cpu_guest_nice);
-
- /*
- * Compute the uptime of the system in jiffies (1/100ths of a second
- * if HZ=100).
- * Machine uptime is multiplied by the number of processors here.
- *
- * NB: Don't add cpu_guest/cpu_guest_nice because cpu_user/cpu_nice
- * already include them.
- */
- *uptime = st_cpu->cpu_user + st_cpu->cpu_nice +
- st_cpu->cpu_sys + st_cpu->cpu_idle +
- st_cpu->cpu_iowait + st_cpu->cpu_hardirq +
- st_cpu->cpu_steal + st_cpu->cpu_softirq;
}
else if (!strncmp(line, "cpu", 3)) {
void oct2chr
(char *);
void read_stat_cpu
- (struct stats_cpu *, int, unsigned long long *);
+ (struct stats_cpu *, int);
void read_stat_irq
(struct stats_irq *, int);
void read_meminfo
* @isdb Flag, true if db printing, false if ppc printing.
* @pre Prefix string for output entries
* @curr Index in array for current sample statistics.
- * @g_itv Interval of time in jiffies multiplied by the number
- * of processors.
+ * @itv Interval of time in jiffies (independent of the number of
+ * processors). Unused here.
***************************************************************************
*/
__print_funct_t render_cpu_stats(struct activity *a, int isdb, char *pre,
- int curr, unsigned long long g_itv)
+ int curr, unsigned long long itv)
{
int i, cpu_offline;
+ unsigned long long tot_jiffies[3];
+ unsigned long long deltot_jiffies;
struct stats_cpu *scc, *scp;
int pt_newlin
= (DISPLAY_HORIZONTALLY(flags) ? PT_NOFLAG : PT_NEWLIN);
/* No */
continue;
+ /*
+ * Yes: Compute the total number of jiffies spent by current processor.
+ * NB: Don't add cpu_guest/cpu_guest_nice because cpu_user/cpu_nice
+ * already include them.
+ */
+ tot_jiffies[curr] = scc->cpu_user + scc->cpu_nice +
+ scc->cpu_sys + scc->cpu_idle +
+ scc->cpu_iowait + scc->cpu_hardirq +
+ scc->cpu_steal + scc->cpu_softirq;
+ tot_jiffies[!curr] = scp->cpu_user + scp->cpu_nice +
+ scp->cpu_sys + scp->cpu_idle +
+ scp->cpu_iowait + scp->cpu_hardirq +
+ scp->cpu_steal + scp->cpu_softirq;
+
+ /* Total number of jiffies spent on the interval */
+ deltot_jiffies = get_interval(tot_jiffies[!curr], tot_jiffies[curr]);
+
if (!i) {
/* This is CPU "all" */
if (DISPLAY_CPU_DEF(a->opt_flags)) {
"-1", /* look! dbtext */
NULL, /* no args */
NOVAL, /* another 0, named for readability */
- ll_sp_value(scp->cpu_user, scc->cpu_user, g_itv),
+ ll_sp_value(scp->cpu_user, scc->cpu_user, deltot_jiffies),
NULL); /* No string arg */
}
else if (DISPLAY_CPU_ALL(a->opt_flags)) {
0.0 :
ll_sp_value(scp->cpu_user - scp->cpu_guest,
scc->cpu_user - scc->cpu_guest,
- g_itv),
+ deltot_jiffies),
NULL);
}
render(isdb, pre, PT_NOFLAG,
"all\t%%nice", NULL, NULL,
NOVAL,
- ll_sp_value(scp->cpu_nice, scc->cpu_nice, g_itv),
+ ll_sp_value(scp->cpu_nice, scc->cpu_nice, deltot_jiffies),
NULL);
}
else if (DISPLAY_CPU_ALL(a->opt_flags)) {
0.0 :
ll_sp_value(scp->cpu_nice - scp->cpu_guest_nice,
scc->cpu_nice - scc->cpu_guest_nice,
- g_itv),
+ deltot_jiffies),
NULL);
}
NOVAL,
ll_sp_value(scp->cpu_sys + scp->cpu_hardirq + scp->cpu_softirq,
scc->cpu_sys + scc->cpu_hardirq + scc->cpu_softirq,
- g_itv),
+ deltot_jiffies),
NULL);
}
else if (DISPLAY_CPU_ALL(a->opt_flags)) {
render(isdb, pre, PT_NOFLAG,
"all\t%%sys", NULL, NULL,
NOVAL,
- ll_sp_value(scp->cpu_sys, scc->cpu_sys, g_itv),
+ ll_sp_value(scp->cpu_sys, scc->cpu_sys, deltot_jiffies),
NULL);
}
render(isdb, pre, PT_NOFLAG,
"all\t%%iowait", NULL, NULL,
NOVAL,
- ll_sp_value(scp->cpu_iowait, scc->cpu_iowait, g_itv),
+ ll_sp_value(scp->cpu_iowait, scc->cpu_iowait, deltot_jiffies),
NULL);
render(isdb, pre, PT_NOFLAG,
"all\t%%steal", NULL, NULL,
NOVAL,
- ll_sp_value(scp->cpu_steal, scc->cpu_steal, g_itv),
+ ll_sp_value(scp->cpu_steal, scc->cpu_steal, deltot_jiffies),
NULL);
if (DISPLAY_CPU_ALL(a->opt_flags)) {
render(isdb, pre, PT_NOFLAG,
"all\t%%irq", NULL, NULL,
NOVAL,
- ll_sp_value(scp->cpu_hardirq, scc->cpu_hardirq, g_itv),
+ ll_sp_value(scp->cpu_hardirq, scc->cpu_hardirq, deltot_jiffies),
NULL);
render(isdb, pre, PT_NOFLAG,
"all\t%%soft", NULL, NULL,
NOVAL,
- ll_sp_value(scp->cpu_softirq, scc->cpu_softirq, g_itv),
+ ll_sp_value(scp->cpu_softirq, scc->cpu_softirq, deltot_jiffies),
NULL);
render(isdb, pre, PT_NOFLAG,
"all\t%%guest", NULL, NULL,
NOVAL,
- ll_sp_value(scp->cpu_guest, scc->cpu_guest, g_itv),
+ ll_sp_value(scp->cpu_guest, scc->cpu_guest, deltot_jiffies),
NULL);
render(isdb, pre, PT_NOFLAG,
"all\t%%gnice", NULL, NULL,
NOVAL,
- ll_sp_value(scp->cpu_guest_nice, scc->cpu_guest_nice, g_itv),
+ ll_sp_value(scp->cpu_guest_nice, scc->cpu_guest_nice, deltot_jiffies),
NULL);
}
NOVAL,
(scc->cpu_idle < scp->cpu_idle) ?
0.0 :
- ll_sp_value(scp->cpu_idle, scc->cpu_idle, g_itv),
+ ll_sp_value(scp->cpu_idle, scc->cpu_idle, deltot_jiffies),
NULL);
}
else {
* (Remember that guest/guest_nice times are already included in
* user/nice modes.)
*/
- if ((scc->cpu_user + scc->cpu_nice + scc->cpu_sys +
- scc->cpu_iowait + scc->cpu_idle + scc->cpu_steal +
- scc->cpu_hardirq + scc->cpu_softirq) == 0) {
+ if (tot_jiffies[curr] == 0) {
/*
* Set current struct fields (which have been set to zero)
* to values from previous iteration. Hence their values won't
*/
*scc = *scp;
- g_itv = 0;
+ deltot_jiffies = 0;
cpu_offline = TRUE;
}
else {
* Recalculate itv for current proc.
* If the result is 0, then current CPU is a tickless one.
*/
- g_itv = get_per_cpu_interval(scc, scp);
+ deltot_jiffies = get_per_cpu_interval(scc, scp);
cpu_offline = FALSE;
}
"%d", /* db text with format char */
cons(iv, i - 1, NOVAL), /* how we pass format args */
NOVAL,
- !g_itv ?
+ !deltot_jiffies ?
0.0 : /* CPU is offline or tickless */
- ll_sp_value(scp->cpu_user, scc->cpu_user, g_itv),
+ ll_sp_value(scp->cpu_user, scc->cpu_user, deltot_jiffies),
NULL);
}
else if (DISPLAY_CPU_ALL(a->opt_flags)) {
render(isdb, pre, PT_NOFLAG,
"cpu%d\t%%usr", "%d", cons(iv, i - 1, NOVAL),
NOVAL,
- (!g_itv ||
+ (!deltot_jiffies ||
((scc->cpu_user - scc->cpu_guest) < (scp->cpu_user - scp->cpu_guest))) ?
0.0 :
ll_sp_value(scp->cpu_user - scp->cpu_guest,
- scc->cpu_user - scc->cpu_guest, g_itv),
+ scc->cpu_user - scc->cpu_guest, deltot_jiffies),
NULL);
}
render(isdb, pre, PT_NOFLAG,
"cpu%d\t%%nice", NULL, cons(iv, i - 1, NOVAL),
NOVAL,
- !g_itv ?
+ !deltot_jiffies ?
0.0 :
- ll_sp_value(scp->cpu_nice, scc->cpu_nice, g_itv),
+ ll_sp_value(scp->cpu_nice, scc->cpu_nice, deltot_jiffies),
NULL);
}
else if (DISPLAY_CPU_ALL(a->opt_flags)) {
render(isdb, pre, PT_NOFLAG,
"cpu%d\t%%nice", NULL, cons(iv, i - 1, NOVAL),
NOVAL,
- (!g_itv ||
+ (!deltot_jiffies ||
((scc->cpu_nice - scc->cpu_guest_nice) < (scp->cpu_nice - scp->cpu_guest_nice))) ?
0.0 :
ll_sp_value(scp->cpu_nice - scp->cpu_guest_nice,
- scc->cpu_nice - scc->cpu_guest_nice, g_itv),
+ scc->cpu_nice - scc->cpu_guest_nice, deltot_jiffies),
NULL);
}
render(isdb, pre, PT_NOFLAG,
"cpu%d\t%%system", NULL, cons(iv, i - 1, NOVAL),
NOVAL,
- !g_itv ?
+ !deltot_jiffies ?
0.0 :
ll_sp_value(scp->cpu_sys + scp->cpu_hardirq + scp->cpu_softirq,
scc->cpu_sys + scc->cpu_hardirq + scc->cpu_softirq,
- g_itv),
+ deltot_jiffies),
NULL);
}
else if (DISPLAY_CPU_ALL(a->opt_flags)) {
render(isdb, pre, PT_NOFLAG,
"cpu%d\t%%sys", NULL, cons(iv, i - 1, NOVAL),
NOVAL,
- !g_itv ?
+ !deltot_jiffies ?
0.0 :
- ll_sp_value(scp->cpu_sys, scc->cpu_sys, g_itv),
+ ll_sp_value(scp->cpu_sys, scc->cpu_sys, deltot_jiffies),
NULL);
}
render(isdb, pre, PT_NOFLAG,
"cpu%d\t%%iowait", NULL, cons(iv, i - 1, NOVAL),
NOVAL,
- !g_itv ?
+ !deltot_jiffies ?
0.0 :
- ll_sp_value(scp->cpu_iowait, scc->cpu_iowait, g_itv),
+ ll_sp_value(scp->cpu_iowait, scc->cpu_iowait, deltot_jiffies),
NULL);
render(isdb, pre, PT_NOFLAG,
"cpu%d\t%%steal", NULL, cons(iv, i - 1, NOVAL),
NOVAL,
- !g_itv ?
+ !deltot_jiffies ?
0.0 :
- ll_sp_value(scp->cpu_steal, scc->cpu_steal, g_itv),
+ ll_sp_value(scp->cpu_steal, scc->cpu_steal, deltot_jiffies),
NULL);
if (DISPLAY_CPU_ALL(a->opt_flags)) {
render(isdb, pre, PT_NOFLAG,
"cpu%d\t%%irq", NULL, cons(iv, i - 1, NOVAL),
NOVAL,
- !g_itv ?
+ !deltot_jiffies ?
0.0 :
- ll_sp_value(scp->cpu_hardirq, scc->cpu_hardirq, g_itv),
+ ll_sp_value(scp->cpu_hardirq, scc->cpu_hardirq, deltot_jiffies),
NULL);
render(isdb, pre, PT_NOFLAG,
"cpu%d\t%%soft", NULL, cons(iv, i - 1, NOVAL),
NOVAL,
- !g_itv ?
+ !deltot_jiffies ?
0.0 :
- ll_sp_value(scp->cpu_softirq, scc->cpu_softirq, g_itv),
+ ll_sp_value(scp->cpu_softirq, scc->cpu_softirq, deltot_jiffies),
NULL);
render(isdb, pre, PT_NOFLAG,
"cpu%d\t%%guest", NULL, cons(iv, i - 1, NOVAL),
NOVAL,
- !g_itv ?
+ !deltot_jiffies ?
0.0 :
- ll_sp_value(scp->cpu_guest, scc->cpu_guest, g_itv),
+ ll_sp_value(scp->cpu_guest, scc->cpu_guest, deltot_jiffies),
NULL);
render(isdb, pre, PT_NOFLAG,
"cpu%d\t%%gnice", NULL, cons(iv, i - 1, NOVAL),
NOVAL,
- !g_itv ?
+ !deltot_jiffies ?
0.0 :
- ll_sp_value(scp->cpu_guest_nice, scc->cpu_guest_nice, g_itv),
+ ll_sp_value(scp->cpu_guest_nice, scc->cpu_guest_nice, deltot_jiffies),
NULL);
}
- if (!g_itv) {
+ if (!deltot_jiffies) {
/* CPU is offline or tickless */
render(isdb, pre, pt_newlin,
"cpu%d\t%%idle", NULL, cons(iv, i - 1, NOVAL),
NOVAL,
(scc->cpu_idle < scp->cpu_idle) ?
0.0 :
- ll_sp_value(scp->cpu_idle, scc->cpu_idle, g_itv),
+ ll_sp_value(scp->cpu_idle, scc->cpu_idle, deltot_jiffies),
NULL);
}
}
/* Header structure for every record */
struct record_header {
/*
- * Machine uptime (multiplied by the # of proc).
- */
- unsigned long long uptime;
- /*
- * Uptime reduced to one processor. Always set, even on UP machines.
+ * Machine uptime in jiffies (independent of the number of processors).
*/
unsigned long long uptime0;
/*
#define RECORD_HEADER_SIZE (sizeof(struct record_header))
#define MAX_RECORD_HEADER_SIZE 512 /* Used for sanity check */
-#define RECORD_HEADER_ULL_NR 3 /* Nr of unsigned long long in record_header structure */
+#define RECORD_HEADER_ULL_NR 2 /* Nr of unsigned long long in record_header structure */
#define RECORD_HEADER_UL_NR 0 /* Nr of unsigned long in record_header structure */
#define RECORD_HEADER_U_NR 0 /* Nr of unsigned int in record_header structure */
*/
#define AO_VOLATILE 0x04
/*
- * Indicate that the interval of time, given to f_print() function
- * displaying statistics, should be the interval of time in jiffies
- * multiplied by the number of processors.
+ * 0x08: Unused.
*/
-#define AO_GLOBAL_ITV 0x08
/*
* This flag should be set for every activity closing a markup used
* by several activities. Used by sadf f_xml_print() functions to
#define IS_COLLECTED(m) (((m) & AO_COLLECTED) == AO_COLLECTED)
#define IS_SELECTED(m) (((m) & AO_SELECTED) == AO_SELECTED)
#define IS_VOLATILE(m) (((m) & AO_VOLATILE) == AO_VOLATILE)
-#define NEED_GLOBAL_ITV(m) (((m) & AO_GLOBAL_ITV) == AO_GLOBAL_ITV)
#define CLOSE_MARKUP(m) (((m) & AO_CLOSE_MARKUP) == AO_CLOSE_MARKUP)
#define HAS_MULTIPLE_OUTPUTS(m) (((m) & AO_MULTIPLE_OUTPUTS) == AO_MULTIPLE_OUTPUTS)
#define ONE_GRAPH_PER_ITEM(m) (((m) & AO_GRAPH_PER_ITEM) == AO_GRAPH_PER_ITEM)
(unsigned int, struct tm *, struct file_header *);
void get_itv_value
(struct record_header *, struct record_header *, unsigned int,
- unsigned long long *, unsigned long long *);
+ unsigned long long *);
void handle_invalid_sa_file
(int *, struct file_magic *, char *, int);
int next_slice
* @nr_proc Number of CPU, including CPU "all".
*
* OUT:
- * @itv Interval in jiffies.
- * @g_itv Interval in jiffies multiplied by the # of proc.
+ * @itv Interval of time in jiffies.
***************************************************************************
*/
void get_itv_value(struct record_header *record_hdr_curr,
struct record_header *record_hdr_prev,
- unsigned int nr_proc,
- unsigned long long *itv, unsigned long long *g_itv)
+ unsigned int nr_proc, unsigned long long *itv)
{
/* Interval value in jiffies */
- *g_itv = get_interval(record_hdr_prev->uptime,
- record_hdr_curr->uptime);
-
- if (nr_proc > 2) {
- *itv = get_interval(record_hdr_prev->uptime0,
- record_hdr_curr->uptime0);
- }
- else {
- *itv = *g_itv;
- }
+ *itv = get_interval(record_hdr_prev->uptime0,
+ record_hdr_curr->uptime0);
}
/*
= (struct stats_cpu *) a->_buf0;
/* Read CPU statistics */
- read_stat_cpu(st_cpu, a->nr, &record_hdr.uptime);
+ read_stat_cpu(st_cpu, a->nr);
return;
}
void read_stats(void)
{
int i;
- __nr_t cpu_nr = act[get_activity_position(act, A_CPU, EXIT_IF_NOT_FOUND)]->nr;
- if (cpu_nr > 1) {
- /* Read system uptime in jiffies */
- read_uptime(&(record_hdr.uptime0));
- }
+ /* Read system uptime in jiffies */
+ read_uptime(&(record_hdr.uptime0));
for (i = 0; i < NR_ACT; i++) {
if (IS_COLLECTED(act[i]->options)) {
(*act[i]->f_read)(act[i]);
}
}
-
- if (cpu_nr == 1) {
- /*
- * If cpu_nr = 1, uptime0 and uptime are equal.
- * Remember that cpu_nr = 1 means one CPU and no SMP kernel
- * (one structure for CPU "all") and cpu_nr = 2 means one CPU
- * and an SMP kernel (two structures for CPUs "all" and "0").
- */
- record_hdr.uptime0 = record_hdr.uptime;
- }
}
/*
struct tm *loctime, int reset_cd, unsigned int act_id)
{
int i;
- unsigned long long dt, itv, g_itv;
+ unsigned long long dt, itv;
char cur_date[TIMESTAMP_LEN], cur_time[TIMESTAMP_LEN], *pre = NULL;
static int cross_day = FALSE;
/* Get interval values */
get_itv_value(&record_hdr[curr], &record_hdr[!curr],
- cpu_nr, &itv, &g_itv);
+ cpu_nr, &itv);
/* Check time (3) */
if (use_tm_end && (datecmp(loctime, &tm_end) > 0)) {
dt, &file_hdr, flags);
}
}
- (*act[i]->f_json_print)(act[i], curr, *tab, NEED_GLOBAL_ITV(act[i]->options) ?
- g_itv : itv);
+ (*act[i]->f_json_print)(act[i], curr, *tab, itv);
}
else if (format == F_XML_OUTPUT) {
/* XML output */
int *tab = (int *) parm;
- (*act[i]->f_xml_print)(act[i], curr, *tab, NEED_GLOBAL_ITV(act[i]->options) ?
- g_itv : itv);
+ (*act[i]->f_xml_print)(act[i], curr, *tab, itv);
}
else if (format == F_SVG_OUTPUT) {
struct svg_parm *svg_p = (struct svg_parm *) parm;
svg_p->dt = (unsigned long) dt;
- (*act[i]->f_svg_print)(act[i], curr, F_MAIN, svg_p,
- NEED_GLOBAL_ITV(act[i]->options) ? g_itv : itv,
- &record_hdr[curr]);
+ (*act[i]->f_svg_print)(act[i], curr, F_MAIN, svg_p, itv, &record_hdr[curr]);
}
else if (format == F_RAW_OUTPUT) {
else {
/* Other output formats: db, ppc */
- (*act[i]->f_render)(act[i], (format == F_DB_OUTPUT), pre, curr,
- NEED_GLOBAL_ITV(act[i]->options) ? g_itv : itv);
+ (*act[i]->f_render)(act[i], (format == F_DB_OUTPUT), pre, curr, itv);
}
}
}
void write_stats_avg(int curr, int read_from_file, unsigned int act_id)
{
int i;
- unsigned long long itv, g_itv;
+ unsigned long long itv;
static __nr_t cpu_nr = -1;
if (cpu_nr < 0)
cpu_nr = act[get_activity_position(act, A_CPU, EXIT_IF_NOT_FOUND)]->nr;
/* Interval value in jiffies */
- g_itv = get_interval(record_hdr[2].uptime, record_hdr[curr].uptime);
-
- if (cpu_nr > 1)
- itv = get_interval(record_hdr[2].uptime0, record_hdr[curr].uptime0);
- else
- itv = g_itv;
+ itv = get_interval(record_hdr[2].uptime0, record_hdr[curr].uptime0);
strncpy(timestamp[curr], _("Average:"), TIMESTAMP_LEN);
timestamp[curr][TIMESTAMP_LEN - 1] = '\0';
if (IS_SELECTED(act[i]->options) && (act[i]->nr > 0)) {
/* Display current average activity statistics */
- (*act[i]->f_print_avg)(act[i], 2, curr,
- NEED_GLOBAL_ITV(act[i]->options) ? g_itv : itv);
+ (*act[i]->f_print_avg)(act[i], 2, curr, itv);
}
}
int use_tm_end, int reset, unsigned int act_id, int reset_cd)
{
int i;
- unsigned long long itv, g_itv;
+ unsigned long long itv;
static int cross_day = 0;
static __nr_t cpu_nr = -1;
/* Get interval values */
get_itv_value(&record_hdr[curr], &record_hdr[!curr],
- cpu_nr, &itv, &g_itv);
+ cpu_nr, &itv);
/* Check time (3) */
if (use_tm_end && (datecmp(&rectime, &tm_end) > 0)) {
if (IS_SELECTED(act[i]->options) && (act[i]->nr > 0)) {
/* Display current activity statistics */
- (*act[i]->f_print)(act[i], !curr, curr,
- NEED_GLOBAL_ITV(act[i]->options) ? g_itv : itv);
+ (*act[i]->f_print)(act[i], !curr, curr, itv);
}
}
* found (.@restart), and time used for the X axis origin
* (@ust_time_ref).
* @itv Interval of time in jiffies (only with F_MAIN action).
+ * Unused here.
* @record_hdr Pointer on record header of current stats sample.
***************************************************************************
*/
__print_funct_t svg_print_cpu_stats(struct activity *a, int curr, int action, struct svg_parm *svg_p,
- unsigned long long g_itv, struct record_header *record_hdr)
+ unsigned long long itv, struct record_header *record_hdr)
{
struct stats_cpu *scc, *scp;
+ unsigned long long tot_jiffies[3];
+ unsigned long long deltot_jiffies;
int group1[] = {5};
int group2[] = {9};
int g_type[] = {SVG_BAR_GRAPH};
/* No */
continue;
+ /*
+ * Yes: Compute the total number of jiffies spent by current processor.
+ * NB: Don't add cpu_guest/cpu_guest_nice because cpu_user/cpu_nice
+ * already include them.
+ */
+ tot_jiffies[curr] = scc->cpu_user + scc->cpu_nice +
+ scc->cpu_sys + scc->cpu_idle +
+ scc->cpu_iowait + scc->cpu_hardirq +
+ scc->cpu_steal + scc->cpu_softirq;
+ tot_jiffies[!curr] = scp->cpu_user + scp->cpu_nice +
+ scp->cpu_sys + scp->cpu_idle +
+ scp->cpu_iowait + scp->cpu_hardirq +
+ scp->cpu_steal + scp->cpu_softirq;
+
+ /* Total number of jiffies spent on the interval */
+ deltot_jiffies = get_interval(tot_jiffies[!curr], tot_jiffies[curr]);
+
pos = i * 10;
offset = 0.0;
* (Remember that guest/guest_nice times are already included in
* user/nice modes.)
*/
- if ((scc->cpu_user + scc->cpu_nice + scc->cpu_sys +
- scc->cpu_iowait + scc->cpu_idle + scc->cpu_steal +
- scc->cpu_hardirq + scc->cpu_softirq) == 0) {
+ if (tot_jiffies[curr] == 0) {
/*
* Set current struct fields (which have been set to zero)
* to values from previous iteration. Hence their values won't
*/
*scc = *scp;
- g_itv = 0;
+ deltot_jiffies = 0;
cpu_offline = TRUE;
}
else {
* Recalculate interval for current proc.
* If result is 0 then current CPU is a tickless one.
*/
- g_itv = get_per_cpu_interval(scc, scp);
+ deltot_jiffies = get_per_cpu_interval(scc, scp);
cpu_offline = FALSE;
}
- if (!g_itv) { /* Current CPU is offline or tickless */
+ if (!deltot_jiffies) { /* Current CPU is offline or tickless */
val = (cpu_offline ? 0.0 /* Offline CPU: %idle = 0% */
: 100.0); /* Tickless CPU: %idle = 100% */
if (DISPLAY_CPU_DEF(a->opt_flags)) {
/* %user */
cpuappend(record_hdr->ust_time - svg_p->ust_time_ref,
- &offset, ll_sp_value(scp->cpu_user, scc->cpu_user, g_itv),
+ &offset, ll_sp_value(scp->cpu_user, scc->cpu_user, deltot_jiffies),
out + pos, outsize + pos, svg_p->dt,
spmin + pos, spmax + pos);
}
(scc->cpu_user - scc->cpu_guest) < (scp->cpu_user - scp->cpu_guest) ?
0.0 :
ll_sp_value(scp->cpu_user - scp->cpu_guest,
- scc->cpu_user - scc->cpu_guest, g_itv),
+ scc->cpu_user - scc->cpu_guest, deltot_jiffies),
out + pos, outsize + pos, svg_p->dt,
spmin + pos, spmax + pos);
}
if (DISPLAY_CPU_DEF(a->opt_flags)) {
/* %nice */
cpuappend(record_hdr->ust_time - svg_p->ust_time_ref,
- &offset, ll_sp_value(scp->cpu_nice, scc->cpu_nice, g_itv),
+ &offset, ll_sp_value(scp->cpu_nice, scc->cpu_nice, deltot_jiffies),
out + pos + 1, outsize + pos + 1, svg_p->dt,
spmin + pos + 1, spmax + pos + 1);
}
(scc->cpu_nice - scc->cpu_guest_nice) < (scp->cpu_nice - scp->cpu_guest_nice) ?
0.0 :
ll_sp_value(scp->cpu_nice - scp->cpu_guest_nice,
- scc->cpu_nice - scc->cpu_guest_nice, g_itv),
+ scc->cpu_nice - scc->cpu_guest_nice, deltot_jiffies),
out + pos + 1, outsize + pos + 1, svg_p->dt,
spmin + pos + 1, spmax + pos + 1);
}
&offset,
ll_sp_value(scp->cpu_sys + scp->cpu_hardirq + scp->cpu_softirq,
scc->cpu_sys + scc->cpu_hardirq + scc->cpu_softirq,
- g_itv),
+ deltot_jiffies),
out + pos + 2, outsize + pos + 2, svg_p->dt,
spmin + pos + 2, spmax + pos + 2);
}
else {
/* %sys */
cpuappend(record_hdr->ust_time - svg_p->ust_time_ref,
- &offset, ll_sp_value(scp->cpu_sys, scc->cpu_sys, g_itv),
+ &offset, ll_sp_value(scp->cpu_sys, scc->cpu_sys, deltot_jiffies),
out + pos + 2, outsize + pos + 2, svg_p->dt,
spmin + pos + 2, spmax + pos + 2);
}
/* %iowait */
cpuappend(record_hdr->ust_time - svg_p->ust_time_ref,
- &offset, ll_sp_value(scp->cpu_iowait, scc->cpu_iowait, g_itv),
+ &offset, ll_sp_value(scp->cpu_iowait, scc->cpu_iowait, deltot_jiffies),
out + pos + 3, outsize + pos + 3, svg_p->dt,
spmin + pos + 3, spmax + pos + 3);
/* %steal */
cpuappend(record_hdr->ust_time - svg_p->ust_time_ref,
- &offset, ll_sp_value(scp->cpu_steal, scc->cpu_steal, g_itv),
+ &offset, ll_sp_value(scp->cpu_steal, scc->cpu_steal, deltot_jiffies),
out + pos + 4, outsize + pos + 4, svg_p->dt,
spmin + pos + 4, spmax + pos + 4);
if (DISPLAY_CPU_ALL(a->opt_flags)) {
/* %irq */
cpuappend(record_hdr->ust_time - svg_p->ust_time_ref,
- &offset, ll_sp_value(scp->cpu_hardirq, scc->cpu_hardirq, g_itv),
+ &offset, ll_sp_value(scp->cpu_hardirq, scc->cpu_hardirq, deltot_jiffies),
out + pos + 5, outsize + pos + 5, svg_p->dt,
spmin + pos + 5, spmax + pos + 5);
/* %soft */
cpuappend(record_hdr->ust_time - svg_p->ust_time_ref,
- &offset, ll_sp_value(scp->cpu_softirq, scc->cpu_softirq, g_itv),
+ &offset, ll_sp_value(scp->cpu_softirq, scc->cpu_softirq, deltot_jiffies),
out + pos + 6, outsize + pos + 6, svg_p->dt,
spmin + pos + 6, spmax + pos + 6);
/* %guest */
cpuappend(record_hdr->ust_time - svg_p->ust_time_ref,
- &offset, ll_sp_value(scp->cpu_guest, scc->cpu_guest, g_itv),
+ &offset, ll_sp_value(scp->cpu_guest, scc->cpu_guest, deltot_jiffies),
out + pos + 7, outsize + pos + 7, svg_p->dt,
spmin + pos + 7, spmax + pos + 7);
/* %gnice */
cpuappend(record_hdr->ust_time - svg_p->ust_time_ref,
- &offset, ll_sp_value(scp->cpu_guest_nice, scc->cpu_guest_nice, g_itv),
+ &offset, ll_sp_value(scp->cpu_guest_nice, scc->cpu_guest_nice, deltot_jiffies),
out + pos + 8, outsize + pos + 8, svg_p->dt,
spmin + pos + 8, spmax + pos + 8);
cpuappend(record_hdr->ust_time - svg_p->ust_time_ref,
&offset,
(scc->cpu_idle < scp->cpu_idle ? 0.0 :
- ll_sp_value(scp->cpu_idle, scc->cpu_idle, g_itv)),
+ ll_sp_value(scp->cpu_idle, scc->cpu_idle, deltot_jiffies)),
out + pos + j, outsize + pos + j, svg_p->dt,
spmin + pos + j, spmax + pos + j);
}
* @a Activity structure with statistics.
* @curr Index in array for current sample statistics.
* @tab Indentation in XML output.
- * @g_itv Interval of time in jiffies mutliplied by the number of
- * processors.
+ * @itv Interval of time in jiffies (independent of the number of
+ * processors). Unused here.
***************************************************************************
*/
__print_funct_t xml_print_cpu_stats(struct activity *a, int curr, int tab,
- unsigned long long g_itv)
+ unsigned long long itv)
{
int i, cpu_offline;
+ unsigned long long tot_jiffies[3];
+ unsigned long long deltot_jiffies;
struct stats_cpu *scc, *scp;
char cpuno[8];
/* No */
continue;
- /* Yes: Display it */
+ /*
+ * Yes: Compute the total number of jiffies spent by current processor.
+ * NB: Don't add cpu_guest/cpu_guest_nice because cpu_user/cpu_nice
+ * already include them.
+ */
+ tot_jiffies[curr] = scc->cpu_user + scc->cpu_nice +
+ scc->cpu_sys + scc->cpu_idle +
+ scc->cpu_iowait + scc->cpu_hardirq +
+ scc->cpu_steal + scc->cpu_softirq;
+ tot_jiffies[!curr] = scp->cpu_user + scp->cpu_nice +
+ scp->cpu_sys + scp->cpu_idle +
+ scp->cpu_iowait + scp->cpu_hardirq +
+ scp->cpu_steal + scp->cpu_softirq;
+
+ /* Total number of jiffies spent on the interval */
+ deltot_jiffies = get_interval(tot_jiffies[!curr], tot_jiffies[curr]);
+
if (!i) {
/* This is CPU "all" */
strcpy(cpuno, "all");
* (Remember that guest/guest_nice times are already included in
* user/nice modes.)
*/
- if ((scc->cpu_user + scc->cpu_nice + scc->cpu_sys +
- scc->cpu_iowait + scc->cpu_idle + scc->cpu_steal +
- scc->cpu_hardirq + scc->cpu_softirq) == 0) {
+ if (tot_jiffies[curr] == 0) {
/*
* Set current struct fields (which have been set to zero)
* to values from previous iteration. Hence their values won't
*/
*scc = *scp;
- g_itv = 0;
+ deltot_jiffies = 0;
cpu_offline = TRUE;
}
else {
* Recalculate interval for current proc.
* If result is 0 then current CPU is a tickless one.
*/
- g_itv = get_per_cpu_interval(scc, scp);
+ deltot_jiffies = get_per_cpu_interval(scc, scp);
cpu_offline = FALSE;
}
- if (!g_itv) {
+ if (!deltot_jiffies) {
/* Current CPU is offline or tickless */
if (DISPLAY_CPU_DEF(a->opt_flags)) {
xprintf(tab, "<cpu number=\"%d\" "
"steal=\"%.2f\" "
"idle=\"%.2f\"/>",
cpuno,
- ll_sp_value(scp->cpu_user, scc->cpu_user, g_itv),
- ll_sp_value(scp->cpu_nice, scc->cpu_nice, g_itv),
+ ll_sp_value(scp->cpu_user, scc->cpu_user, deltot_jiffies),
+ ll_sp_value(scp->cpu_nice, scc->cpu_nice, deltot_jiffies),
ll_sp_value(scp->cpu_sys + scp->cpu_hardirq + scp->cpu_softirq,
scc->cpu_sys + scc->cpu_hardirq + scc->cpu_softirq,
- g_itv),
- ll_sp_value(scp->cpu_iowait, scc->cpu_iowait, g_itv),
- ll_sp_value(scp->cpu_steal, scc->cpu_steal, g_itv),
+ deltot_jiffies),
+ ll_sp_value(scp->cpu_iowait, scc->cpu_iowait, deltot_jiffies),
+ ll_sp_value(scp->cpu_steal, scc->cpu_steal, deltot_jiffies),
scc->cpu_idle < scp->cpu_idle ?
0.0 :
- ll_sp_value(scp->cpu_idle, scc->cpu_idle, g_itv));
+ ll_sp_value(scp->cpu_idle, scc->cpu_idle, deltot_jiffies));
}
else if (DISPLAY_CPU_ALL(a->opt_flags)) {
xprintf(tab, "<cpu number=\"%s\" "
(scc->cpu_user - scc->cpu_guest) < (scp->cpu_user - scp->cpu_guest) ?
0.0 :
ll_sp_value(scp->cpu_user - scp->cpu_guest,
- scc->cpu_user - scc->cpu_guest, g_itv),
+ scc->cpu_user - scc->cpu_guest, deltot_jiffies),
(scc->cpu_nice - scc->cpu_guest_nice) < (scp->cpu_nice - scp->cpu_guest_nice) ?
0.0 :
ll_sp_value(scp->cpu_nice - scp->cpu_guest_nice,
- scc->cpu_nice - scc->cpu_guest_nice, g_itv),
- ll_sp_value(scp->cpu_sys, scc->cpu_sys, g_itv),
- ll_sp_value(scp->cpu_iowait, scc->cpu_iowait, g_itv),
- ll_sp_value(scp->cpu_steal, scc->cpu_steal, g_itv),
- ll_sp_value(scp->cpu_hardirq, scc->cpu_hardirq, g_itv),
- ll_sp_value(scp->cpu_softirq, scc->cpu_softirq, g_itv),
- ll_sp_value(scp->cpu_guest, scc->cpu_guest, g_itv),
- ll_sp_value(scp->cpu_guest_nice, scc->cpu_guest_nice, g_itv),
+ scc->cpu_nice - scc->cpu_guest_nice, deltot_jiffies),
+ ll_sp_value(scp->cpu_sys, scc->cpu_sys, deltot_jiffies),
+ ll_sp_value(scp->cpu_iowait, scc->cpu_iowait, deltot_jiffies),
+ ll_sp_value(scp->cpu_steal, scc->cpu_steal, deltot_jiffies),
+ ll_sp_value(scp->cpu_hardirq, scc->cpu_hardirq, deltot_jiffies),
+ ll_sp_value(scp->cpu_softirq, scc->cpu_softirq, deltot_jiffies),
+ ll_sp_value(scp->cpu_guest, scc->cpu_guest, deltot_jiffies),
+ ll_sp_value(scp->cpu_guest_nice, scc->cpu_guest_nice, deltot_jiffies),
scc->cpu_idle < scp->cpu_idle ?
0.0 :
- ll_sp_value(scp->cpu_idle, scc->cpu_idle, g_itv));
+ ll_sp_value(scp->cpu_idle, scc->cpu_idle, deltot_jiffies));
}
}