~ubuntu-branches/ubuntu/saucy/sysstat/saucy

« back to all changes in this revision

Viewing changes to mpstat.c

  • Committer: Bazaar Package Importer
  • Author(s): Robert Luberda
  • Date: 2011-08-28 19:50:36 UTC
  • mfrom: (1.1.22 upstream) (2.1.14 sid)
  • Revision ID: james.westby@ubuntu.com-20110828195036-5zk8yk5cbeeli0ml
Tags: 10.0.2-1
* New upstream (stable) release.
* debian/control: Set architecture to linux-any (closes: #619949).
* The debconf message has already been ixed in 8.1.8-2, (LP: #342655).

Show diffs side-by-side

added added

removed removed

Lines of Context:
87
87
                progname);
88
88
 
89
89
        fprintf(stderr, _("Options are:\n"
90
 
                          "[ -A ] [ -I { SUM | CPU | SCPU | ALL } ] [ -u ] [ -P { <cpu> [,...] | ALL } ] [ -V ]\n"));
 
90
                          "[ -A ] [ -I { SUM | CPU | SCPU | ALL } ] [ -u ]\n"
 
91
                          "[ -P { <cpu> [,...] | ON | ALL } ] [ -V ]\n"));
91
92
        exit(1);
92
93
}
93
94
 
211
212
                        unsigned long long itv, int prev, int curr,
212
213
                        char *prev_string, char *curr_string)
213
214
{
 
215
        struct stats_cpu *scc, *scp;
214
216
        int j = 0, offset, cpu;
215
217
        struct stats_irqcpu *p, *q, *p0, *q0;
216
218
 
248
250
 
249
251
        for (cpu = 1; cpu <= cpu_nr; cpu++) {
250
252
 
 
253
                scc = st_cpu[curr] + cpu;
 
254
                scp = st_cpu[prev] + cpu;
 
255
 
251
256
                /*
252
 
                * Check if we want stats about this CPU.
 
257
                 * Check if we want stats about this CPU.
253
258
                 * CPU must have been explicitly selected using option -P,
254
259
                 * else we display every CPU.
255
260
                 */
256
261
                if (!(*(cpu_bitmap + (cpu >> 3)) & (1 << (cpu & 0x07))) && USE_P_OPTION(flags))
257
262
                        continue;
258
263
 
 
264
                if ((scc->cpu_user    + scc->cpu_nice + scc->cpu_sys   +
 
265
                     scc->cpu_iowait  + scc->cpu_idle + scc->cpu_steal +
 
266
                     scc->cpu_hardirq + scc->cpu_softirq) == 0) {
 
267
 
 
268
                        /* Offline CPU found */
 
269
 
 
270
                        if (DISPLAY_ONLINE_CPU(flags))
 
271
                                continue;
 
272
                }
 
273
 
259
274
                printf("%-11s  %3d", curr_string, cpu - 1);
260
275
 
261
276
                for (j = 0; j < ic_nr; j++) {
299
314
 
300
315
/*
301
316
 ***************************************************************************
302
 
 * Core function used to display statistics
 
317
 * Core function used to display statistics.
303
318
 *
304
319
 * IN:
305
320
 * @prev        Position in array where statistics used as reference are.
393
408
                        if (!(*(cpu_bitmap + (cpu >> 3)) & (1 << (cpu & 0x07))))
394
409
                                continue;
395
410
                        
396
 
                        printf("%-11s %4d", curr_string, cpu - 1);
397
 
 
398
411
                        /*
399
412
                         * If the CPU is offline then it is omited from /proc/stat
400
413
                         * and the sum of all values is zero.
403
416
                        if ((scc->cpu_user    + scc->cpu_nice + scc->cpu_sys   +
404
417
                             scc->cpu_iowait  + scc->cpu_idle + scc->cpu_steal +
405
418
                             scc->cpu_hardirq + scc->cpu_softirq) == 0) {
406
 
                                /*
407
 
                                 * Set current struct fields (which have been set to zero)
408
 
                                 * to values from previous iteration. Hence their values won't
409
 
                                 * jump from zero when the CPU comes back online.
410
 
                                 */
411
 
                                *scc = *scp;
412
419
 
413
 
                                printf("  %6.2f  %6.2f  %6.2f  %6.2f  %6.2f  %6.2f"
414
 
                                       "  %6.2f  %6.2f  %6.2f\n",
415
 
                                       0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
 
420
                                if (!DISPLAY_ONLINE_CPU(flags)) {
 
421
                                        printf("%-11s %4d"
 
422
                                               "  %6.2f  %6.2f  %6.2f  %6.2f  %6.2f  %6.2f"
 
423
                                               "  %6.2f  %6.2f  %6.2f\n",
 
424
                                               curr_string, cpu - 1,
 
425
                                               0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
 
426
                                }
416
427
                                continue;
417
428
                        }
418
429
 
 
430
                        printf("%-11s %4d", curr_string, cpu - 1);
 
431
 
419
432
                        /* Recalculate itv for current proc */
420
433
                        pc_itv = get_per_cpu_interval(scc, scp);
421
434
                        
492
505
                        if (!(*(cpu_bitmap + (cpu >> 3)) & (1 << (cpu & 0x07))))
493
506
                                continue;
494
507
 
 
508
                        if ((scc->cpu_user    + scc->cpu_nice + scc->cpu_sys   +
 
509
                             scc->cpu_iowait  + scc->cpu_idle + scc->cpu_steal +
 
510
                             scc->cpu_hardirq + scc->cpu_softirq) == 0) {
 
511
 
 
512
                                /* This is an offline CPU */
 
513
                                
 
514
                                if (!DISPLAY_ONLINE_CPU(flags)) {
 
515
                                        printf("%-11s %4d"
 
516
                                               "  %9.2f\n",
 
517
                                               curr_string, cpu - 1,
 
518
                                               0.0);
 
519
                                }
 
520
                                continue;
 
521
                        }
 
522
 
495
523
                        printf("%-11s %4d", curr_string, cpu - 1);
496
524
 
497
525
                        /* Recalculate itv for current proc */
498
526
                        pc_itv = get_per_cpu_interval(scc, scp);
499
527
 
500
528
                        if (!pc_itv) {
501
 
                                /* Current CPU is offline */
 
529
                                /* This is a tickless CPU */
502
530
                                printf(" %9.2f\n", 0.0);
503
531
                        }
504
532
                        else {
517
545
                write_irqcpu_stats(st_softirqcpu, softirqcpu_nr, dis, itv, prev, curr,
518
546
                                   prev_string, curr_string);
519
547
        }
 
548
 
 
549
        /* Fix CPU counter values for every offline CPU */
 
550
        for (cpu = 1; cpu <= cpu_nr; cpu++) {
 
551
 
 
552
                scc = st_cpu[curr] + cpu;
 
553
                scp = st_cpu[prev] + cpu;
 
554
 
 
555
                if ((scc->cpu_user    + scc->cpu_nice + scc->cpu_sys   +
 
556
                     scc->cpu_iowait  + scc->cpu_idle + scc->cpu_steal +
 
557
                     scc->cpu_hardirq + scc->cpu_softirq) == 0) {
 
558
                        /*
 
559
                         * Offline CPU found.
 
560
                         * Set current struct fields (which have been set to zero)
 
561
                         * to values from previous iteration. Hence their values won't
 
562
                         * jump from zero when the CPU comes back online.
 
563
                         */
 
564
                        *scc = *scp;
 
565
                }
 
566
        }
520
567
}
521
568
 
522
569
/*
523
570
 ***************************************************************************
524
 
 * Print statistics average
 
571
 * Print statistics average.
525
572
 *
526
573
 * IN:
527
574
 * @curr        Position in array where statistics for current sample are.
539
586
 
540
587
/*
541
588
 ***************************************************************************
542
 
 * Print statistics
 
589
 * Print statistics.
543
590
 *
544
591
 * IN:
545
592
 * @curr        Position in array where statistics for current sample are.
859
906
                                dis_hdr++;
860
907
                                
861
908
                                for (t = strtok(argv[opt], ","); t; t = strtok(NULL, ",")) {
862
 
                                        if (!strcmp(t, K_ALL)) {
 
909
                                        if (!strcmp(t, K_ALL) || !strcmp(t, K_ON)) {
863
910
                                                if (cpu_nr) {
864
911
                                                        dis_hdr = 9;
865
912
                                                }
868
915
                                                 * Also indicate to display stats for CPU 'all'.
869
916
                                                 */
870
917
                                                memset(cpu_bitmap, 0xff, ((cpu_nr + 1) >> 3) + 1);
 
918
                                                if (!strcmp(t, K_ON)) {
 
919
                                                        /* Display stats only for online CPU */
 
920
                                                        flags |= F_P_ON;
 
921
                                                }
871
922
                                        }
872
923
                                        else {
873
924
                                                if (strspn(t, DIGITS) != strlen(t)) {