~ubuntu-branches/ubuntu/natty/sysstat/natty

« back to all changes in this revision

Viewing changes to sa_common.c

  • Committer: Bazaar Package Importer
  • Author(s): Robert Luberda
  • Date: 2008-11-13 19:46:29 UTC
  • mfrom: (1.1.13 upstream)
  • Revision ID: james.westby@ubuntu.com-20081113194629-kvn8jz6g7unc5ksq
Tags: 8.1.7-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
49
49
 *
50
50
 * IN:
51
51
 * @value       Value used to init bitmap.
52
 
 * @nr          Size of the bitmap in bytes.
 
52
 * @sz          Size of the bitmap in bytes.
53
53
 *
54
54
 * OUT:
55
55
 * @bitmap      Bitmap initialized.
56
56
 ***************************************************************************
57
57
 */
58
 
void set_bitmap(unsigned char bitmap[], unsigned char value, unsigned int nr)
 
58
void set_bitmap(unsigned char bitmap[], unsigned char value, unsigned int sz)
59
59
{
60
60
        register int i;
61
61
 
62
 
        for (i = 0; i < nr; i++) {
 
62
        for (i = 0; i < sz; i++) {
63
63
                bitmap[i] = value;
64
64
        }
65
65
}
77
77
        int i, j;
78
78
        
79
79
        for (i = 0; i < NR_ACT; i++) {
80
 
                if (act[i]->nr > 0) {
81
 
                        for (j = 0; j < 3; j++) {
82
 
                                SREALLOC(act[i]->buf[j], void, act[i]->msize * act[i]->nr);
 
80
                if (*act[i]->nr > 0) {
 
81
                        for (j = 0; j < 3; j++) {
 
82
                                SREALLOC(act[i]->buf[j], void, act[i]->msize * *act[i]->nr);
 
83
                        }
 
84
                }
 
85
        }
 
86
}
 
87
 
 
88
/*
 
89
 ***************************************************************************
 
90
 * Free structures.
 
91
 *
 
92
 * IN:
 
93
 * @act Array of activities.
 
94
 ***************************************************************************
 
95
 */
 
96
void free_structures(struct activity *act[])
 
97
{
 
98
        int i, j;
 
99
        
 
100
        for (i = 0; i < NR_ACT; i++) {
 
101
                if (*act[i]->nr > 0) {
 
102
                        for (j = 0; j < 3; j++) {
 
103
                                if (act[i]->buf[j]) {
 
104
                                        free(act[i]->buf[j]);
 
105
                                }
83
106
                        }
84
107
                }
85
108
        }
201
224
int decode_timestamp(char timestamp[], struct tstamp *tse)
202
225
{
203
226
        timestamp[2] = timestamp[5] = '\0';
204
 
        tse->tm_sec  = atoi(&(timestamp[6]));
205
 
        tse->tm_min  = atoi(&(timestamp[3]));
 
227
        tse->tm_sec  = atoi(&timestamp[6]);
 
228
        tse->tm_min  = atoi(&timestamp[3]);
206
229
        tse->tm_hour = atoi(timestamp);
207
230
 
208
231
        if ((tse->tm_sec < 0) || (tse->tm_sec > 59) ||
352
375
                mktime(rectime);
353
376
        }
354
377
        else {
355
 
                loc_t = localtime((const time_t *) &(file_hdr->sa_ust_time));
 
378
                loc_t = localtime((const time_t *) &file_hdr->sa_ust_time);
356
379
                *rectime = *loc_t;
357
380
        }
358
381
}
408
431
 
409
432
        sndc = (struct stats_net_dev *) a->buf[curr] + pos;
410
433
 
411
 
        while (index < a->nr) {
 
434
        while (index < *a->nr) {
412
435
                sndp = (struct stats_net_dev *) a->buf[ref] + index;
413
436
                if (!strcmp(sndc->interface, sndp->interface)) {
414
437
                        /*
478
501
        }
479
502
 
480
503
        /* Network interface not found: Look for the first free structure */
481
 
        for (index = 0; index < a->nr; index++) {
 
504
        for (index = 0; index < *a->nr; index++) {
482
505
                sndp = (struct stats_net_dev *) a->buf[ref] + index;
483
506
                if (!strcmp(sndp->interface, "?")) {
484
507
                        memset(sndp, 0, STATS_NET_DEV_SIZE);
486
509
                        break;
487
510
                }
488
511
        }
489
 
        if (index >= a->nr) {
 
512
        if (index >= *a->nr) {
490
513
                /* No free structure: Default is structure of same rank */
491
514
                index = pos;
492
515
        }
523
546
 
524
547
        snedc = (struct stats_net_edev *) a->buf[curr] + pos;
525
548
 
526
 
        while (index < a->nr) {
 
549
        while (index < *a->nr) {
527
550
                snedp = (struct stats_net_edev *) a->buf[ref] + index;
528
551
                if (!strcmp(snedc->interface, snedp->interface)) {
529
552
                        /*
553
576
        }
554
577
 
555
578
        /* Network interface not found: Look for the first free structure */
556
 
        for (index = 0; index < a->nr; index++) {
 
579
        for (index = 0; index < *a->nr; index++) {
557
580
                snedp = (struct stats_net_edev *) a->buf[ref] + index;
558
581
                if (!strcmp(snedp->interface, "?")) {
559
582
                        memset(snedp, 0, STATS_NET_EDEV_SIZE);
561
584
                        break;
562
585
                }
563
586
        }
564
 
        if (index >= a->nr) {
 
587
        if (index >= *a->nr) {
565
588
                /* No free structure: Default is structure of same rank */
566
589
                index = pos;
567
590
        }
596
619
 
597
620
        sdc = (struct stats_disk *) a->buf[curr] + pos;
598
621
 
599
 
        while (index < a->nr) {
 
622
        while (index < *a->nr) {
600
623
                sdp = (struct stats_disk *) a->buf[ref] + index;
601
624
                if ((sdc->major == sdp->major) &&
602
625
                    (sdc->minor == sdp->minor)) {
621
644
        }
622
645
 
623
646
        /* Disk not found: Look for the first free structure */
624
 
        for (index = 0; index < a->nr; index++) {
 
647
        for (index = 0; index < *a->nr; index++) {
625
648
                sdp = (struct stats_disk *) a->buf[ref] + index;
626
649
                if (!(sdp->major + sdp->minor)) {
627
650
                        memset(sdp, 0, STATS_DISK_SIZE);
630
653
                        break;
631
654
                }
632
655
        }
633
 
        if (index >= a->nr) {
 
656
        if (index >= *a->nr) {
634
657
                /* No free structure found: Default is structure of same rank */
635
658
                index = pos;
636
659
        }
666
689
 
667
690
/*
668
691
 ***************************************************************************
 
692
 * Free bitmaps for activities that have one.
 
693
 *
 
694
 * IN:
 
695
 * @act         Array of activities.
 
696
 ***************************************************************************
 
697
 */
 
698
void free_bitmaps(struct activity *act[])
 
699
{
 
700
        int i;
 
701
        
 
702
        for (i = 0; i < NR_ACT; i++) {
 
703
                if (act[i]->bitmap_size) {
 
704
                        free(act[i]->bitmap);
 
705
                }
 
706
        }
 
707
}
 
708
 
 
709
/*
 
710
 ***************************************************************************
669
711
 * Look for activity in array.
670
712
 *
671
713
 * IN:
901
943
                        continue;
902
944
 
903
945
                if (((p = get_activity_position(act, id_seq[i])) < 0) ||
904
 
                    (act[p]->nr < 1)) {
 
946
                    (*act[p]->nr < 1)) {
905
947
                        PANIC(1);
906
948
                }
907
949
 
908
 
                memcpy(act[p]->buf[dest], act[p]->buf[src], act[p]->msize * act[p]->nr);
 
950
                memcpy(act[p]->buf[dest], act[p]->buf[src], act[p]->msize * *act[p]->nr);
909
951
                
910
952
        }
911
953
}
941
983
                                exit(2);
942
984
                        }
943
985
                }
944
 
                else if ((act[p]->nr > 1) && (act[p]->msize > act[p]->fsize)) {
945
 
                        for (j = 0; j < act[p]->nr; j++) {
 
986
                else if ((*act[p]->nr > 1) && (act[p]->msize > act[p]->fsize)) {
 
987
                        for (j = 0; j < *act[p]->nr; j++) {
946
988
                                sa_fread(ifd, (char *) act[p]->buf[curr] + j * act[p]->msize,
947
989
                                         act[p]->fsize, HARD_SIZE);
948
990
                        }
949
991
                }
950
 
                else if (act[p]->nr > 0) {
951
 
                        sa_fread(ifd, act[p]->buf[curr], act[p]->fsize * act[p]->nr, HARD_SIZE);
 
992
                else if (*act[p]->nr > 0) {
 
993
                        sa_fread(ifd, act[p]->buf[curr], act[p]->fsize * *act[p]->nr, HARD_SIZE);
952
994
                }
953
995
                else {
954
 
                        PANIC(act[p]->nr);
 
996
                        PANIC(*act[p]->nr);
955
997
                }
956
998
        }
957
999
}
1039
1081
                                act[p]->msize = fal->size;
1040
1082
                        }
1041
1083
                        act[p]->fsize = fal->size;
1042
 
                        act[p]->nr    = fal->nr;
 
1084
                        *act[p]->nr   = fal->nr;
1043
1085
                        id_seq[j++]   = fal->id;
1044
1086
                }
1045
1087
        }
1122
1164
                        break;
1123
1165
                        
1124
1166
                case 'B':
1125
 
                        act[get_activity_position(act, A_PAGE)]->options |= AO_SELECTED;
 
1167
                        SELECT_ACTIVITY(A_PAGE);
1126
1168
                        break;
1127
1169
                        
1128
1170
                case 'b':
1129
 
                        act[get_activity_position(act, A_IO)]->options |= AO_SELECTED;
 
1171
                        SELECT_ACTIVITY(A_IO);
1130
1172
                        break;
1131
1173
                        
1132
1174
                case 'C':
1134
1176
                        break;
1135
1177
                        
1136
1178
                case 'd':
1137
 
                        act[get_activity_position(act, A_DISK)]->options |= AO_SELECTED;
 
1179
                        SELECT_ACTIVITY(A_DISK);
1138
1180
                        break;
1139
1181
                        
1140
1182
                case 'p':
1142
1184
                        break;
1143
1185
                        
1144
1186
                case 'q':
1145
 
                        act[get_activity_position(act, A_QUEUE)]->options |= AO_SELECTED;
 
1187
                        SELECT_ACTIVITY(A_QUEUE);
1146
1188
                        break;
1147
1189
                        
1148
1190
                case 'r':
1174
1216
                case 'u':
1175
1217
                        p = get_activity_position(act, A_CPU);
1176
1218
                        act[p]->options |= AO_SELECTED;
1177
 
                        if (!(*(argv[*opt] + i + 1)) && argv[(*opt) + 1] && !strcmp(argv[(*opt) + 1], K_ALL)) {
 
1219
                        if (!*(argv[*opt] + i + 1) && argv[*opt + 1] && !strcmp(argv[*opt + 1], K_ALL)) {
1178
1220
                                (*opt)++;
1179
1221
                                act[p]->opt_flags = AO_F_CPU_ALL;
1180
1222
                        }
1184
1226
                        return 0;
1185
1227
                        
1186
1228
                case 'v':
1187
 
                        act[get_activity_position(act, A_KTABLES)]->options |= AO_SELECTED;
 
1229
                        SELECT_ACTIVITY(A_KTABLES);
1188
1230
                        break;
1189
1231
                        
1190
1232
                case 'w':
1191
 
                        act[get_activity_position(act, A_PCSW)]->options |= AO_SELECTED;
 
1233
                        SELECT_ACTIVITY(A_PCSW);
1192
1234
                        break;
1193
1235
                        
1194
1236
                case 'W':
1195
 
                        act[get_activity_position(act, A_SWAP)]->options |= AO_SELECTED;
 
1237
                        SELECT_ACTIVITY(A_SWAP);
1196
1238
                        break;
1197
1239
                        
1198
1240
                case 'y':
1199
 
                        act[get_activity_position(act, A_SERIAL)]->options |= AO_SELECTED;
 
1241
                        SELECT_ACTIVITY(A_SERIAL);
1200
1242
                        break;
1201
1243
                        
1202
1244
                case 'V':
1228
1270
int parse_sar_n_opt(char *argv[], int *opt, struct activity *act[])
1229
1271
{
1230
1272
        if (!strcmp(argv[*opt], K_DEV)) {
1231
 
                act[get_activity_position(act, A_NET_DEV)]->options  |= AO_SELECTED;
 
1273
                SELECT_ACTIVITY(A_NET_DEV);
1232
1274
        }
1233
1275
        else if (!strcmp(argv[*opt], K_EDEV)) {
1234
 
                act[get_activity_position(act, A_NET_EDEV)]->options |= AO_SELECTED;
 
1276
                SELECT_ACTIVITY(A_NET_EDEV);
1235
1277
        }
1236
1278
        else if (!strcmp(argv[*opt], K_SOCK)) {
1237
 
                act[get_activity_position(act, A_NET_SOCK)]->options |= AO_SELECTED;
 
1279
                SELECT_ACTIVITY(A_NET_SOCK);
1238
1280
        }
1239
1281
        else if (!strcmp(argv[*opt], K_NFS)) {
1240
 
                act[get_activity_position(act, A_NET_NFS)]->options  |= AO_SELECTED;
 
1282
                SELECT_ACTIVITY(A_NET_NFS);
1241
1283
        }
1242
1284
        else if (!strcmp(argv[*opt], K_NFSD)) {
1243
 
                act[get_activity_position(act, A_NET_NFSD)]->options |= AO_SELECTED;
 
1285
                SELECT_ACTIVITY(A_NET_NFSD);
 
1286
        }
 
1287
        else if (!strcmp(argv[*opt], K_IP)) {
 
1288
                SELECT_ACTIVITY(A_NET_IP);
 
1289
        }
 
1290
        else if (!strcmp(argv[*opt], K_EIP)) {
 
1291
                SELECT_ACTIVITY(A_NET_EIP);
 
1292
        }
 
1293
        else if (!strcmp(argv[*opt], K_ICMP)) {
 
1294
                SELECT_ACTIVITY(A_NET_ICMP);
 
1295
        }
 
1296
        else if (!strcmp(argv[*opt], K_EICMP)) {
 
1297
                SELECT_ACTIVITY(A_NET_EICMP);
 
1298
        }
 
1299
        else if (!strcmp(argv[*opt], K_TCP)) {
 
1300
                SELECT_ACTIVITY(A_NET_TCP);
 
1301
        }
 
1302
        else if (!strcmp(argv[*opt], K_ETCP)) {
 
1303
                SELECT_ACTIVITY(A_NET_ETCP);
 
1304
        }
 
1305
        else if (!strcmp(argv[*opt], K_UDP)) {
 
1306
                SELECT_ACTIVITY(A_NET_UDP);
1244
1307
        }
1245
1308
        else if (!strcmp(argv[*opt], K_ALL)) {
1246
 
                act[get_activity_position(act, A_NET_DEV)]->options  |= AO_SELECTED;
1247
 
                act[get_activity_position(act, A_NET_EDEV)]->options |= AO_SELECTED;
1248
 
                act[get_activity_position(act, A_NET_SOCK)]->options |= AO_SELECTED;
1249
 
                act[get_activity_position(act, A_NET_NFS)]->options  |= AO_SELECTED;
1250
 
                act[get_activity_position(act, A_NET_NFSD)]->options |= AO_SELECTED;
 
1309
                SELECT_ACTIVITY(A_NET_DEV);
 
1310
                SELECT_ACTIVITY(A_NET_EDEV);
 
1311
                SELECT_ACTIVITY(A_NET_SOCK);
 
1312
                SELECT_ACTIVITY(A_NET_NFS);
 
1313
                SELECT_ACTIVITY(A_NET_NFSD);
 
1314
                SELECT_ACTIVITY(A_NET_IP);
 
1315
                SELECT_ACTIVITY(A_NET_EIP);
 
1316
                SELECT_ACTIVITY(A_NET_ICMP);
 
1317
                SELECT_ACTIVITY(A_NET_EICMP);
 
1318
                SELECT_ACTIVITY(A_NET_TCP);
 
1319
                SELECT_ACTIVITY(A_NET_ETCP);
 
1320
                SELECT_ACTIVITY(A_NET_UDP);
1251
1321
        }
1252
1322
        else
1253
1323
                return 1;