xref: /titanic_41/usr/src/cmd/sgs/liblddbg/common/statistics.c (revision d291d9f21e8c0417aec99de243dd48bc400002d0)
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 /*
24  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
25  * Use is subject to license terms.
26  */
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 #include	"_debug.h"
30 #include	"msg.h"
31 #include	"libld.h"
32 
33 void
34 Dbg_statistics_ld(Ofl_desc *ofl)
35 {
36 	if (DBG_NOTCLASS(DBG_STATISTICS))
37 		return;
38 
39 	dbg_print(MSG_ORIG(MSG_STR_EMPTY));
40 	dbg_print(MSG_INTL(MSG_STATS_GENERAL));
41 
42 	if (ofl->ofl_objscnt || ofl->ofl_soscnt || ofl->ofl_arscnt) {
43 		dbg_print(MSG_INTL(MSG_STATS_FILES),
44 		    EC_XWORD(ofl->ofl_objscnt), EC_XWORD(ofl->ofl_soscnt),
45 		    EC_XWORD(ofl->ofl_arscnt));
46 	}
47 
48 	if (ofl->ofl_locscnt || ofl->ofl_globcnt) {
49 		dbg_print(MSG_INTL(MSG_STATS_SYMBOLS_OUT),
50 		    EC_XWORD(ofl->ofl_globcnt), EC_XWORD(ofl->ofl_locscnt));
51 	}
52 	if (ofl->ofl_entercnt || ofl->ofl_scopecnt || ofl->ofl_elimcnt) {
53 		dbg_print(MSG_INTL(MSG_STATS_SYMBOLS_IN),
54 		    EC_XWORD(ofl->ofl_entercnt), EC_XWORD(ofl->ofl_scopecnt),
55 		    EC_XWORD(ofl->ofl_elimcnt));
56 	}
57 
58 	if (ofl->ofl_outrelscnt) {
59 		dbg_print(MSG_INTL(MSG_STATS_RELOCS_OUT),
60 		    EC_XWORD(ofl->ofl_outrelscnt));
61 	}
62 	if (ofl->ofl_entrelscnt || ofl->ofl_actrelscnt) {
63 		dbg_print(MSG_INTL(MSG_STATS_RELOCS_IN),
64 		    EC_XWORD(ofl->ofl_entrelscnt),
65 		    EC_XWORD(ofl->ofl_actrelscnt));
66 	}
67 }
68 
69 void
70 Dbg_statistics_ar(Ofl_desc *ofl)
71 {
72 	Listnode	*lnp;
73 	Ar_desc		*adp;
74 	Elf_Arsym	*arsym;
75 	Ar_aux		*aux;
76 
77 	if (DBG_NOTCLASS(DBG_STATISTICS | DBG_UNUSED))
78 		return;
79 
80 	dbg_print(MSG_ORIG(MSG_STR_EMPTY));
81 	for (LIST_TRAVERSE(&ofl->ofl_ars, lnp, adp)) {
82 		size_t	poffset = 0;
83 		uint_t	count = 0, used = 0;
84 
85 		if ((adp->ad_flags & FLG_ARD_EXTRACT) == 0) {
86 			Dbg_unused_file(adp->ad_name, 0);
87 			continue;
88 		}
89 
90 		if (DBG_NOTCLASS(DBG_STATISTICS))
91 			continue;
92 
93 		arsym = adp->ad_start;
94 		aux = adp->ad_aux;
95 		while (arsym->as_off) {
96 			/*
97 			 * Assume that symbols from the same member file are
98 			 * adjacent within the archive symbol table.
99 			 */
100 			if (poffset != arsym->as_off) {
101 				count++;
102 				poffset = arsym->as_off;
103 				if (aux->au_mem == FLG_ARMEM_PROC)
104 					used++;
105 			}
106 			aux++, arsym++;
107 		}
108 		if ((count == 0) || (used == 0))
109 			continue;
110 #ifndef	UDIV_NOT_SUPPORTED
111 		dbg_print(MSG_INTL(MSG_STATS_AR), adp->ad_name, count, used,
112 		    ((used * 100) / count));
113 #endif
114 	}
115 	dbg_print(MSG_ORIG(MSG_STR_EMPTY));
116 }
117