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