~ubuntu-branches/ubuntu/hardy/sysstat/hardy

« back to all changes in this revision

Viewing changes to sadf.c

  • Committer: Bazaar Package Importer
  • Author(s): Robert Luberda
  • Date: 2006-05-29 20:11:57 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20060529201157-e6mxz13s36uq4fzd
Tags: 6.1.3-1
* New upstream version (development):
  + daily data files format has changed again.
* debian/control: Standards-Version: 3.7.2 (no changes needed).
* debian/watch: prefer downloads from the upstream site.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 * sadf: system activity data formatter
3
 
 * (C) 1999-2005 by Sebastien GODARD (sysstat <at> wanadoo.fr)
 
3
 * (C) 1999-2006 by Sebastien GODARD (sysstat <at> wanadoo.fr)
4
4
 *
5
5
 ***************************************************************************
6
6
 * This program is free software; you can redistribute it and/or modify it *
76
76
{
77
77
   fprintf(stderr, _("Usage: %s [ options... ] [ <interval> [ <count> ] ] [ <datafile> ]\n"
78
78
                   "Options are:\n"
79
 
                   "[ -d | -H | -p | -x ] [ -t ] [ -V ]\n"
 
79
                   "[ -d | -D | -H | -p | -x ] [ -t ] [ -V ]\n"
80
80
                   "[ -P { <cpu> | ALL } ] [ -s [ <hh:mm:ss> ] ] [ -e [ <hh:mm:ss> ] ]\n"
81
81
                   "[ -- <sar_options...> ]\n"),
82
82
           progname);
109
109
   va_list args;
110
110
 
111
111
   va_start(args, fmt);
112
 
   vsprintf(buf, fmt, args);
 
112
   vsnprintf(buf, sizeof(buf), fmt, args);
113
113
   va_end(args);
114
114
 
115
115
   prtab(nr_tab);
132
132
   /* NOTE: loc_time structure must have been init'ed before! */
133
133
   if (PRINT_TRUE_TIME(flags) &&
134
134
       ((format == S_O_DB_OPTION) || (format == S_O_XML_OPTION)))
135
 
      /* '-d -t' or '-x -t' */
 
135
      /* '-d -t' or '-x -t'. Option -t is ignored with option -p and -D */
136
136
      ltm = localtime(&file_stats[curr].ust_time);
137
137
   else
138
 
      /* '-p' or '-p -t' or '-d' or '-x' */
 
138
      /* '-p' od '-D' or '-d' or '-x' */
139
139
      ltm = gmtime(&file_stats[curr].ust_time);
140
140
 
141
141
   loc_time = *ltm;
158
158
      else
159
159
         strftime(cur_time, len, "%Y-%m-%d %H:%M:%S UTC", &loc_time);
160
160
   }
161
 
   else if (format == S_O_PPC_OPTION)
 
161
   else if ((format == S_O_PPC_OPTION) || (format == S_O_DBD_OPTION))
162
162
      sprintf(cur_time, "%ld", file_stats[curr].ust_time);
163
163
}
164
164
 
282
282
   struct file_stats
283
283
      *fsi = &file_stats[curr],
284
284
      *fsj = &file_stats[!curr];
285
 
 
286
285
   char pre[80];        /* Text at beginning of each line */
287
286
   int wantproc = !WANT_PER_PROC(flags)
288
287
      || (WANT_PER_PROC(flags) && WANT_ALL_PROC(flags));
289
 
   int isdb = (format == S_O_DB_OPTION);
290
 
 
 
288
   int isdb = ((format == S_O_DB_OPTION) || (format == S_O_DBD_OPTION));
291
289
 
292
290
   /*
293
291
    * This substring appears on every output line, preformat it here
341
339
             NOVAL,
342
340
             ll_sp_value(fsj->cpu_iowait, fsi->cpu_iowait, g_itv));
343
341
 
 
342
      render(isdb, pre, PT_NOFLAG,
 
343
             "all\t%%steal", NULL, NULL,
 
344
             NOVAL,
 
345
             ll_sp_value(fsj->cpu_steal, fsi->cpu_steal, g_itv));
 
346
 
344
347
      render(isdb, pre, PT_NEWLIN,
345
348
             "all\t%%idle", NULL, NULL,
346
349
             NOVAL,
357
360
         *sci = st_cpu[curr],
358
361
         *scj = st_cpu[!curr];
359
362
 
360
 
      for (i = 0; i <= file_hdr.sa_proc; i++, sci++, scj++) {
 
363
      for (i = 0; i < file_hdr.sa_proc; i++, sci++, scj++) {
361
364
         if (cpu_bitmap[i >> 3] & (1 << (i & 0x07))) {
362
365
 
363
366
            /* Recalculate itv for current proc */
385
388
                   NOVAL,
386
389
                   ll_sp_value(scj->per_cpu_iowait, sci->per_cpu_iowait, pc_itv));
387
390
 
 
391
            render(isdb, pre, PT_NOFLAG,
 
392
                   "cpu%d\t%%steal", NULL, cons(iv, i, NOVAL),
 
393
                   NOVAL,
 
394
                   ll_sp_value(scj->per_cpu_steal, sci->per_cpu_steal, pc_itv));
 
395
 
388
396
            render(isdb, pre, PT_NEWLIN,
389
397
                   "cpu%d\t%%idle", NULL, cons(iv, i, NOVAL),
390
398
                   NOVAL,
570
578
      int j, k, offset;
571
579
      struct stats_irq_cpu *p, *q, *p0, *q0;
572
580
 
573
 
      for (k = 0; k <= file_hdr.sa_proc; k++) {
 
581
      for (k = 0; k < file_hdr.sa_proc; k++) {
574
582
         if (!(cpu_bitmap[k >> 3] & (1 << (k & 0x07))))
575
583
            continue;
576
584
 
1026
1034
   /* cpu */
1027
1035
   xprintf(*tab, "<cpu-load>");
1028
1036
   xprintf(++(*tab), "<cpu number=\"all\" user=\"%.2f\" nice=\"%.2f\" "
1029
 
                     "system=\"%.2f\" iowait=\"%.2f\" idle=\"%.2f\"/>",
 
1037
                     "system=\"%.2f\" iowait=\"%.2f\" steal=\"%.2f\" idle=\"%.2f\"/>",
1030
1038
           ll_sp_value(fsj->cpu_user, fsi->cpu_user, g_itv),
1031
1039
           ll_sp_value(fsj->cpu_nice, fsi->cpu_nice, g_itv),
1032
1040
           ll_sp_value(fsj->cpu_system, fsi->cpu_system, g_itv),
1033
1041
           ll_sp_value(fsj->cpu_iowait, fsi->cpu_iowait, g_itv),
 
1042
           ll_sp_value(fsj->cpu_steal, fsi->cpu_steal, g_itv),
1034
1043
           (fsi->cpu_idle < fsj->cpu_idle)
1035
1044
           ? 0.0
1036
1045
           : ll_sp_value(fsj->cpu_idle, fsi->cpu_idle, g_itv));
1041
1050
         *sci = st_cpu[curr],
1042
1051
         *scj = st_cpu[!curr];
1043
1052
 
1044
 
      for (i = 0; i <= file_hdr.sa_proc; i++, sci++, scj++) {
 
1053
      for (i = 0; i < file_hdr.sa_proc; i++, sci++, scj++) {
1045
1054
 
1046
1055
         /* Recalculate itv for current proc */
1047
1056
         pc_itv = get_per_cpu_interval(sci, scj);
1048
1057
        
1049
1058
         xprintf(*tab, "<cpu number=\"%d\" user=\"%.2f\" nice=\"%.2f\" "
1050
 
                       "system=\"%.2f\" iowait=\"%.2f\" idle=\"%.2f\"/>",
 
1059
                       "system=\"%.2f\" iowait=\"%.2f\" steal=\"%.2f\" idle=\"%.2f\"/>",
1051
1060
                 i,
1052
1061
                 ll_sp_value(scj->per_cpu_user, sci->per_cpu_user, pc_itv),
1053
1062
                 ll_sp_value(scj->per_cpu_nice, sci->per_cpu_nice, pc_itv),
1054
1063
                 ll_sp_value(scj->per_cpu_system, sci->per_cpu_system, pc_itv),
1055
1064
                 ll_sp_value(scj->per_cpu_iowait, sci->per_cpu_iowait, pc_itv),
 
1065
                 ll_sp_value(scj->per_cpu_steal, sci->per_cpu_steal, pc_itv),
1056
1066
                 (sci->per_cpu_idle < scj->per_cpu_idle)
1057
1067
                 ? 0.0
1058
1068
                 : ll_sp_value(scj->per_cpu_idle, sci->per_cpu_idle, pc_itv));
1083
1093
      xprintf(*tab, "<int-proc per=\"second\">");
1084
1094
      (*tab)++;
1085
1095
 
1086
 
      for (k = 0; k <= file_hdr.sa_proc; k++) {
 
1096
      for (k = 0; k < file_hdr.sa_proc; k++) {
1087
1097
 
1088
1098
         for (j = 0; j < file_hdr.sa_irqcpu; j++) {
1089
1099
            p0 = st_irq_cpu[curr] + j;  /* irq field set only for proc #0 */
1393
1403
   if (format == S_O_PPC_OPTION)
1394
1404
      printf("%s\t-1\t%ld\tLINUX-RESTART\n",
1395
1405
             file_hdr.sa_nodename, file_stats[curr].ust_time);
1396
 
   else if (format == S_O_DB_OPTION)
 
1406
   else if ((format == S_O_DB_OPTION) || (format ==S_O_DBD_OPTION))
1397
1407
      printf("%s;-1;%s;LINUX-RESTART\n",
1398
1408
             file_hdr.sa_nodename, cur_time);
1399
1409
}
1412
1422
                    file_hdr->sa_release, file_hdr->sa_nodename);
1413
1423
 
1414
1424
   printf("Activity flag: %#x\n", file_hdr->sa_actflag);
1415
 
   printf("#CPU:    %u\n", file_hdr->sa_proc + 1);
 
1425
   printf("Sizeof(long): %d\n", file_hdr->sa_sizeof_long);
 
1426
   printf("#CPU:    %u\n", file_hdr->sa_proc);
1416
1427
   printf("#IrqCPU: %u\n", file_hdr->sa_irqcpu);
1417
1428
   printf("#Disks:  %u\n", file_hdr->sa_nr_disk);
1418
1429
   printf("#Serial: %u\n", file_hdr->sa_serial);
1447
1458
 */
1448
1459
void allocate_structures(int stype)
1449
1460
{
1450
 
   if (file_hdr.sa_proc > 0)
1451
 
      salloc_cpu_array(st_cpu, file_hdr.sa_proc + 1);
 
1461
   if (file_hdr.sa_proc)
 
1462
      salloc_cpu_array(st_cpu, file_hdr.sa_proc);
1452
1463
   if (file_hdr.sa_serial)
1453
1464
      salloc_serial_array(st_serial, file_hdr.sa_serial);
1454
1465
   if (file_hdr.sa_irqcpu)
1455
 
      salloc_irqcpu_array(st_irq_cpu, file_hdr.sa_proc + 1,
 
1466
      salloc_irqcpu_array(st_irq_cpu, file_hdr.sa_proc,
1456
1467
                          file_hdr.sa_irqcpu);
1457
1468
   if (file_hdr.sa_iface)
1458
1469
      salloc_net_dev_array(st_net_dev, file_hdr.sa_iface);
1469
1480
void copy_structures(int dest, int src)
1470
1481
{
1471
1482
   memcpy(&file_stats[dest], &file_stats[src], FILE_STATS_SIZE);
1472
 
   if (file_hdr.sa_proc > 0)
 
1483
   if (file_hdr.sa_proc)
1473
1484
      memcpy(st_cpu[dest], st_cpu[src],
1474
 
             STATS_ONE_CPU_SIZE * (file_hdr.sa_proc + 1));
 
1485
             STATS_ONE_CPU_SIZE * file_hdr.sa_proc);
1475
1486
   if (GET_ONE_IRQ(file_hdr.sa_actflag))
1476
1487
      memcpy(interrupts[dest], interrupts[src],
1477
1488
             STATS_ONE_IRQ_SIZE);
1480
1491
             STATS_SERIAL_SIZE * file_hdr.sa_serial);
1481
1492
   if (file_hdr.sa_irqcpu)
1482
1493
      memcpy(st_irq_cpu[dest], st_irq_cpu[src],
1483
 
             STATS_IRQ_CPU_SIZE * (file_hdr.sa_proc + 1) * file_hdr.sa_irqcpu);
 
1494
             STATS_IRQ_CPU_SIZE * file_hdr.sa_proc * file_hdr.sa_irqcpu);
1484
1495
   if (file_hdr.sa_iface)
1485
1496
      memcpy(st_net_dev[dest], st_net_dev[src],
1486
1497
             STATS_NET_DEV_SIZE * file_hdr.sa_iface);
1497
1508
 */
1498
1509
void read_extra_stats(short curr, int ifd)
1499
1510
{
1500
 
   if (file_hdr.sa_proc > 0)
 
1511
   if (file_hdr.sa_proc)
1501
1512
      sa_fread(ifd, st_cpu[curr],
1502
 
               STATS_ONE_CPU_SIZE * (file_hdr.sa_proc + 1), HARD_SIZE);
 
1513
               STATS_ONE_CPU_SIZE * file_hdr.sa_proc, HARD_SIZE);
1503
1514
   if (GET_ONE_IRQ(file_hdr.sa_actflag))
1504
1515
      sa_fread(ifd, interrupts[curr],
1505
1516
               STATS_ONE_IRQ_SIZE, HARD_SIZE);
1508
1519
               STATS_SERIAL_SIZE * file_hdr.sa_serial, HARD_SIZE);
1509
1520
   if (file_hdr.sa_irqcpu)
1510
1521
      sa_fread(ifd, st_irq_cpu[curr],
1511
 
               STATS_IRQ_CPU_SIZE * (file_hdr.sa_proc + 1) * file_hdr.sa_irqcpu, HARD_SIZE);
 
1522
               STATS_IRQ_CPU_SIZE * file_hdr.sa_proc * file_hdr.sa_irqcpu, HARD_SIZE);
1512
1523
   if (file_hdr.sa_iface)
1513
1524
      sa_fread(ifd, st_net_dev[curr],
1514
1525
               STATS_NET_DEV_SIZE * file_hdr.sa_iface, HARD_SIZE);
1876
1887
                     usage(argv[0]);
1877
1888
                  format = S_O_DB_OPTION;
1878
1889
                  break;
 
1890
                case 'D':
 
1891
                  if (format && (format != S_O_DBD_OPTION))
 
1892
                     usage(argv[0]);
 
1893
                  format = S_O_DBD_OPTION;
 
1894
                  break;
1879
1895
                case 'H':
1880
1896
                  if (format && (format != S_O_HDR_OPTION))
1881
1897
                     usage(argv[0]);