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