~ubuntu-branches/ubuntu/quantal/sysstat/quantal

« back to all changes in this revision

Viewing changes to sar.c

  • Committer: Bazaar Package Importer
  • Author(s): Dave Walker (Daviey)
  • Date: 2011-02-09 17:10:56 UTC
  • mfrom: (1.1.19 upstream) (2.1.11 sid)
  • Revision ID: james.westby@ubuntu.com-20110209171056-ep8aecyxtppsrbnf
Tags: 9.1.7-2ubuntu1
* debian/patches/cflags-ordering.patch: Re-arrange CFLAGS in 
  ./Makefile.in to resolve FTBFS. (LP: #716043)
* debian/control: Updated maintainer, as per policy.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 * sar: report system activity
3
 
 * (C) 1999-2009 by Sebastien GODARD (sysstat <at> orange.fr)
 
3
 * (C) 1999-2010 by Sebastien GODARD (sysstat <at> orange.fr)
4
4
 *
5
5
 ***************************************************************************
6
6
 * This program is free software; you can redistribute it and/or modify it *
50
50
int dis = TRUE;
51
51
 
52
52
unsigned int flags = 0;
 
53
unsigned int dm_major;  /* Device-mapper major number */
 
54
 
53
55
char timestamp[2][TIMESTAMP_LEN];
54
56
 
55
57
unsigned long avg_count = 0;
102
104
 
103
105
        print_usage_title(progname);
104
106
        fprintf(stderr, _("Options are:\n"
105
 
                          "[ -A ] [ -b ] [ -B ] [ -C ] [ -d ] [ -h ] [ -m ] [ -p ] [ -q ] [ -r ] [ -R ]\n"
106
 
                          "[ -S ] [ -t ] [ -u [ ALL ] ] [ -v ] [ -V ] [ -w ] [ -W ] [ -y ]\n"
 
107
                          "[ -A ] [ -b ] [ -B ] [ -C ] [ -d ] [ -h ] [ -H ] [ -p ] [ -q ] [ -r ]\n"
 
108
                          "[ -R ] [ -S ] [ -t ] [ -u [ ALL ] ] [ -v ] [ -V ] [ -w ] [ -W ] [ -y ]\n"
107
109
                          "[ -I { <int> [,...] | SUM | ALL | XALL } ] [ -P { <cpu> [,...] | ALL } ]\n"
108
 
                          "[ -n { <keyword> [,...] | ALL } ]\n"
 
110
                          "[ -m { <keyword> [,...] | ALL } ] [ -n { <keyword> [,...] | ALL } ]\n"
109
111
                          "[ -o [ <filename> ] | -f [ <filename> ] ]\n"
110
112
                          "[ -i <interval> ] [ -s [ <hh:mm:ss> ] ] [ -e [ <hh:mm:ss> ] ]\n"));
111
113
        exit(1);
127
129
        fprintf(stderr, _("\t-b\tI/O and transfer rate statistics\n"));
128
130
        fprintf(stderr, _("\t-B\tPaging statistics\n"));
129
131
        fprintf(stderr, _("\t-d\tBlock device statistics\n"));
 
132
        fprintf(stderr, _("\t-H\tHugepages utilization statistics\n"));
130
133
        fprintf(stderr, _("\t-I { <int> | SUM | ALL | XALL }\n"
131
134
                          "\t\tInterrupts statistics\n"));
132
 
        fprintf(stderr, _("\t-m\tPower management statistics\n"));
 
135
        fprintf(stderr, _("\t-m { <keyword> [,...] | ALL }\n"
 
136
                          "\t\tPower management statistics\n"
 
137
                          "\t\tKeywords are:\n"
 
138
                          "\t\tCPU\tCPU instantaneous clock frequency\n"
 
139
                          "\t\tFAN\tFans speed\n"
 
140
                          "\t\tFREQ\tCPU average clock frequency\n"
 
141
                          "\t\tIN\tVoltage inputs\n"
 
142
                          "\t\tTEMP\tDevices temperature\n"));
133
143
        fprintf(stderr, _("\t-n { <keyword> [,...] | ALL }\n"
134
144
                          "\t\tNetwork statistics\n"
135
145
                          "\t\tKeywords are:\n"
211
221
 ***************************************************************************
212
222
 * Check that every selected activity actually belongs to the sequence list.
213
223
 * If not, then the activity should be unselected since it will not be sent
214
 
 * by sadc. An activity can be unsent if its number of items is null.
 
224
 * by sadc. An activity can be not sent if its number of items is null.
215
225
 *
216
226
 * IN:
217
227
 * @act_nr      Size of sequence list.
237
247
 
238
248
/*
239
249
 ***************************************************************************
240
 
 * Fill the rectime structure with current record's time, based on current
241
 
 * record's time data saved in file.
 
250
 * Fill the (struct tm) rectime structure with current record's time,
 
251
 * based on current record's time data saved in file.
242
252
 * The resulting timestamp is expressed in the locale of the file creator
243
253
 * or in the user's own locale depending on whether option -t has been used
244
254
 * or not.
245
255
 *
246
256
 * IN:
247
257
 * @curr        Index in array for current sample statistics.
 
258
 *
 
259
 * RETURNS:
 
260
 * 1 if an error was detected, or 0 otherwise.
248
261
 ***************************************************************************
249
262
*/
250
 
void sar_get_record_timestamp_struct(int curr)
 
263
int sar_get_record_timestamp_struct(int curr)
251
264
{
252
265
        struct tm *ltm;
253
266
 
259
272
                rectime.tm_sec  = record_hdr[curr].second;
260
273
        }
261
274
        else {
262
 
                ltm = localtime((const time_t *) &record_hdr[curr].ust_time);
 
275
                if ((ltm = localtime((const time_t *) &record_hdr[curr].ust_time)) == NULL)
 
276
                        /*
 
277
                         * An error was detected.
 
278
                         * The rectime structure has NOT been updated.
 
279
                         */
 
280
                        return 1;
 
281
                
263
282
                rectime = *ltm;
264
283
        }
 
284
        
 
285
        return 0;
265
286
}
266
287
 
267
288
/*
310
331
 *
311
332
 * OUT:
312
333
 * @cur_time    Timestamp string.
 
334
 *
 
335
 * RETURNS:
 
336
 * 1 if an error was detected, or 0 otherwise.
313
337
 ***************************************************************************
314
338
*/
315
 
void set_record_timestamp_string(int curr, char *cur_time, int len)
 
339
int set_record_timestamp_string(int curr, char *cur_time, int len)
316
340
{
317
341
        /* Fill timestamp structure */
318
 
        sar_get_record_timestamp_struct(curr);
 
342
        if (sar_get_record_timestamp_struct(curr))
 
343
                /* Error detected */
 
344
                return 1;
319
345
 
320
346
        /* Set cur_time date value */
321
347
        strftime(cur_time, len, "%X", &rectime);
 
348
 
 
349
        return 0;
322
350
}
323
351
 
324
352
/*
400
428
 * @cnt                 Number of remaining lines to display.
401
429
 *
402
430
 * RETURNS:
403
 
 * 1 if stats have been successfully displayed.
 
431
 * 1 if stats have been successfully displayed, and 0 otherwise.
404
432
 ***************************************************************************
405
433
 */
406
434
int write_stats(int curr, int read_from_file, long *cnt, int use_tm_start,
423
451
        }
424
452
 
425
453
        /* Set previous timestamp */
426
 
        set_record_timestamp_string(!curr, timestamp[!curr], 16);
 
454
        if (set_record_timestamp_string(!curr, timestamp[!curr], 16))
 
455
                return 0;
427
456
        /* Set current timestamp */
428
 
        set_record_timestamp_string(curr,  timestamp[curr],  16);
 
457
        if (set_record_timestamp_string(curr,  timestamp[curr],  16))
 
458
                return 0;
429
459
 
430
460
        /* Check if we are beginning a new day */
431
461
        if (use_tm_start && record_hdr[!curr].ust_time &&
502
532
        record_hdr[!curr].ust_time    = record_hdr[curr].ust_time;
503
533
 
504
534
        for (i = 0; i < NR_ACT; i++) {
505
 
                if (IS_SELECTED(act[i]->options) && (act[i]->nr > 0))
506
 
                        memset(act[i]->buf[!curr], 0, act[i]->msize * act[i]->nr);
 
535
                if (IS_SELECTED(act[i]->options) && (act[i]->nr > 0)) {
 
536
                        memset(act[i]->buf[!curr], 0, act[i]->msize * act[i]->nr * act[i]->nr2);
 
537
                }
507
538
        }
508
539
        
509
540
        flags |= S_F_SINCE_BOOT;
562
593
 * @ifd                 Input file descriptor.
563
594
 *
564
595
 * RETURNS:
565
 
 * 1 if the record has been successfully displayed.
 
596
 * 1 if the record has been successfully displayed, and 0 otherwise.
566
597
 ***************************************************************************
567
598
 */
568
599
int sar_print_special(int curr, int use_tm_start, int use_tm_end, int rtype, int ifd)
570
601
        char cur_time[26];
571
602
        int dp = 1;
572
603
 
573
 
        set_record_timestamp_string(curr, cur_time, 26);
 
604
        if (set_record_timestamp_string(curr, cur_time, 26))
 
605
                return 0;
574
606
 
575
607
        /* The record must be in the interval specified by -s/-e options */
576
608
        if ((use_tm_start && (datecmp(&rectime, &tm_start) < 0)) ||
611
643
void read_sadc_stat_bunch(int curr)
612
644
{
613
645
        int i, p;
614
 
        
 
646
 
615
647
        /* Read record header (type is always R_STATS since it is read from sadc) */
616
648
        if (sa_read(&record_hdr[curr], RECORD_HEADER_SIZE)) {
617
649
                print_read_error();
624
656
                if ((p = get_activity_position(act, id_seq[i])) < 0) {
625
657
                        PANIC(1);
626
658
                }
627
 
                
628
 
                if (sa_read(act[p]->buf[curr], act[p]->fsize * act[p]->nr)) {
 
659
 
 
660
                if (sa_read(act[p]->buf[curr], act[p]->fsize * act[p]->nr * act[p]->nr2)) {
629
661
                        print_read_error();
630
662
                }
631
663
        }
794
826
 
795
827
                p = get_activity_position(act, file_act.id);
796
828
 
797
 
                if ((p < 0) || (act[p]->fsize != file_act.size) || !file_act.nr) {
 
829
                if ((p < 0) || (act[p]->fsize != file_act.size)
 
830
                            || !file_act.nr
 
831
                            || !file_act.nr2
 
832
                            || (act[p]->magic != file_act.magic)) {
 
833
                        /* Remember that we are reading data from sadc and not from a file... */
798
834
                        fprintf(stderr, _("Inconsistent input data\n"));
799
835
                        exit(3);
800
836
                }
801
837
 
802
838
                id_seq[i]   = file_act.id;      /* We necessarily have "i < NR_ACT" */
803
839
                act[p]->nr  = file_act.nr;
 
840
                act[p]->nr2 = file_act.nr2;
804
841
        }
805
842
 
806
843
        while (i < NR_ACT) {
865
902
                                 */
866
903
                                read_file_stat_bunch(act, 0, ifd, file_hdr.sa_nr_act,
867
904
                                                     file_actlst);
868
 
                                sar_get_record_timestamp_struct(0);
 
905
                                if (sar_get_record_timestamp_struct(0))
 
906
                                        /*
 
907
                                         * An error was detected.
 
908
                                         * The timestamp hasn't been updated.
 
909
                                         */
 
910
                                        continue;
869
911
                        }
870
912
                }
871
913
                while ((rtype == R_RESTART) || (rtype == R_COMMENT) ||
883
925
                        exit(2);
884
926
                }
885
927
 
886
 
                /* Read and write stats located between two possible Linux restarts */
 
928
                /*
 
929
                 * Read and write stats located between two possible Linux restarts.
 
930
                 * Activities that should be displayed are saved in id_seq[] array.
 
931
                 */
887
932
                for (i = 0; i < NR_ACT; i++) {
888
933
 
889
934
                        if (!id_seq[i])
1014
1059
                            NO_RESET, ALL_ACTIVITIES);
1015
1060
 
1016
1061
                if (record_hdr[curr].record_type == R_LAST_STATS) {
1017
 
                        /* File rotation is happening: re-read header data sent by sadc */
 
1062
                        /* File rotation is happening: Re-read header data sent by sadc */
1018
1063
                        read_header_data();
1019
1064
                        allocate_structures(act);
1020
1065
                }
1040
1085
 */
1041
1086
int main(int argc, char **argv)
1042
1087
{
1043
 
        int opt = 1, args_idx = 2;
 
1088
        int i, opt = 1, args_idx = 2;
1044
1089
        int fd[2];
1045
1090
        char from_file[MAX_FILE_LEN], to_file[MAX_FILE_LEN];
1046
1091
        char ltemp[20];
1141
1186
                        flags |= S_F_INTERVAL_SET;
1142
1187
                }
1143
1188
 
 
1189
                else if (!strcmp(argv[opt], "-m")) {
 
1190
                        if (argv[++opt]) {
 
1191
                                /* Parse option -m */
 
1192
                                if (parse_sar_m_opt(argv, &opt, act)) {
 
1193
                                        usage(argv[0]);
 
1194
                                }
 
1195
                        }
 
1196
                        else {
 
1197
                                usage(argv[0]);
 
1198
                        }
 
1199
                }
 
1200
 
1144
1201
                else if (!strcmp(argv[opt], "-n")) {
1145
1202
                        if (argv[++opt]) {
1146
1203
                                /* Parse option -n */
1218
1275
                usage(argv[0]);
1219
1276
        }
1220
1277
 
 
1278
        if (USE_PRETTY_OPTION(flags)) {
 
1279
                dm_major = get_devmap_major();
 
1280
        }
 
1281
        
1221
1282
        if (!count) {
1222
1283
                /*
1223
1284
                 * count parameter not set: Display all the contents of the file
1293
1354
 
1294
1355
                /* Flags to be passed to sadc */
1295
1356
                salloc(args_idx++, "-z");
1296
 
                salloc(args_idx++, "-S");
1297
 
                salloc(args_idx++, K_ALL);
1298
 
 
1299
 
                /* Outfile arg */
 
1357
                
 
1358
                /* Writing data to a file (option -o) */
1300
1359
                if (to_file[0]) {
 
1360
                        /* Collect all possible activities (option -S ALL for sadc) */
 
1361
                        salloc(args_idx++, "-S");
 
1362
                        salloc(args_idx++, K_ALL);
 
1363
                        /* Outfile arg */
1301
1364
                        salloc(args_idx++, to_file);
1302
1365
                }
 
1366
                else {
 
1367
                        /*
 
1368
                         * If option -o hasn't been used, then tell sadc
 
1369
                         * to collect only activities that will be displayed.
 
1370
                         */
 
1371
                        int act_id = 0;
 
1372
                        
 
1373
                        for (i = 0; i < NR_ACT; i++) {
 
1374
                                if (IS_SELECTED(act[i]->options)) {
 
1375
                                        act_id |= act[i]->group;
 
1376
                                }
 
1377
                        }
 
1378
                        if (act_id) {
 
1379
                                act_id <<= 8;
 
1380
                                snprintf(ltemp, 19, "%d", act_id);
 
1381
                                ltemp[19] = '\0';
 
1382
                                salloc(args_idx++, "-S");
 
1383
                                salloc(args_idx++, ltemp);
 
1384
                        }
 
1385
                }
1303
1386
 
1304
1387
                /* Last arg is NULL */
1305
1388
                args[args_idx] = NULL;