xref: /illumos-gate/usr/src/cmd/sgs/liblddbg/common/statistics.c (revision 7c478bd95313f5f23a4c958a745db2134aa0324)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  *	Copyright 2003 Sun Microsystems, Inc.  All rights reserved.
24*7c478bd9Sstevel@tonic-gate  *	Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
27*7c478bd9Sstevel@tonic-gate 
28*7c478bd9Sstevel@tonic-gate #include	"_debug.h"
29*7c478bd9Sstevel@tonic-gate #include	"msg.h"
30*7c478bd9Sstevel@tonic-gate #include	"libld.h"
31*7c478bd9Sstevel@tonic-gate 
32*7c478bd9Sstevel@tonic-gate void
33*7c478bd9Sstevel@tonic-gate Dbg_statistics_ld(Ofl_desc *ofl)
34*7c478bd9Sstevel@tonic-gate {
35*7c478bd9Sstevel@tonic-gate 	if (DBG_NOTCLASS(DBG_STATISTICS))
36*7c478bd9Sstevel@tonic-gate 		return;
37*7c478bd9Sstevel@tonic-gate 
38*7c478bd9Sstevel@tonic-gate 	dbg_print(MSG_ORIG(MSG_STR_EMPTY));
39*7c478bd9Sstevel@tonic-gate 	dbg_print(MSG_INTL(MSG_STATS_GENERAL));
40*7c478bd9Sstevel@tonic-gate 
41*7c478bd9Sstevel@tonic-gate 	if (ofl->ofl_objscnt || ofl->ofl_soscnt || ofl->ofl_arscnt) {
42*7c478bd9Sstevel@tonic-gate 		dbg_print(MSG_INTL(MSG_STATS_FILES),
43*7c478bd9Sstevel@tonic-gate 		    EC_XWORD(ofl->ofl_objscnt), EC_XWORD(ofl->ofl_soscnt),
44*7c478bd9Sstevel@tonic-gate 		    EC_XWORD(ofl->ofl_arscnt));
45*7c478bd9Sstevel@tonic-gate 	}
46*7c478bd9Sstevel@tonic-gate 
47*7c478bd9Sstevel@tonic-gate 	if (ofl->ofl_locscnt || ofl->ofl_globcnt || ofl->ofl_entercnt) {
48*7c478bd9Sstevel@tonic-gate 		dbg_print(MSG_INTL(MSG_STATS_SYMBOLS),
49*7c478bd9Sstevel@tonic-gate 		    EC_XWORD(ofl->ofl_locscnt), EC_XWORD(ofl->ofl_globcnt),
50*7c478bd9Sstevel@tonic-gate 		    EC_XWORD(ofl->ofl_entercnt));
51*7c478bd9Sstevel@tonic-gate 	}
52*7c478bd9Sstevel@tonic-gate 
53*7c478bd9Sstevel@tonic-gate 	if (ofl->ofl_outrelscnt || ofl->ofl_actrelscnt) {
54*7c478bd9Sstevel@tonic-gate 		dbg_print(MSG_INTL(MSG_STATS_RELOCS),
55*7c478bd9Sstevel@tonic-gate 		    EC_XWORD(ofl->ofl_outrelscnt),
56*7c478bd9Sstevel@tonic-gate 		    EC_XWORD(ofl->ofl_actrelscnt));
57*7c478bd9Sstevel@tonic-gate 	}
58*7c478bd9Sstevel@tonic-gate }
59*7c478bd9Sstevel@tonic-gate 
60*7c478bd9Sstevel@tonic-gate void
61*7c478bd9Sstevel@tonic-gate Dbg_statistics_ar(Ofl_desc *ofl)
62*7c478bd9Sstevel@tonic-gate {
63*7c478bd9Sstevel@tonic-gate 	Listnode	*lnp;
64*7c478bd9Sstevel@tonic-gate 	Ar_desc		*adp;
65*7c478bd9Sstevel@tonic-gate 	Elf_Arsym	*arsym;
66*7c478bd9Sstevel@tonic-gate 	Ar_aux		*aux;
67*7c478bd9Sstevel@tonic-gate 
68*7c478bd9Sstevel@tonic-gate 	if (DBG_NOTCLASS(DBG_STATISTICS | DBG_UNUSED))
69*7c478bd9Sstevel@tonic-gate 		return;
70*7c478bd9Sstevel@tonic-gate 
71*7c478bd9Sstevel@tonic-gate 	dbg_print(MSG_ORIG(MSG_STR_EMPTY));
72*7c478bd9Sstevel@tonic-gate 	for (LIST_TRAVERSE(&ofl->ofl_ars, lnp, adp)) {
73*7c478bd9Sstevel@tonic-gate 		size_t	poffset = 0;
74*7c478bd9Sstevel@tonic-gate 		uint_t	count = 0, used = 0;
75*7c478bd9Sstevel@tonic-gate 
76*7c478bd9Sstevel@tonic-gate 		if ((adp->ad_flags & FLG_ARD_EXTRACT) == 0) {
77*7c478bd9Sstevel@tonic-gate 			Dbg_unused_file(adp->ad_name, 0);
78*7c478bd9Sstevel@tonic-gate 			continue;
79*7c478bd9Sstevel@tonic-gate 		}
80*7c478bd9Sstevel@tonic-gate 
81*7c478bd9Sstevel@tonic-gate 		if (DBG_NOTCLASS(DBG_STATISTICS))
82*7c478bd9Sstevel@tonic-gate 			continue;
83*7c478bd9Sstevel@tonic-gate 
84*7c478bd9Sstevel@tonic-gate 		arsym = adp->ad_start;
85*7c478bd9Sstevel@tonic-gate 		aux = adp->ad_aux;
86*7c478bd9Sstevel@tonic-gate 		while (arsym->as_off) {
87*7c478bd9Sstevel@tonic-gate 			/*
88*7c478bd9Sstevel@tonic-gate 			 * Assume that symbols from the same member file are
89*7c478bd9Sstevel@tonic-gate 			 * adjacent within the archive symbol table.
90*7c478bd9Sstevel@tonic-gate 			 */
91*7c478bd9Sstevel@tonic-gate 			if (poffset != arsym->as_off) {
92*7c478bd9Sstevel@tonic-gate 				count++;
93*7c478bd9Sstevel@tonic-gate 				poffset = arsym->as_off;
94*7c478bd9Sstevel@tonic-gate 				if (aux->au_mem == FLG_ARMEM_PROC)
95*7c478bd9Sstevel@tonic-gate 					used++;
96*7c478bd9Sstevel@tonic-gate 			}
97*7c478bd9Sstevel@tonic-gate 			aux++, arsym++;
98*7c478bd9Sstevel@tonic-gate 		}
99*7c478bd9Sstevel@tonic-gate 		if ((count == 0) || (used == 0))
100*7c478bd9Sstevel@tonic-gate 			continue;
101*7c478bd9Sstevel@tonic-gate #ifndef	UDIV_NOT_SUPPORTED
102*7c478bd9Sstevel@tonic-gate 		dbg_print(MSG_INTL(MSG_STATS_AR), adp->ad_name, count, used,
103*7c478bd9Sstevel@tonic-gate 		    ((used * 100) / count));
104*7c478bd9Sstevel@tonic-gate #endif
105*7c478bd9Sstevel@tonic-gate 	}
106*7c478bd9Sstevel@tonic-gate 	dbg_print(MSG_ORIG(MSG_STR_EMPTY));
107*7c478bd9Sstevel@tonic-gate }
108