~ubuntu-branches/ubuntu/karmic/sysstat/karmic

« back to all changes in this revision

Viewing changes to sadf.c

  • Committer: Bazaar Package Importer
  • Author(s): Robert Luberda
  • Date: 2009-06-07 21:37:20 UTC
  • mfrom: (1.1.15 upstream) (2.1.4 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090607213720-4sixxpv1y32q27qn
Tags: 9.0.3-2
Remove some debugging cruft left by accident.

Show diffs side-by-side

added added

removed removed

Lines of Context:
73
73
 
74
74
/*
75
75
 ***************************************************************************
76
 
 * Print usage and exit
 
76
 * Print usage and exit.
77
77
 *
78
78
 * IN:
79
79
 * @progname    Name of sysstat command.
94
94
 
95
95
/*
96
96
 ***************************************************************************
97
 
 * Init structures
 
97
 * Init structures.
98
98
 ***************************************************************************
99
99
 */
100
100
void init_structures(void)
108
108
 
109
109
/*
110
110
 ***************************************************************************
111
 
 * Fill rectime structure according to time data saved in file.
 
111
 * Fill the rectime structure with current record's date and time, based on
 
112
 * current record's "number of seconds since the epoch" saved in file.
 
113
 * The resulting timestamp is expressed in UTC or in local time, depending
 
114
 * on whether option -t has been used or not.
112
115
 * NB: Option -t is ignored when option -p is used, since option -p
113
116
 * displays its timestamp as a long integer. This is type 'time_t',
114
117
 * which is the number of seconds since 1970 _always_ expressed in UTC.
117
120
 * @curr        Index in array for current sample statistics.
118
121
 ***************************************************************************
119
122
*/
120
 
void sadf_set_rectime(int curr)
 
123
void sadf_get_record_timestamp_struct(int curr)
121
124
{
122
125
        struct tm *ltm;
123
126
 
135
138
 
136
139
/*
137
140
 ***************************************************************************
138
 
 * Set timestamp string
 
141
 * Set current record's timestamp string. This timestamp is expressed in
 
142
 * UTC or in local time, depending on whether option -t has been used or
 
143
 * not.
 
144
 * NB: If options -D or -p have been used, the timestamp in expressed in
 
145
 * seconds since 1970.
139
146
 *
140
147
 * IN:
141
148
 * @curr        Index in array for current sample statistics.
145
152
 * @cur_time    Timestamp string.
146
153
 ***************************************************************************
147
154
*/
148
 
void set_timestamp(int curr, char *cur_time, int len)
 
155
void set_record_timestamp_string(int curr, char *cur_time, int len)
149
156
{
150
 
        sadf_set_rectime(curr);
 
157
        /* Fill timestamp structure */
 
158
        sadf_get_record_timestamp_struct(curr);
151
159
 
152
160
        /* Set cur_time date value */
153
161
        if (format == S_O_DB_OPTION) {
265
273
 
266
274
/*
267
275
 ***************************************************************************
268
 
 * Write system statistics
 
276
 * Write system statistics.
269
277
 *
270
278
 * IN:
271
279
 * @curr                Index in array for current sample statistics.
295
303
                cpu_nr = *act[get_activity_position(act, A_CPU)]->nr;
296
304
        }
297
305
 
298
 
        /* Check time (1) */
 
306
        /*
 
307
         * Check time (1).
 
308
         * For this first check, we use the time interval entered on
 
309
         * the command line. This is equivalent to sar's option -i which
 
310
         * selects records at seconds as close as possible to the number
 
311
         * specified by the interval parameter.
 
312
         */
299
313
        if (!next_slice(record_hdr[2].uptime0, record_hdr[curr].uptime0,
300
314
                        reset, interval))
301
315
                /* Not close enough to desired interval */
302
316
                return 0;
303
317
 
304
318
        /* Set current timestamp */
305
 
        set_timestamp(curr, cur_time, 26);
 
319
        set_record_timestamp_string(curr, cur_time, 26);
306
320
 
307
321
        /* Check if we are beginning a new day */
308
322
        if (use_tm_start && record_hdr[!curr].ust_time &&
363
377
        unsigned long long dt, itv, g_itv;
364
378
        char cur_time[XML_TIMESTAMP_LEN];
365
379
 
366
 
        /* Set timestamp for current data */
367
 
        sadf_set_rectime(curr);
 
380
        /* Fill timestamp structure (rectime) for current record */
 
381
        sadf_get_record_timestamp_struct(curr);
368
382
 
369
383
        /* Get interval values */
370
384
        get_itv_value(&record_hdr[curr], &record_hdr[!curr],
414
428
{
415
429
        char cur_time[64];
416
430
 
417
 
        /* Set timestamp for current data */
418
 
        sadf_set_rectime(curr);
 
431
        /* Fill timestamp structure for current record */
 
432
        sadf_get_record_timestamp_struct(curr);
419
433
 
420
434
        strftime(cur_time, 64, "date=\"%Y-%m-%d\" time=\"%H:%M:%S\"", &rectime);
421
435
        xprintf(tab, "<boot %s/>", cur_time);
439
453
        sa_fread(ifd, file_comment, MAX_COMMENT_LEN, HARD_SIZE);
440
454
        file_comment[MAX_COMMENT_LEN - 1] = '\0';
441
455
 
442
 
        /* Set timestamp for current data */
443
 
        sadf_set_rectime(curr);
 
456
        /* Fill timestamp structure for current record */
 
457
        sadf_get_record_timestamp_struct(curr);
444
458
 
445
459
        strftime(cur_time, 64, "date=\"%Y-%m-%d\" time=\"%H:%M:%S\"", &rectime);
446
460
        xprintf(tab, "<comment %s com=\"%s\"/>", cur_time, file_comment);
463
477
        char cur_time[26];
464
478
        int dp = 1;
465
479
 
466
 
        set_timestamp(curr, cur_time, 26);
 
480
        set_record_timestamp_string(curr, cur_time, 26);
467
481
 
468
482
        /* The record must be in the interval specified by -s/-e options */
469
483
        if ((use_tm_start && (datecmp(&loctime, &tm_start) < 0)) ||
568
582
 */
569
583
void display_xml_header(int *tab, __nr_t cpu_nr)
570
584
{
 
585
        char cur_time[XML_TIMESTAMP_LEN];
 
586
        
571
587
        printf("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
572
588
        printf("<!DOCTYPE Configure PUBLIC \"DTD v%s sysstat //EN\"\n", XML_DTD_VERSION);
573
589
        printf("\"http://pagesperso-orange.fr/sebastien.godard/sysstat.dtd\">\n");
578
594
        xprintf(*tab, "<host nodename=\"%s\">", file_hdr.sa_nodename);
579
595
        xprintf(++(*tab), "<sysname>%s</sysname>", file_hdr.sa_sysname);
580
596
        xprintf(*tab, "<release>%s</release>", file_hdr.sa_release);
 
597
                
581
598
        xprintf(*tab, "<machine>%s</machine>", file_hdr.sa_machine);
582
599
        xprintf(*tab, "<number-of-cpus>%d</number-of-cpus>", cpu_nr > 1 ? cpu_nr - 1 : 1);
 
600
 
 
601
        /* Fill file timestmap structure (rectime) */
 
602
        get_file_timestamp_struct(flags, &rectime, &file_hdr);
 
603
        strftime(cur_time, XML_TIMESTAMP_LEN, "%Y-%m-%d", &rectime);
 
604
        xprintf(*tab, "<file-date>%s</file-date>", cur_time);
583
605
}
584
606
 
585
607
/*
601
623
 *              reinitialized (used in next_slice() function).
602
624
 ***************************************************************************
603
625
 */
604
 
void read_curr_act_stats(int ifd, off_t fpos, int *curr, long *cnt, int *eosaf,
605
 
                         unsigned int act_id, int *reset, struct file_activity *file_actlst)
 
626
void rw_curr_act_stats(int ifd, off_t fpos, int *curr, long *cnt, int *eosaf,
 
627
                       unsigned int act_id, int *reset, struct file_activity *file_actlst)
606
628
{
607
629
        unsigned char rtype;
608
630
        int next;
670
692
 
671
693
/*
672
694
 ***************************************************************************
673
 
 * Display activities for -x option
 
695
 * Display activities for -x option.
674
696
 *
675
697
 * IN:
676
698
 * @ifd         File descriptor of input file.
701
723
        xprintf(tab++, "<statistics>");
702
724
        do {
703
725
                /*
704
 
                 * If this record is a special (RESTART or COMMENT)  one,
705
 
                 * try to get another one.
 
726
                 * If this record is a special (RESTART or COMMENT) one,
 
727
                 * skip it and try to read the next record in file.
706
728
                 */
707
729
                do {
708
730
                        eosaf = sa_fread(ifd, &record_hdr[0], RECORD_HEADER_SIZE, SOFT_SIZE);
710
732
 
711
733
                        if (!eosaf && (rtype != R_RESTART) && (rtype != R_COMMENT)) {
712
734
                                /*
713
 
                                 * Ok: previous record was not a special one.
 
735
                                 * OK: Previous record was not a special one.
714
736
                                 * So read now the extra fields.
715
737
                                 */
716
738
                                read_file_stat_bunch(act, 0, ifd, file_hdr.sa_nr_act,
718
740
                        }
719
741
 
720
742
                        if (!eosaf && (rtype == R_COMMENT)) {
721
 
                                /* Ignore COMMENT record */
 
743
                                /*
 
744
                                 * Ignore COMMENT record.
 
745
                                 * (Unlike RESTART records, COMMENT records have an additional
 
746
                                 * comment field).
 
747
                                 */
722
748
                                if (lseek(ifd, MAX_COMMENT_LEN, SEEK_CUR) < MAX_COMMENT_LEN) {
723
749
                                        perror("lseek");
724
750
                                }
818
844
 
819
845
/*
820
846
 ***************************************************************************
821
 
 * Display activities for -p and -d options
 
847
 * Display activities for -p and -d options.
822
848
 *
823
849
 * IN:
824
850
 * @ifd         File descriptor of input file.
850
876
                        }
851
877
                        else {
852
878
                                /*
853
 
                                 * Ok: previous record was not a RESTART one.
 
879
                                 * OK: Previous record was not a special one.
854
880
                                 * So read now the extra fields.
855
881
                                 */
856
882
                                read_file_stat_bunch(act, 0, ifd, file_hdr.sa_nr_act,
857
883
                                                     file_actlst);
858
 
                                sadf_set_rectime(0);
 
884
                                sadf_get_record_timestamp_struct(0);
859
885
                        }
860
886
                }
861
887
                while ((rtype == R_RESTART) || (rtype == R_COMMENT) ||
880
906
                         * If stats are displayed horizontally, then all activities
881
907
                         * are printed on the same line.
882
908
                         */
883
 
                        read_curr_act_stats(ifd, fpos, &curr, &cnt, &eosaf,
884
 
                                            ALL_ACTIVITIES, &reset, file_actlst);
 
909
                        rw_curr_act_stats(ifd, fpos, &curr, &cnt, &eosaf,
 
910
                                          ALL_ACTIVITIES, &reset, file_actlst);
885
911
                }
886
912
                else {
887
913
                        /* For each requested activity... */
898
924
                                        continue;
899
925
 
900
926
                                if (!HAS_MULTIPLE_OUTPUTS(act[p]->options)) {
901
 
                                        read_curr_act_stats(ifd, fpos, &curr, &cnt, &eosaf,
902
 
                                                            act[p]->id, &reset, file_actlst);
 
927
                                        rw_curr_act_stats(ifd, fpos, &curr, &cnt, &eosaf,
 
928
                                                          act[p]->id, &reset, file_actlst);
903
929
                                }
904
930
                                else {
905
931
                                        unsigned int optf, msk;
910
936
                                                if (act[p]->opt_flags & msk) {
911
937
                                                        act[p]->opt_flags &= msk;
912
938
                                                        
913
 
                                                        read_curr_act_stats(ifd, fpos, &curr, &cnt,
914
 
                                                                            &eosaf, act[p]->id, &reset,
915
 
                                                                            file_actlst);
 
939
                                                        rw_curr_act_stats(ifd, fpos, &curr, &cnt, &eosaf,
 
940
                                                                          act[p]->id, &reset, file_actlst);
916
941
                                                        act[p]->opt_flags = optf;
917
942
                                                }
918
943
                                        }
944
969
 
945
970
/*
946
971
 ***************************************************************************
947
 
 * Read statistics from a system activity data file
 
972
 * Read statistics from a system activity data file.
948
973
 *
949
974
 * IN:
950
975
 * @dfile       System activity data file name.
969
994
        /* Perform required allocations */
970
995
        allocate_structures(act);
971
996
 
972
 
        set_hdr_rectime(flags, &rectime, &file_hdr);
973
 
 
974
997
        if (format == S_O_XML_OPTION) {
975
998
                xml_display_loop(ifd, file_actlst);
976
999
        }