~ubuntu-branches/ubuntu/oneiric/sysstat/oneiric

« back to all changes in this revision

Viewing changes to sa_wrap.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
 * sysstat - sa_wrap.c: Functions used in activity.c
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 *
27
27
 
28
28
/*
29
29
 ***************************************************************************
30
 
 * Count number of interrupts that are in /proc/stat file.
31
 
 * Truncate the number of different individual interrupts to NR_IRQS.
32
 
 *
33
 
 * IN:
34
 
 * @a   Activity structure.
35
 
 *
36
 
 * RETURNS:
37
 
 * Number of interrupts, including total number of interrupts.
38
 
 * Value in [0, NR_IRQS + 1].
39
 
 ***************************************************************************
40
 
 */
41
 
__nr_t wrap_get_irq_nr(struct activity *a)
42
 
{
43
 
        __nr_t n;
44
 
 
45
 
        if ((n = get_irq_nr()) > (a->bitmap->b_size + 1)) {
46
 
                n = a->bitmap->b_size + 1;
47
 
        }
48
 
        
49
 
        return n;
50
 
}
51
 
 
52
 
/*
53
 
 ***************************************************************************
54
 
 * Find number of serial lines that support tx/rx accounting
55
 
 * in /proc/tty/driver/serial file.
56
 
 *
57
 
 * IN:
58
 
 * @a   Activity structure.
59
 
 *
60
 
 * RETURNS:
61
 
 * Number of serial lines supporting tx/rx accouting + a pre-allocation
62
 
 * constant.
63
 
 ***************************************************************************
64
 
 */
65
 
__nr_t wrap_get_serial_nr(struct activity *a)
66
 
{
67
 
        __nr_t n = 0;
68
 
        
69
 
        if ((n = get_serial_nr()) > 0)
70
 
                return n + NR_SERIAL_PREALLOC;
71
 
        
72
 
        return 0;
73
 
}
74
 
 
75
 
/*
76
 
 ***************************************************************************
77
 
 * Find number of interfaces (network devices) that are in /proc/net/dev
78
 
 * file.
79
 
 *
80
 
 * IN:
81
 
 * @a   Activity structure.
82
 
 *
83
 
 * RETURNS:
84
 
 * Number of network interfaces + a pre-allocation constant.
85
 
 ***************************************************************************
86
 
 */
87
 
__nr_t wrap_get_iface_nr(struct activity *a)
88
 
{
89
 
        __nr_t n = 0;
90
 
        
91
 
        if ((n = get_iface_nr()) > 0)
92
 
                return n + NR_IFACE_PREALLOC;
93
 
        
94
 
        return 0;
95
 
}
96
 
 
97
 
/*
98
 
 ***************************************************************************
99
 
 * Compute number of CPU structures to allocate.
100
 
 *
101
 
 * IN:
102
 
 * @a   Activity structure.
103
 
 *
104
 
 * RETURNS:
105
 
 * Number of structures (value in [1, NR_CPUS + 1]).
106
 
 * 1 means that there is only one proc and non SMP kernel.
107
 
 * 2 means one proc and SMP kernel.
108
 
 * Etc.
109
 
 ***************************************************************************
110
 
 */
111
 
__nr_t wrap_get_cpu_nr(struct activity *a)
112
 
{
113
 
        return (get_cpu_nr(a->bitmap->b_size) + 1);
114
 
}
115
 
 
116
 
/*
117
 
 ***************************************************************************
118
 
 * Get number of devices in /proc/{diskstats,partitions}
119
 
 * or number of disk_io entries in /proc/stat.
120
 
 * Always done, since disk stats must be read at least for sar -b
121
 
 * if not for sar -d.
122
 
 *
123
 
 * IN:
124
 
 * @a   Activity structure.
125
 
 *
126
 
 * RETURNS:
127
 
 * Number of devices + a pre-allocation constant.
128
 
 ***************************************************************************
129
 
 */
130
 
__nr_t wrap_get_disk_nr(struct activity *a)
131
 
{
132
 
        __nr_t n = 0;
133
 
        unsigned int f = COLLECT_PARTITIONS(a->opt_flags);
134
 
        
135
 
        n = get_disk_nr(&f);
136
 
 
137
 
        if (f == READ_DISKSTATS) {
138
 
                flags |= S_F_HAS_DISKSTATS;
139
 
        }
140
 
        else if (f == READ_PPARTITIONS) {
141
 
                flags |= S_F_HAS_PPARTITIONS;
142
 
        }
143
 
        
144
 
        if (n > 0)
145
 
                return n + NR_DISK_PREALLOC;
146
 
        
147
 
        return 0;
148
 
}
149
 
 
150
 
/*
151
 
 ***************************************************************************
152
30
 * Read CPU statistics.
153
31
 *
154
32
 * IN:
273
151
        struct stats_swap *st_swap
274
152
                = (struct stats_swap *) a->_buf0;
275
153
 
276
 
        /* Try to read stats from /proc/vmstat, otherwise from /proc/stat */
277
 
        if (!read_vmstat_swap(st_swap)) {
278
 
                read_stat_swap(st_swap);
279
 
        }
 
154
        /* Read stats from /proc/vmstat */
 
155
        read_vmstat_swap(st_swap);
280
156
        
281
157
        return;
282
158
}
297
173
        struct stats_paging *st_paging
298
174
                = (struct stats_paging *) a->_buf0;
299
175
 
300
 
        /* Try to read stats from /proc/vmstat, otherwise from /proc/stat */
301
 
        if (!read_vmstat_paging(st_paging)) {
302
 
                read_stat_paging(st_paging);
303
 
        }
 
176
        /* Read stats from /proc/vmstat */
 
177
        read_vmstat_paging(st_paging);
304
178
        
305
179
        return;
306
180
}
321
195
        struct stats_io *st_io
322
196
                = (struct stats_io *) a->_buf0;
323
197
 
324
 
        /* Try to read stats from /proc/diskstats, /proc/partitions or /proc/stat */
325
 
        if (HAS_DISKSTATS(flags)) {
326
 
                read_diskstats_io(st_io);
327
 
        }
328
 
        else if (HAS_PPARTITIONS(flags)) {
329
 
                read_ppartitions_io(st_io);
330
 
        }
331
 
        else {
332
 
                read_stat_io(st_io);
333
 
        }
 
198
        /* Read stats from /proc/diskstats */
 
199
        read_diskstats_io(st_io);
334
200
 
335
201
        return;
336
202
}
351
217
        struct stats_disk *st_disk
352
218
                = (struct stats_disk *) a->_buf0;
353
219
 
354
 
        /* Try to read stats from /proc/diskstats, /proc/partitions or /proc/stat */
355
 
        if (HAS_DISKSTATS(flags)) {
356
 
                read_diskstats_disk(st_disk, a->nr, COLLECT_PARTITIONS(a->opt_flags));
357
 
        }
358
 
        else if (HAS_PPARTITIONS(flags)) {
359
 
                read_partitions_disk(st_disk, a->nr);
360
 
        }
361
 
        else {
362
 
                read_stat_disk(st_disk, a->nr);
363
 
        }
 
220
        /* Read stats from /proc/diskstats */
 
221
        read_diskstats_disk(st_disk, a->nr, COLLECT_PARTITIONS(a->opt_flags));
364
222
 
365
223
        return;
366
224
}
826
684
        
827
685
        return;
828
686
}
 
687
 
 
688
/*
 
689
 ***************************************************************************
 
690
 * Read fan statistics.
 
691
 *
 
692
 * IN:
 
693
 * @a  Activity structure.
 
694
 *
 
695
 * OUT:
 
696
 * @a  Activity structure with statistics.
 
697
 ***************************************************************************
 
698
 */
 
699
__read_funct_t wrap_read_fan(struct activity *a)
 
700
{
 
701
        struct stats_pwr_fan *st_pwr_fan
 
702
                = (struct stats_pwr_fan *) a->_buf0;
 
703
 
 
704
        /* Read fan stats */
 
705
        read_fan(st_pwr_fan, a->nr);
 
706
 
 
707
        return;
 
708
}
 
709
 
 
710
/*
 
711
 ***************************************************************************
 
712
 * Read temperature statistics.
 
713
 *
 
714
 * IN:
 
715
 * @a  Activity structure.
 
716
 *
 
717
 * OUT:
 
718
 * @a  Activity structure with statistics.
 
719
 ***************************************************************************
 
720
 */
 
721
__read_funct_t wrap_read_temp(struct activity *a)
 
722
{
 
723
        struct stats_pwr_temp *st_pwr_temp
 
724
                = (struct stats_pwr_temp *) a->_buf0;
 
725
 
 
726
        /* Read temperature stats */
 
727
        read_temp(st_pwr_temp, a->nr);
 
728
 
 
729
        return;
 
730
}
 
731
 
 
732
/*
 
733
 ***************************************************************************
 
734
 * Read voltage input statistics.
 
735
 *
 
736
 * IN:
 
737
 * @a  Activity structure.
 
738
 *
 
739
 * OUT:
 
740
 * @a  Activity structure with statistics.
 
741
 ***************************************************************************
 
742
 */
 
743
__read_funct_t wrap_read_in(struct activity *a)
 
744
{
 
745
        struct stats_pwr_in *st_pwr_in
 
746
                = (struct stats_pwr_in *) a->_buf0;
 
747
 
 
748
        /* Read voltage input stats */
 
749
        read_in(st_pwr_in, a->nr);
 
750
 
 
751
        return;
 
752
}
 
753
 
 
754
/*
 
755
 ***************************************************************************
 
756
 * Read hugepages statistics.
 
757
 *
 
758
 * IN:
 
759
 * @a   Activity structure.
 
760
 *
 
761
 * OUT:
 
762
 * @a   Activity structure with statistics.
 
763
 ***************************************************************************
 
764
 */
 
765
__read_funct_t wrap_read_meminfo_huge(struct activity *a)
 
766
{
 
767
        struct stats_huge *st_huge
 
768
                = (struct stats_huge *) a->_buf0;
 
769
 
 
770
        /* Read hugepages stats */
 
771
        read_meminfo_huge(st_huge);
 
772
 
 
773
        return;
 
774
}
 
775
 
 
776
/*
 
777
 ***************************************************************************
 
778
 * Read weighted CPU frequency statistics.
 
779
 *
 
780
 * IN:
 
781
 * @a   Activity structure.
 
782
 *
 
783
 * OUT:
 
784
 * @a   Activity structure with statistics.
 
785
 ***************************************************************************
 
786
 */
 
787
__read_funct_t wrap_read_time_in_state(struct activity *a)
 
788
{
 
789
        __nr_t  cpu = 0;
 
790
        int j;
 
791
        struct stats_pwr_wghfreq *st_pwr_wghfreq
 
792
                = (struct stats_pwr_wghfreq *) a->_buf0;
 
793
        struct stats_pwr_wghfreq *st_pwr_wghfreq_i, *st_pwr_wghfreq_j, *st_pwr_wghfreq_all_j;
 
794
 
 
795
        while (cpu < (a->nr - 1)) {
 
796
                /* Read current CPU time-in-state data */
 
797
                st_pwr_wghfreq_i = st_pwr_wghfreq + (cpu + 1) * a->nr2;
 
798
                read_time_in_state(st_pwr_wghfreq_i, cpu, a->nr2);
 
799
 
 
800
                /* Also save data for CPU 'all' */
 
801
                for (j = 0; j < a->nr2; j++) {
 
802
                        st_pwr_wghfreq_j     = st_pwr_wghfreq_i + j;    /* CPU #cpu, state #j */
 
803
                        st_pwr_wghfreq_all_j = st_pwr_wghfreq   + j;    /* CPU #all, state #j */
 
804
                        if (!cpu) {
 
805
                                /* Assume that possible frequencies are the same for all CPUs */
 
806
                                st_pwr_wghfreq_all_j->freq = st_pwr_wghfreq_j->freq;
 
807
                        }
 
808
                        st_pwr_wghfreq_all_j->time_in_state += st_pwr_wghfreq_j->time_in_state;
 
809
                }
 
810
                cpu++;
 
811
        }
 
812
 
 
813
        /* Special processing for non SMP kernels: Only CPU 'all' is available */
 
814
        if (a->nr == 1) {
 
815
                read_time_in_state(st_pwr_wghfreq, 0, a->nr2);
 
816
        }
 
817
        else {
 
818
                for (j = 0; j < a->nr2; j++) {
 
819
                        st_pwr_wghfreq_all_j = st_pwr_wghfreq + j;      /* CPU #all, state #j */
 
820
                        st_pwr_wghfreq_all_j->time_in_state /= (a->nr - 1);
 
821
                }
 
822
        }
 
823
 
 
824
        return;
 
825
}
 
826
 
 
827
/*
 
828
 ***************************************************************************
 
829
 * Count number of interrupts that are in /proc/stat file.
 
830
 * Truncate the number of different individual interrupts to NR_IRQS.
 
831
 *
 
832
 * IN:
 
833
 * @a   Activity structure.
 
834
 *
 
835
 * RETURNS:
 
836
 * Number of interrupts, including total number of interrupts.
 
837
 * Value in [0, NR_IRQS + 1].
 
838
 ***************************************************************************
 
839
 */
 
840
__nr_t wrap_get_irq_nr(struct activity *a)
 
841
{
 
842
        __nr_t n;
 
843
 
 
844
        if ((n = get_irq_nr()) > (a->bitmap->b_size + 1)) {
 
845
                n = a->bitmap->b_size + 1;
 
846
        }
 
847
 
 
848
        return n;
 
849
}
 
850
 
 
851
/*
 
852
 ***************************************************************************
 
853
 * Find number of serial lines that support tx/rx accounting
 
854
 * in /proc/tty/driver/serial file.
 
855
 *
 
856
 * IN:
 
857
 * @a   Activity structure.
 
858
 *
 
859
 * RETURNS:
 
860
 * Number of serial lines supporting tx/rx accouting + a pre-allocation
 
861
 * constant.
 
862
 ***************************************************************************
 
863
 */
 
864
__nr_t wrap_get_serial_nr(struct activity *a)
 
865
{
 
866
        __nr_t n = 0;
 
867
 
 
868
        if ((n = get_serial_nr()) > 0)
 
869
                return n + NR_SERIAL_PREALLOC;
 
870
 
 
871
        return 0;
 
872
}
 
873
 
 
874
/*
 
875
 ***************************************************************************
 
876
 * Find number of interfaces (network devices) that are in /proc/net/dev
 
877
 * file.
 
878
 *
 
879
 * IN:
 
880
 * @a   Activity structure.
 
881
 *
 
882
 * RETURNS:
 
883
 * Number of network interfaces + a pre-allocation constant.
 
884
 ***************************************************************************
 
885
 */
 
886
__nr_t wrap_get_iface_nr(struct activity *a)
 
887
{
 
888
        __nr_t n = 0;
 
889
 
 
890
        if ((n = get_iface_nr()) > 0)
 
891
                return n + NR_IFACE_PREALLOC;
 
892
 
 
893
        return 0;
 
894
}
 
895
 
 
896
/*
 
897
 ***************************************************************************
 
898
 * Compute number of CPU structures to allocate.
 
899
 *
 
900
 * IN:
 
901
 * @a   Activity structure.
 
902
 *
 
903
 * RETURNS:
 
904
 * Number of structures (value in [1, NR_CPUS + 1]).
 
905
 * 1 means that there is only one proc and non SMP kernel.
 
906
 * 2 means one proc and SMP kernel.
 
907
 * Etc.
 
908
 ***************************************************************************
 
909
 */
 
910
__nr_t wrap_get_cpu_nr(struct activity *a)
 
911
{
 
912
        return (get_cpu_nr(a->bitmap->b_size) + 1);
 
913
}
 
914
 
 
915
/*
 
916
 ***************************************************************************
 
917
 * Get number of devices in /proc/diskstats.
 
918
 * Always done, since disk stats must be read at least for sar -b
 
919
 * if not for sar -d.
 
920
 *
 
921
 * IN:
 
922
 * @a   Activity structure.
 
923
 *
 
924
 * RETURNS:
 
925
 * Number of devices + a pre-allocation constant.
 
926
 ***************************************************************************
 
927
 */
 
928
__nr_t wrap_get_disk_nr(struct activity *a)
 
929
{
 
930
        __nr_t n = 0;
 
931
        unsigned int f = COLLECT_PARTITIONS(a->opt_flags);
 
932
 
 
933
        if ((n = get_disk_nr(f)) > 0)
 
934
                return n + NR_DISK_PREALLOC;
 
935
 
 
936
        return 0;
 
937
}
 
938
 
 
939
/*
 
940
 ***************************************************************************
 
941
 * Get number of fan structures to allocate.
 
942
 *
 
943
 * IN:
 
944
 * @a  Activity structure.
 
945
 *
 
946
 * RETURNS:
 
947
 * Number of structures.
 
948
 ***************************************************************************
 
949
 */
 
950
__nr_t wrap_get_fan_nr(struct activity *a)
 
951
{
 
952
        return (get_fan_nr());
 
953
}
 
954
 
 
955
/*
 
956
 ***************************************************************************
 
957
 * Get number of temp structures to allocate.
 
958
 *
 
959
 * IN:
 
960
 * @a  Activity structure.
 
961
 *
 
962
 * RETURNS:
 
963
 * Number of structures.
 
964
 ***************************************************************************
 
965
 */
 
966
__nr_t wrap_get_temp_nr(struct activity *a)
 
967
{
 
968
        return (get_temp_nr());
 
969
}
 
970
 
 
971
/*
 
972
 ***************************************************************************
 
973
 * Get number of voltage input structures to allocate.
 
974
 *
 
975
 * IN:
 
976
 * @a  Activity structure.
 
977
 *
 
978
 * RETURNS:
 
979
 * Number of structures.
 
980
 ***************************************************************************
 
981
 */
 
982
__nr_t wrap_get_in_nr(struct activity *a)
 
983
{
 
984
        return (get_in_nr());
 
985
}
 
986
 
 
987
/*
 
988
 ***************************************************************************
 
989
 * Count number of possible frequencies for CPU#0.
 
990
 *
 
991
 * IN:
 
992
 * @a   Activity structure.
 
993
 *
 
994
 * RETURNS:
 
995
 * Number of CPU frequencies + a pre-allocation constant.
 
996
 ***************************************************************************
 
997
 */
 
998
__nr_t wrap_get_freq_nr(struct activity *a)
 
999
{
 
1000
        __nr_t n = 0;
 
1001
 
 
1002
        if ((n = get_freq_nr()) > 0)
 
1003
                return n + NR_FREQ_PREALLOC;
 
1004
 
 
1005
        return 0;
 
1006
}