~ubuntu-branches/ubuntu/intrepid/sysstat/intrepid

« back to all changes in this revision

Viewing changes to sar.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
 * sar: report system activity
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 *
80
80
                   "[ -A ] [ -b ] [ -B ] [ -c ] [ -d ] [ -i <interval> ] [ -p ] [ -q ]\n"
81
81
                   "[ -r ] [ -R ] [ -t ] [ -u ] [ -v ] [ -V ] [ -w ] [ -W ] [ -y ]\n"
82
82
                   "[ -I { <irq> | SUM | ALL | XALL } ] [ -P { <cpu> | ALL } ]\n"
83
 
                   "[ -n { DEV | EDEV | NFS | NFSD | SOCK | FULL } ]\n"
 
83
                   "[ -n { DEV | EDEV | NFS | NFSD | SOCK | ALL } ]\n"
84
84
                   "[ -x { <pid> | SELF | ALL } ] [ -X { <pid> | SELF | ALL } ]\n"
85
85
                   "[ -o [ <filename> ] | -f [ <filename> ] ]\n"
86
86
                   "[ -s [ <hh:mm:ss> ] ] [ -e [ <hh:mm:ss> ] ]\n"),
154
154
 */
155
155
void allocate_structures(int stype)
156
156
{
157
 
   if (file_hdr.sa_proc > 0)
158
 
      salloc_cpu_array(st_cpu, file_hdr.sa_proc + 1);
 
157
   if (file_hdr.sa_proc)
 
158
      salloc_cpu_array(st_cpu, file_hdr.sa_proc);
159
159
   if ((stype == USE_SADC) &&
160
160
       (GET_PID(sar_actflag) || GET_CPID(sar_actflag))) {
161
161
      pid_nr = file_hdr.sa_nr_pid;
164
164
   if (file_hdr.sa_serial)
165
165
      salloc_serial_array(st_serial, file_hdr.sa_serial);
166
166
   if (file_hdr.sa_irqcpu)
167
 
      salloc_irqcpu_array(st_irq_cpu, file_hdr.sa_proc + 1, file_hdr.sa_irqcpu);
 
167
      salloc_irqcpu_array(st_irq_cpu, file_hdr.sa_proc, file_hdr.sa_irqcpu);
168
168
   if (file_hdr.sa_iface)
169
169
      salloc_net_dev_array(st_net_dev, file_hdr.sa_iface);
170
170
   if (file_hdr.sa_nr_disk)
184
184
{
185
185
   unsigned int j = 0, i;
186
186
 
187
 
   if (cpu_nr == 0) {
 
187
   if (!cpu_nr) {
188
188
      fprintf(stderr, _("Not an SMP machine...\n"));
189
189
      exit(1);
190
190
   }
191
191
 
192
 
   for (i = (cpu_nr + 1); i < NR_CPUS; i++)
 
192
   for (i = cpu_nr; i < NR_CPUS; i++)
193
193
      j |= cpu_bitmap[i >> 3] & (1 << (i & 0x07));
194
194
 
195
195
   if (j) {
211
211
 
212
212
   if (WANT_PER_PROC(flags)) {
213
213
      if (WANT_ALL_PROC(flags))
214
 
         for (i = cpu_nr + 1; i < ((NR_CPUS >> 3) + 1) << 3; i++)
 
214
         for (i = cpu_nr; i < ((NR_CPUS >> 3) + 1) << 3; i++)
215
215
            /*
216
216
             * Reset every bit for proc > cpu_nr
217
217
             * (only done when -P ALL entered on the command line)
308
308
   if (GET_CPU(act)) {
309
309
      if (dis)
310
310
         printf("\n%-11s       CPU     %%user     %%nice   %%system   "
311
 
                "%%iowait     %%idle\n",
 
311
                "%%iowait    %%steal     %%idle\n",
312
312
                prev_string);
313
313
 
314
314
      if (!WANT_PER_PROC(flags) ||
316
316
 
317
317
         printf("%-11s       all", curr_string);
318
318
 
319
 
         printf("    %6.2f    %6.2f    %6.2f    %6.2f",
 
319
         printf("    %6.2f    %6.2f    %6.2f    %6.2f    %6.2f",
320
320
                ll_sp_value(fsj->cpu_user, fsi->cpu_user, g_itv),
321
321
                ll_sp_value(fsj->cpu_nice, fsi->cpu_nice, g_itv),
322
322
                ll_sp_value(fsj->cpu_system, fsi->cpu_system, g_itv),
323
 
                ll_sp_value(fsj->cpu_iowait, fsi->cpu_iowait, g_itv));
 
323
                ll_sp_value(fsj->cpu_iowait, fsi->cpu_iowait, g_itv),
 
324
                ll_sp_value(fsj->cpu_steal, fsi->cpu_steal, g_itv));
324
325
 
325
326
         printf("    %6.2f\n",
326
327
                fsi->cpu_idle < fsj->cpu_idle ? /* Handle buggy kernels */
333
334
            *sci = st_cpu[curr],
334
335
            *scj = st_cpu[prev];
335
336
        
336
 
         for (i = 0; i <= file_hdr.sa_proc; i++, sci++, scj++) {
 
337
         for (i = 0; i < file_hdr.sa_proc; i++, sci++, scj++) {
337
338
            if (cpu_bitmap[i >> 3] & (1 << (i & 0x07))) {
338
339
 
339
340
               printf("%-11s       %3d", curr_string, i);
341
342
               /* Recalculate itv for current proc */
342
343
               pc_itv = get_per_cpu_interval(sci, scj);
343
344
        
344
 
               printf("    %6.2f    %6.2f    %6.2f    %6.2f",
 
345
               printf("    %6.2f    %6.2f    %6.2f    %6.2f    %6.2f",
345
346
                      ll_sp_value(scj->per_cpu_user, sci->per_cpu_user, pc_itv),
346
347
                      ll_sp_value(scj->per_cpu_nice, sci->per_cpu_nice, pc_itv),
347
348
                      ll_sp_value(scj->per_cpu_system, sci->per_cpu_system, pc_itv),
348
 
                      ll_sp_value(scj->per_cpu_iowait, sci->per_cpu_iowait, pc_itv));
 
349
                      ll_sp_value(scj->per_cpu_iowait, sci->per_cpu_iowait, pc_itv),
 
350
                      ll_sp_value(scj->per_cpu_steal, sci->per_cpu_steal, pc_itv));
349
351
 
350
352
               printf("    %6.2f\n",
351
353
                      sci->per_cpu_idle < scj->per_cpu_idle ?
547
549
         printf("\n");
548
550
      }
549
551
 
550
 
      for (k = 0; k <= file_hdr.sa_proc; k++) {
 
552
      for (k = 0; k < file_hdr.sa_proc; k++) {
551
553
         if (cpu_bitmap[k >> 3] & (1 << (k & 0x07))) {
552
554
 
553
555
            printf("%-11s  %3d", curr_string, k);
610
612
            continue;
611
613
         j = check_iface_reg(&file_hdr, st_net_dev, curr, prev, i);
612
614
         sndj = st_net_dev[prev] + j;
613
 
        
614
615
         printf("%-11s %9s", curr_string, sndi->interface);
615
616
        
616
617
         printf(" %9.2f %9.2f %9.2f %9.2f %9.2f %9.2f %9.2f\n",
1028
1029
   file_stats[!curr].minute      = file_stats[curr].minute;
1029
1030
   file_stats[!curr].second      = file_stats[curr].second;
1030
1031
   file_stats[!curr].ust_time    = file_stats[curr].ust_time;
1031
 
   if (file_hdr.sa_proc > 0)
1032
 
      memset(st_cpu[!curr], 0, STATS_ONE_CPU_SIZE * (file_hdr.sa_proc + 1));
 
1032
   if (file_hdr.sa_proc)
 
1033
      memset(st_cpu[!curr], 0, STATS_ONE_CPU_SIZE * file_hdr.sa_proc);
1033
1034
   memset(interrupts[!curr], 0, STATS_ONE_IRQ_SIZE);
1034
1035
   if (pid_nr)
1035
1036
      memset (pid_stats[!curr][0], 0, PID_STATS_SIZE * pid_nr);
1036
1037
   if (file_hdr.sa_serial)
1037
1038
      memset(st_serial[!curr], 0, STATS_SERIAL_SIZE * file_hdr.sa_serial);
1038
1039
   if (file_hdr.sa_irqcpu)
1039
 
      memset(st_irq_cpu[!curr], 0, STATS_IRQ_CPU_SIZE * (file_hdr.sa_proc + 1) * file_hdr.sa_irqcpu);
 
1040
      memset(st_irq_cpu[!curr], 0, STATS_IRQ_CPU_SIZE * file_hdr.sa_proc * file_hdr.sa_irqcpu);
1040
1041
   if (file_hdr.sa_iface)
1041
1042
      memset(st_net_dev[!curr], 0, STATS_NET_DEV_SIZE * file_hdr.sa_iface);
1042
1043
   if (file_hdr.sa_nr_disk)
1104
1105
void copy_structures(int dest, int src, int stype)
1105
1106
{
1106
1107
   memcpy(&file_stats[dest], &file_stats[src], FILE_STATS_SIZE);
1107
 
   if (file_hdr.sa_proc > 0)
 
1108
   if (file_hdr.sa_proc)
1108
1109
      memcpy(st_cpu[dest], st_cpu[src],
1109
 
             STATS_ONE_CPU_SIZE * (file_hdr.sa_proc + 1));
 
1110
             STATS_ONE_CPU_SIZE * file_hdr.sa_proc);
1110
1111
   if (GET_ONE_IRQ(file_hdr.sa_actflag))
1111
1112
      memcpy(interrupts[dest], interrupts[src],
1112
1113
             STATS_ONE_IRQ_SIZE);
1118
1119
             STATS_SERIAL_SIZE * file_hdr.sa_serial);
1119
1120
   if (file_hdr.sa_irqcpu)
1120
1121
      memcpy(st_irq_cpu[dest], st_irq_cpu[src],
1121
 
             STATS_IRQ_CPU_SIZE * (file_hdr.sa_proc + 1) * file_hdr.sa_irqcpu);
 
1122
             STATS_IRQ_CPU_SIZE * file_hdr.sa_proc * file_hdr.sa_irqcpu);
1122
1123
   if (file_hdr.sa_iface)
1123
1124
      memcpy(st_net_dev[dest], st_net_dev[src],
1124
1125
             STATS_NET_DEV_SIZE * file_hdr.sa_iface);
1135
1136
 */
1136
1137
void read_extra_stats(short curr, int ifd)
1137
1138
{
1138
 
   if (file_hdr.sa_proc > 0)
 
1139
   if (file_hdr.sa_proc)
1139
1140
      sa_fread(ifd, st_cpu[curr],
1140
 
               STATS_ONE_CPU_SIZE * (file_hdr.sa_proc + 1), HARD_SIZE);
 
1141
               STATS_ONE_CPU_SIZE * file_hdr.sa_proc, HARD_SIZE);
1141
1142
   if (GET_ONE_IRQ(file_hdr.sa_actflag))
1142
1143
      sa_fread(ifd, interrupts[curr],
1143
1144
               STATS_ONE_IRQ_SIZE, HARD_SIZE);
1146
1147
               STATS_SERIAL_SIZE * file_hdr.sa_serial, HARD_SIZE);
1147
1148
   if (file_hdr.sa_irqcpu)
1148
1149
      sa_fread(ifd, st_irq_cpu[curr],
1149
 
               STATS_IRQ_CPU_SIZE * (file_hdr.sa_proc + 1) * file_hdr.sa_irqcpu, HARD_SIZE);
 
1150
               STATS_IRQ_CPU_SIZE * file_hdr.sa_proc * file_hdr.sa_irqcpu, HARD_SIZE);
1150
1151
   if (file_hdr.sa_iface)
1151
1152
      sa_fread(ifd, st_net_dev[curr],
1152
1153
               STATS_NET_DEV_SIZE * file_hdr.sa_iface, HARD_SIZE);
1166
1167
{
1167
1168
   if (sa_read(&file_stats[curr], file_hdr.sa_st_size))
1168
1169
      exit(0);
1169
 
   if ((file_hdr.sa_proc > 0) &&
1170
 
       sa_read(st_cpu[curr], STATS_ONE_CPU_SIZE * (file_hdr.sa_proc + 1)))
 
1170
   if ((file_hdr.sa_proc) &&
 
1171
       sa_read(st_cpu[curr], STATS_ONE_CPU_SIZE * file_hdr.sa_proc))
1171
1172
      exit(0);
1172
1173
   if (GET_ONE_IRQ(file_hdr.sa_actflag) &&
1173
1174
       sa_read(interrupts[curr], STATS_ONE_IRQ_SIZE))
1179
1180
       sa_read(st_serial[curr], STATS_SERIAL_SIZE * file_hdr.sa_serial))
1180
1181
      exit(0);
1181
1182
   if (file_hdr.sa_irqcpu &&
1182
 
       sa_read(st_irq_cpu[curr], STATS_IRQ_CPU_SIZE * (file_hdr.sa_proc + 1) * file_hdr.sa_irqcpu))
 
1183
       sa_read(st_irq_cpu[curr], STATS_IRQ_CPU_SIZE * file_hdr.sa_proc * file_hdr.sa_irqcpu))
1183
1184
      exit(0);
1184
1185
   if (file_hdr.sa_iface &&
1185
1186
       sa_read(st_net_dev[curr], STATS_NET_DEV_SIZE * file_hdr.sa_iface))
1196
1197
 ***************************************************************************
1197
1198
 */
1198
1199
void handle_curr_act_stats(int ifd, off_t fpos, short *curr, long *cnt, int *eosaf,
1199
 
                         int rows, unsigned int act, int *reset)
 
1200
                           int rows, unsigned int act, int *reset)
1200
1201
{
1201
1202
   short dis = 1;
1202
1203
   unsigned long lines;
1456
1457
   read_stat_bunch(0);
1457
1458
 
1458
1459
   if (!dis_hdr) {
1459
 
      if (file_hdr.sa_proc > 0)
 
1460
      if (file_hdr.sa_proc)
1460
1461
         more = 2 + file_hdr.sa_proc;
1461
1462
      if (pid_nr)
1462
1463
         more = pid_nr;