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