]> granicus.if.org Git - sysstat/blob - sa_wrap.c
%ifutil: Add NIC utilization percentage to sar network stats
[sysstat] / sa_wrap.c
1 /*
2  * sysstat - sa_wrap.c: Functions used in activity.c
3  * (C) 1999-2013 by Sebastien GODARD (sysstat <at> orange.fr)
4  *
5  ***************************************************************************
6  * This program is free software; you can redistribute it and/or modify it *
7  * under the terms of the GNU General Public License as published  by  the *
8  * Free Software Foundation; either version 2 of the License, or (at  your *
9  * option) any later version.                                              *
10  *                                                                         *
11  * This program is distributed in the hope that it  will  be  useful,  but *
12  * WITHOUT ANY WARRANTY; without the implied warranty  of  MERCHANTABILITY *
13  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License *
14  * for more details.                                                       *
15  *                                                                         *
16  * You should have received a copy of the GNU General Public License along *
17  * with this program; if not, write to the Free Software Foundation, Inc., *
18  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA                   *
19  ***************************************************************************
20  */
21
22 #include "sa.h"
23 #include "rd_stats.h"
24 #include "count.h"
25 #include "rd_sensors.h"
26
27 extern unsigned int flags;
28 extern struct record_header record_hdr;
29
30 /*
31  ***************************************************************************
32  * Read CPU statistics.
33  *
34  * IN:
35  * @a   Activity structure.
36  *
37  * OUT:
38  * @a   Activity structure with statistics.
39  ***************************************************************************
40  */
41 __read_funct_t wrap_read_stat_cpu(struct activity *a)
42 {
43         struct stats_cpu *st_cpu
44                 = (struct stats_cpu *) a->_buf0;
45         
46         /* Read CPU statistics */
47         read_stat_cpu(st_cpu, a->nr, &record_hdr.uptime, &record_hdr.uptime0);
48         
49         return;
50 }
51
52 /*
53  ***************************************************************************
54  * Read process (task) creation and context switch statistics.
55  *
56  * IN:
57  * @a   Activity structure.
58  *
59  * OUT:
60  * @a   Activity structure with statistics.
61  ***************************************************************************
62  */
63 __read_funct_t wrap_read_stat_pcsw(struct activity *a)
64 {
65         struct stats_pcsw *st_pcsw
66                 = (struct stats_pcsw *) a->_buf0;
67
68         /* Read process and context switch stats */
69         read_stat_pcsw(st_pcsw);
70         
71         return;
72 }
73
74 /*
75  ***************************************************************************
76  * Read interrupt statistics.
77  *
78  * IN:
79  * @a   Activity structure.
80  *
81  * OUT:
82  * @a   Activity structure with statistics.
83  ***************************************************************************
84  */
85 __read_funct_t wrap_read_stat_irq(struct activity *a)
86 {
87         struct stats_irq *st_irq
88                 = (struct stats_irq *) a->_buf0;
89
90         /* Read interrupts stats */
91         read_stat_irq(st_irq, a->nr);
92         
93         return;
94 }
95
96 /*
97  ***************************************************************************
98  * Read queue and load statistics.
99  *
100  * IN:
101  * @a   Activity structure.
102  *
103  * OUT:
104  * @a   Activity structure with statistics.
105  ***************************************************************************
106  */
107 __read_funct_t wrap_read_loadavg(struct activity *a)
108 {
109         struct stats_queue *st_queue
110                 = (struct stats_queue *) a->_buf0;
111
112         /* Read queue and load stats */
113         read_loadavg(st_queue);
114         
115         return;
116 }
117
118 /*
119  ***************************************************************************
120  * Read memory statistics.
121  *
122  * IN:
123  * @a   Activity structure.
124  *
125  * OUT:
126  * @a   Activity structure with statistics.
127  ***************************************************************************
128  */
129 __read_funct_t wrap_read_meminfo(struct activity *a)
130 {
131         struct stats_memory *st_memory
132                 = (struct stats_memory *) a->_buf0;
133
134         /* Read memory stats */
135         read_meminfo(st_memory);
136         
137         return;
138 }
139
140 /*
141  ***************************************************************************
142  * Read swapping statistics.
143  *
144  * IN:
145  * @a   Activity structure.
146  *
147  * OUT:
148  * @a   Activity structure with statistics.
149  ***************************************************************************
150  */
151 __read_funct_t wrap_read_swap(struct activity *a)
152 {
153         struct stats_swap *st_swap
154                 = (struct stats_swap *) a->_buf0;
155
156         /* Read stats from /proc/vmstat */
157         read_vmstat_swap(st_swap);
158         
159         return;
160 }
161
162 /*
163  ***************************************************************************
164  * Read paging statistics.
165  *
166  * IN:
167  * @a   Activity structure.
168  *
169  * OUT:
170  * @a   Activity structure with statistics.
171  ***************************************************************************
172  */
173 __read_funct_t wrap_read_paging(struct activity *a)
174 {
175         struct stats_paging *st_paging
176                 = (struct stats_paging *) a->_buf0;
177
178         /* Read stats from /proc/vmstat */
179         read_vmstat_paging(st_paging);
180         
181         return;
182 }
183
184 /*
185  ***************************************************************************
186  * Read I/O and transfer rates statistics.
187  *
188  * IN:
189  * @a   Activity structure.
190  *
191  * OUT:
192  * @a   Activity structure with statistics.
193  ***************************************************************************
194  */
195 __read_funct_t wrap_read_io(struct activity *a)
196 {
197         struct stats_io *st_io
198                 = (struct stats_io *) a->_buf0;
199
200         /* Read stats from /proc/diskstats */
201         read_diskstats_io(st_io);
202
203         return;
204 }
205
206 /*
207  ***************************************************************************
208  * Read block devices statistics.
209  *
210  * IN:
211  * @a   Activity structure.
212  *
213  * OUT:
214  * @a   Activity structure with statistics.
215  ***************************************************************************
216  */
217 __read_funct_t wrap_read_disk(struct activity *a)
218 {
219         struct stats_disk *st_disk
220                 = (struct stats_disk *) a->_buf0;
221
222         /* Read stats from /proc/diskstats */
223         read_diskstats_disk(st_disk, a->nr, COLLECT_PARTITIONS(a->opt_flags));
224
225         return;
226 }
227
228 /*
229  ***************************************************************************
230  * Read serial lines statistics.
231  *
232  * IN:
233  * @a   Activity structure.
234  *
235  * OUT:
236  * @a   Activity structure with statistics.
237  ***************************************************************************
238  */
239 __read_funct_t wrap_read_tty_driver_serial(struct activity *a)
240 {
241         struct stats_serial *st_serial
242                 = (struct stats_serial *) a->_buf0;
243
244         /* Read serial lines stats */
245         read_tty_driver_serial(st_serial, a->nr);
246         
247         return;
248 }
249
250 /*
251  ***************************************************************************
252  * Read kernel tables statistics.
253  *
254  * IN:
255  * @a   Activity structure.
256  *
257  * OUT:
258  * @a   Activity structure with statistics.
259  ***************************************************************************
260  */
261 __read_funct_t wrap_read_kernel_tables(struct activity *a)
262 {
263         struct stats_ktables *st_ktables
264                 = (struct stats_ktables *) a->_buf0;
265
266         /* Read kernel tables stats */
267         read_kernel_tables(st_ktables);
268         
269         return;
270 }
271
272 /*
273  ***************************************************************************
274  * Read network interfaces statistics.
275  *
276  * IN:
277  * @a   Activity structure.
278  *
279  * OUT:
280  * @a   Activity structure with statistics.
281  ***************************************************************************
282  */
283 __read_funct_t wrap_read_net_dev(struct activity *a)
284 {
285         struct stats_net_dev *st_net_dev
286                 = (struct stats_net_dev *) a->_buf0;
287         int dev;
288
289         /* Read network interfaces stats */
290         dev = read_net_dev(st_net_dev, a->nr);
291         if (!dev)
292                 /* No data read. Exit */
293                 return;
294         
295         /* Read duplex and speed info for each interface */
296         read_if_info(st_net_dev, dev);
297         
298         return;
299 }
300
301 /*
302  ***************************************************************************
303  * Read network interfaces errors statistics.
304  *
305  * IN:
306  * @a   Activity structure.
307  *
308  * OUT:
309  * @a   Activity structure with statistics.
310  ***************************************************************************
311  */
312 __read_funct_t wrap_read_net_edev(struct activity *a)
313 {
314         struct stats_net_edev *st_net_edev
315                 = (struct stats_net_edev *) a->_buf0;
316
317         /* Read network interfaces errors stats */
318         read_net_edev(st_net_edev, a->nr);
319         
320         return;
321 }
322
323 /*
324  ***************************************************************************
325  * Read NFS client statistics.
326  *
327  * IN:
328  * @a   Activity structure.
329  *
330  * OUT:
331  * @a   Activity structure with statistics.
332  ***************************************************************************
333  */
334 __read_funct_t wrap_read_net_nfs(struct activity *a)
335 {
336         struct stats_net_nfs *st_net_nfs
337                 = (struct stats_net_nfs *) a->_buf0;
338
339         /* Read NFS client stats */
340         read_net_nfs(st_net_nfs);
341         
342         return;
343 }
344
345 /*
346  ***************************************************************************
347  * Read NFS server statistics.
348  *
349  * IN:
350  * @a   Activity structure.
351  *
352  * OUT:
353  * @a   Activity structure with statistics.
354  ***************************************************************************
355  */
356 __read_funct_t wrap_read_net_nfsd(struct activity *a)
357 {
358         struct stats_net_nfsd *st_net_nfsd
359                 = (struct stats_net_nfsd *) a->_buf0;
360
361         /* Read NFS server stats */
362         read_net_nfsd(st_net_nfsd);
363         
364         return;
365 }
366
367 /*
368  ***************************************************************************
369  * Read network sockets statistics.
370  *
371  * IN:
372  * @a   Activity structure.
373  *
374  * OUT:
375  * @a   Activity structure with statistics.
376  ***************************************************************************
377  */
378 __read_funct_t wrap_read_net_sock(struct activity *a)
379 {
380         struct stats_net_sock *st_net_sock
381                 = (struct stats_net_sock *) a->_buf0;
382
383         /* Read network sockets stats */
384         read_net_sock(st_net_sock);
385         
386         return;
387 }
388
389 /*
390  ***************************************************************************
391  * Read IP statistics.
392  *
393  * IN:
394  * @a   Activity structure.
395  *
396  * OUT:
397  * @a   Activity structure with statistics.
398  ***************************************************************************
399  */
400 __read_funct_t wrap_read_net_ip(struct activity *a)
401 {
402         struct stats_net_ip *st_net_ip
403                 = (struct stats_net_ip *) a->_buf0;
404
405         /* Read IP stats */
406         read_net_ip(st_net_ip);
407         
408         return;
409 }
410
411 /*
412  ***************************************************************************
413  * Read IP error statistics.
414  *
415  * IN:
416  * @a   Activity structure.
417  *
418  * OUT:
419  * @a   Activity structure with statistics.
420  ***************************************************************************
421  */
422 __read_funct_t wrap_read_net_eip(struct activity *a)
423 {
424         struct stats_net_eip *st_net_eip
425                 = (struct stats_net_eip *) a->_buf0;
426
427         /* Read IP error stats */
428         read_net_eip(st_net_eip);
429         
430         return;
431 }
432
433 /*
434  ***************************************************************************
435  * Read ICMP statistics.
436  *
437  * IN:
438  * @a   Activity structure.
439  *
440  * OUT:
441  * @a   Activity structure with statistics.
442  ***************************************************************************
443  */
444 __read_funct_t wrap_read_net_icmp(struct activity *a)
445 {
446         struct stats_net_icmp *st_net_icmp
447                 = (struct stats_net_icmp *) a->_buf0;
448
449         /* Read ICMP stats */
450         read_net_icmp(st_net_icmp);
451         
452         return;
453 }
454
455 /*
456  ***************************************************************************
457  * Read ICMP error statistics.
458  *
459  * IN:
460  * @a   Activity structure.
461  *
462  * OUT:
463  * @a   Activity structure with statistics.
464  ***************************************************************************
465  */
466 __read_funct_t wrap_read_net_eicmp(struct activity *a)
467 {
468         struct stats_net_eicmp *st_net_eicmp
469                 = (struct stats_net_eicmp *) a->_buf0;
470
471         /* Read ICMP error stats */
472         read_net_eicmp(st_net_eicmp);
473         
474         return;
475 }
476
477 /*
478  ***************************************************************************
479  * Read TCP statistics.
480  *
481  * IN:
482  * @a   Activity structure.
483  *
484  * OUT:
485  * @a   Activity structure with statistics.
486  ***************************************************************************
487  */
488 __read_funct_t wrap_read_net_tcp(struct activity *a)
489 {
490         struct stats_net_tcp *st_net_tcp
491                 = (struct stats_net_tcp *) a->_buf0;
492
493         /* Read TCP stats */
494         read_net_tcp(st_net_tcp);
495         
496         return;
497 }
498
499 /*
500  ***************************************************************************
501  * Read TCP error statistics.
502  *
503  * IN:
504  * @a   Activity structure.
505  *
506  * OUT:
507  * @a   Activity structure with statistics.
508  ***************************************************************************
509  */
510 __read_funct_t wrap_read_net_etcp(struct activity *a)
511 {
512         struct stats_net_etcp *st_net_etcp
513                 = (struct stats_net_etcp *) a->_buf0;
514
515         /* Read TCP error stats */
516         read_net_etcp(st_net_etcp);
517         
518         return;
519 }
520
521 /*
522  ***************************************************************************
523  * Read UDP statistics.
524  *
525  * IN:
526  * @a   Activity structure.
527  *
528  * OUT:
529  * @a   Activity structure with statistics.
530  ***************************************************************************
531  */
532 __read_funct_t wrap_read_net_udp(struct activity *a)
533 {
534         struct stats_net_udp *st_net_udp
535                 = (struct stats_net_udp *) a->_buf0;
536
537         /* Read UDP stats */
538         read_net_udp(st_net_udp);
539         
540         return;
541 }
542
543 /*
544  ***************************************************************************
545  * Read IPv6 network sockets statistics.
546  *
547  * IN:
548  * @a   Activity structure.
549  *
550  * OUT:
551  * @a   Activity structure with statistics.
552  ***************************************************************************
553  */
554 __read_funct_t wrap_read_net_sock6(struct activity *a)
555 {
556         struct stats_net_sock6 *st_net_sock6
557                 = (struct stats_net_sock6 *) a->_buf0;
558
559         /* Read IPv6 network sockets stats */
560         read_net_sock6(st_net_sock6);
561         
562         return;
563 }
564
565 /*
566  ***************************************************************************
567  * Read IPv6 statistics.
568  *
569  * IN:
570  * @a   Activity structure.
571  *
572  * OUT:
573  * @a   Activity structure with statistics.
574  ***************************************************************************
575  */
576 __read_funct_t wrap_read_net_ip6(struct activity *a)
577 {
578         struct stats_net_ip6 *st_net_ip6
579                 = (struct stats_net_ip6 *) a->_buf0;
580
581         /* Read IPv6 stats */
582         read_net_ip6(st_net_ip6);
583         
584         return;
585 }
586
587 /*
588  ***************************************************************************
589  * Read IPv6 error statistics.
590  *
591  * IN:
592  * @a   Activity structure.
593  *
594  * OUT:
595  * @a   Activity structure with statistics.
596  ***************************************************************************
597  */
598 __read_funct_t wrap_read_net_eip6(struct activity *a)
599 {
600         struct stats_net_eip6 *st_net_eip6
601                 = (struct stats_net_eip6 *) a->_buf0;
602
603         /* Read IPv6 error stats */
604         read_net_eip6(st_net_eip6);
605         
606         return;
607 }
608
609 /*
610  ***************************************************************************
611  * Read ICMPv6 statistics.
612  *
613  * IN:
614  * @a   Activity structure.
615  *
616  * OUT:
617  * @a   Activity structure with statistics.
618  ***************************************************************************
619  */
620 __read_funct_t wrap_read_net_icmp6(struct activity *a)
621 {
622         struct stats_net_icmp6 *st_net_icmp6
623                 = (struct stats_net_icmp6 *) a->_buf0;
624
625         /* Read ICMPv6 stats */
626         read_net_icmp6(st_net_icmp6);
627         
628         return;
629 }
630
631 /*
632  ***************************************************************************
633  * Read ICMPv6 error statistics.
634  *
635  * IN:
636  * @a   Activity structure.
637  *
638  * OUT:
639  * @a   Activity structure with statistics.
640  ***************************************************************************
641  */
642 __read_funct_t wrap_read_net_eicmp6(struct activity *a)
643 {
644         struct stats_net_eicmp6 *st_net_eicmp6
645                 = (struct stats_net_eicmp6 *) a->_buf0;
646
647         /* Read ICMPv6 error stats */
648         read_net_eicmp6(st_net_eicmp6);
649         
650         return;
651 }
652
653 /*
654  ***************************************************************************
655  * Read UDPv6 statistics.
656  *
657  * IN:
658  * @a   Activity structure.
659  *
660  * OUT:
661  * @a   Activity structure with statistics.
662  ***************************************************************************
663  */
664 __read_funct_t wrap_read_net_udp6(struct activity *a)
665 {
666         struct stats_net_udp6 *st_net_udp6
667                 = (struct stats_net_udp6 *) a->_buf0;
668
669         /* Read UDPv6 stats */
670         read_net_udp6(st_net_udp6);
671         
672         return;
673 }
674
675 /*
676  ***************************************************************************
677  * Read CPU frequency statistics.
678  *
679  * IN:
680  * @a   Activity structure.
681  *
682  * OUT:
683  * @a   Activity structure with statistics.
684  ***************************************************************************
685  */
686 __read_funct_t wrap_read_cpuinfo(struct activity *a)
687 {
688         struct stats_pwr_cpufreq *st_pwr_cpufreq
689                 = (struct stats_pwr_cpufreq *) a->_buf0;
690
691         /* Read CPU frequency stats */
692         read_cpuinfo(st_pwr_cpufreq, a->nr);
693         
694         return;
695 }
696
697 /*
698  ***************************************************************************
699  * Read fan statistics.
700  *
701  * IN:
702  * @a  Activity structure.
703  *
704  * OUT:
705  * @a  Activity structure with statistics.
706  ***************************************************************************
707  */
708 __read_funct_t wrap_read_fan(struct activity *a)
709 {
710         struct stats_pwr_fan *st_pwr_fan
711                 = (struct stats_pwr_fan *) a->_buf0;
712
713         /* Read fan stats */
714         read_fan(st_pwr_fan, a->nr);
715
716         return;
717 }
718
719 /*
720  ***************************************************************************
721  * Read temperature statistics.
722  *
723  * IN:
724  * @a  Activity structure.
725  *
726  * OUT:
727  * @a  Activity structure with statistics.
728  ***************************************************************************
729  */
730 __read_funct_t wrap_read_temp(struct activity *a)
731 {
732         struct stats_pwr_temp *st_pwr_temp
733                 = (struct stats_pwr_temp *) a->_buf0;
734
735         /* Read temperature stats */
736         read_temp(st_pwr_temp, a->nr);
737
738         return;
739 }
740
741 /*
742  ***************************************************************************
743  * Read voltage input statistics.
744  *
745  * IN:
746  * @a  Activity structure.
747  *
748  * OUT:
749  * @a  Activity structure with statistics.
750  ***************************************************************************
751  */
752 __read_funct_t wrap_read_in(struct activity *a)
753 {
754         struct stats_pwr_in *st_pwr_in
755                 = (struct stats_pwr_in *) a->_buf0;
756
757         /* Read voltage input stats */
758         read_in(st_pwr_in, a->nr);
759
760         return;
761 }
762
763 /*
764  ***************************************************************************
765  * Read hugepages statistics.
766  *
767  * IN:
768  * @a   Activity structure.
769  *
770  * OUT:
771  * @a   Activity structure with statistics.
772  ***************************************************************************
773  */
774 __read_funct_t wrap_read_meminfo_huge(struct activity *a)
775 {
776         struct stats_huge *st_huge
777                 = (struct stats_huge *) a->_buf0;
778
779         /* Read hugepages stats */
780         read_meminfo_huge(st_huge);
781
782         return;
783 }
784
785 /*
786  ***************************************************************************
787  * Read weighted CPU frequency statistics.
788  *
789  * IN:
790  * @a   Activity structure.
791  *
792  * OUT:
793  * @a   Activity structure with statistics.
794  ***************************************************************************
795  */
796 __read_funct_t wrap_read_time_in_state(struct activity *a)
797 {
798         __nr_t  cpu = 0;
799         int j;
800         struct stats_pwr_wghfreq *st_pwr_wghfreq
801                 = (struct stats_pwr_wghfreq *) a->_buf0;
802         struct stats_pwr_wghfreq *st_pwr_wghfreq_i, *st_pwr_wghfreq_j, *st_pwr_wghfreq_all_j;
803
804         while (cpu < (a->nr - 1)) {
805                 /* Read current CPU time-in-state data */
806                 st_pwr_wghfreq_i = st_pwr_wghfreq + (cpu + 1) * a->nr2;
807                 read_time_in_state(st_pwr_wghfreq_i, cpu, a->nr2);
808
809                 /* Also save data for CPU 'all' */
810                 for (j = 0; j < a->nr2; j++) {
811                         st_pwr_wghfreq_j     = st_pwr_wghfreq_i + j;    /* CPU #cpu, state #j */
812                         st_pwr_wghfreq_all_j = st_pwr_wghfreq   + j;    /* CPU #all, state #j */
813                         if (!cpu) {
814                                 /* Assume that possible frequencies are the same for all CPUs */
815                                 st_pwr_wghfreq_all_j->freq = st_pwr_wghfreq_j->freq;
816                         }
817                         st_pwr_wghfreq_all_j->time_in_state += st_pwr_wghfreq_j->time_in_state;
818                 }
819                 cpu++;
820         }
821
822         /* Special processing for non SMP kernels: Only CPU 'all' is available */
823         if (a->nr == 1) {
824                 read_time_in_state(st_pwr_wghfreq, 0, a->nr2);
825         }
826         else {
827                 for (j = 0; j < a->nr2; j++) {
828                         st_pwr_wghfreq_all_j = st_pwr_wghfreq + j;      /* CPU #all, state #j */
829                         st_pwr_wghfreq_all_j->time_in_state /= (a->nr - 1);
830                 }
831         }
832
833         return;
834 }
835
836 /*
837  ***************************************************************************
838  * Read USB devices statistics.
839  *
840  * IN:
841  * @a  Activity structure.
842  *
843  * OUT:
844  * @a  Activity structure with statistics.
845  ***************************************************************************
846  */
847 __read_funct_t wrap_read_bus_usb_dev(struct activity *a)
848 {
849         struct stats_pwr_usb *st_pwr_usb
850                 = (struct stats_pwr_usb *) a->_buf0;
851
852         /* Read USB devices stats */
853         read_bus_usb_dev(st_pwr_usb, a->nr);
854
855         return;
856 }
857
858 /*
859  ***************************************************************************
860  * Read filesystem statistics.
861  *
862  * IN:
863  * @a   Activity structure.
864  *
865  * OUT:
866  * @a   Activity structure with statistics.
867  ***************************************************************************
868  */
869 __read_funct_t wrap_read_filesystem(struct activity *a)
870 {
871         struct stats_filesystem *st_filesystem
872                 = (struct stats_filesystem *) a->_buf0;
873
874         /* Read filesystems from /etc/mtab */
875         read_filesystem(st_filesystem, a->nr);
876
877         return;
878 }
879
880 /*
881  ***************************************************************************
882  * Count number of interrupts that are in /proc/stat file.
883  * Truncate the number of different individual interrupts to NR_IRQS.
884  *
885  * IN:
886  * @a   Activity structure.
887  *
888  * RETURNS:
889  * Number of interrupts, including total number of interrupts.
890  * Value in [0, NR_IRQS + 1].
891  ***************************************************************************
892  */
893 __nr_t wrap_get_irq_nr(struct activity *a)
894 {
895         __nr_t n;
896
897         if ((n = get_irq_nr()) > (a->bitmap->b_size + 1)) {
898                 n = a->bitmap->b_size + 1;
899         }
900
901         return n;
902 }
903
904 /*
905  ***************************************************************************
906  * Find number of serial lines that support tx/rx accounting
907  * in /proc/tty/driver/serial file.
908  *
909  * IN:
910  * @a   Activity structure.
911  *
912  * RETURNS:
913  * Number of serial lines supporting tx/rx accouting + a pre-allocation
914  * constant.
915  ***************************************************************************
916  */
917 __nr_t wrap_get_serial_nr(struct activity *a)
918 {
919         __nr_t n = 0;
920
921         if ((n = get_serial_nr()) > 0)
922                 return n + NR_SERIAL_PREALLOC;
923
924         return 0;
925 }
926
927 /*
928  ***************************************************************************
929  * Find number of interfaces (network devices) that are in /proc/net/dev
930  * file.
931  *
932  * IN:
933  * @a   Activity structure.
934  *
935  * RETURNS:
936  * Number of network interfaces + a pre-allocation constant.
937  ***************************************************************************
938  */
939 __nr_t wrap_get_iface_nr(struct activity *a)
940 {
941         __nr_t n = 0;
942
943         if ((n = get_iface_nr()) > 0)
944                 return n + NR_IFACE_PREALLOC;
945
946         return 0;
947 }
948
949 /*
950  ***************************************************************************
951  * Compute number of CPU structures to allocate.
952  *
953  * IN:
954  * @a   Activity structure.
955  *
956  * RETURNS:
957  * Number of structures (value in [1, NR_CPUS + 1]).
958  * 1 means that there is only one proc and non SMP kernel.
959  * 2 means one proc and SMP kernel.
960  * Etc.
961  ***************************************************************************
962  */
963 __nr_t wrap_get_cpu_nr(struct activity *a)
964 {
965         return (get_cpu_nr(a->bitmap->b_size) + 1);
966 }
967
968 /*
969  ***************************************************************************
970  * Get number of devices in /proc/diskstats.
971  * Always done, since disk stats must be read at least for sar -b
972  * if not for sar -d.
973  *
974  * IN:
975  * @a   Activity structure.
976  *
977  * RETURNS:
978  * Number of devices + a pre-allocation constant.
979  ***************************************************************************
980  */
981 __nr_t wrap_get_disk_nr(struct activity *a)
982 {
983         __nr_t n = 0;
984         unsigned int f = COLLECT_PARTITIONS(a->opt_flags);
985
986         if ((n = get_disk_nr(f)) > 0)
987                 return n + NR_DISK_PREALLOC;
988
989         return 0;
990 }
991
992 /*
993  ***************************************************************************
994  * Get number of fan structures to allocate.
995  *
996  * IN:
997  * @a  Activity structure.
998  *
999  * RETURNS:
1000  * Number of structures.
1001  ***************************************************************************
1002  */
1003 __nr_t wrap_get_fan_nr(struct activity *a)
1004 {
1005         return (get_fan_nr());
1006 }
1007
1008 /*
1009  ***************************************************************************
1010  * Get number of temp structures to allocate.
1011  *
1012  * IN:
1013  * @a  Activity structure.
1014  *
1015  * RETURNS:
1016  * Number of structures.
1017  ***************************************************************************
1018  */
1019 __nr_t wrap_get_temp_nr(struct activity *a)
1020 {
1021         return (get_temp_nr());
1022 }
1023
1024 /*
1025  ***************************************************************************
1026  * Get number of voltage input structures to allocate.
1027  *
1028  * IN:
1029  * @a  Activity structure.
1030  *
1031  * RETURNS:
1032  * Number of structures.
1033  ***************************************************************************
1034  */
1035 __nr_t wrap_get_in_nr(struct activity *a)
1036 {
1037         return (get_in_nr());
1038 }
1039
1040 /*
1041  ***************************************************************************
1042  * Count number of possible frequencies for CPU#0.
1043  *
1044  * IN:
1045  * @a   Activity structure.
1046  *
1047  * RETURNS:
1048  * Number of CPU frequencies + a pre-allocation constant.
1049  ***************************************************************************
1050  */
1051 __nr_t wrap_get_freq_nr(struct activity *a)
1052 {
1053         __nr_t n = 0;
1054
1055         if ((n = get_freq_nr()) > 0)
1056                 return n + NR_FREQ_PREALLOC;
1057
1058         return 0;
1059 }
1060
1061 /*
1062  ***************************************************************************
1063  * Count number of USB devices plugged into the system.
1064  *
1065  * IN:
1066  * @a   Activity structure.
1067  *
1068  * RETURNS:
1069  * Number of USB devices + a pre-allocation constant.
1070  ***************************************************************************
1071  */
1072 __nr_t wrap_get_usb_nr(struct activity *a)
1073 {
1074         __nr_t n = 0;
1075
1076         if ((n = get_usb_nr()) >= 0)
1077                 /* Return a positive number even if no USB devices have been found */
1078                 return n + NR_USB_PREALLOC;
1079         
1080         return 0;
1081 }
1082
1083 /*
1084  ***************************************************************************
1085  * Get number of mounted filesystems from /etc/mtab. Don't take into account
1086  * pseudo-filesystems.
1087  *
1088  * IN:
1089  * @a   Activity structure.
1090  *
1091  * RETURNS:
1092  * Number of filesystems + a pre-allocation constant.
1093  ***************************************************************************
1094  */
1095 __nr_t wrap_get_filesystem_nr(struct activity *a)
1096 {
1097         __nr_t n = 0;
1098
1099         if ((n = get_filesystem_nr()) > 0)
1100                 return n + NR_FILESYSTEM_PREALLOC;
1101
1102         return 0;
1103 }