xref: /illumos-gate/usr/src/cmd/sgs/liblddbg/common/statistics.c (revision c174926f3ba44d30fdb24cfb4d93ae3fce579601)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate  * with the License.
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate  * and limitations under the License.
137c478bd9Sstevel@tonic-gate  *
147c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate  *
207c478bd9Sstevel@tonic-gate  * CDDL HEADER END
217c478bd9Sstevel@tonic-gate  */
22*c174926fSrie 
237c478bd9Sstevel@tonic-gate /*
24*c174926fSrie  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
25*c174926fSrie  * Use is subject to license terms.
267c478bd9Sstevel@tonic-gate  */
277c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #include	"_debug.h"
307c478bd9Sstevel@tonic-gate #include	"msg.h"
317c478bd9Sstevel@tonic-gate #include	"libld.h"
327c478bd9Sstevel@tonic-gate 
337c478bd9Sstevel@tonic-gate void
347c478bd9Sstevel@tonic-gate Dbg_statistics_ld(Ofl_desc *ofl)
357c478bd9Sstevel@tonic-gate {
367c478bd9Sstevel@tonic-gate 	if (DBG_NOTCLASS(DBG_STATISTICS))
377c478bd9Sstevel@tonic-gate 		return;
387c478bd9Sstevel@tonic-gate 
397c478bd9Sstevel@tonic-gate 	dbg_print(MSG_ORIG(MSG_STR_EMPTY));
407c478bd9Sstevel@tonic-gate 	dbg_print(MSG_INTL(MSG_STATS_GENERAL));
417c478bd9Sstevel@tonic-gate 
427c478bd9Sstevel@tonic-gate 	if (ofl->ofl_objscnt || ofl->ofl_soscnt || ofl->ofl_arscnt) {
437c478bd9Sstevel@tonic-gate 		dbg_print(MSG_INTL(MSG_STATS_FILES),
447c478bd9Sstevel@tonic-gate 		    EC_XWORD(ofl->ofl_objscnt), EC_XWORD(ofl->ofl_soscnt),
457c478bd9Sstevel@tonic-gate 		    EC_XWORD(ofl->ofl_arscnt));
467c478bd9Sstevel@tonic-gate 	}
477c478bd9Sstevel@tonic-gate 
48*c174926fSrie 	if (ofl->ofl_locscnt || ofl->ofl_globcnt) {
49*c174926fSrie 		dbg_print(MSG_INTL(MSG_STATS_SYMBOLS_OUT),
50*c174926fSrie 		    EC_XWORD(ofl->ofl_globcnt), EC_XWORD(ofl->ofl_locscnt));
51*c174926fSrie 	}
52*c174926fSrie 	if (ofl->ofl_entercnt || ofl->ofl_scopecnt || ofl->ofl_elimcnt) {
53*c174926fSrie 		dbg_print(MSG_INTL(MSG_STATS_SYMBOLS_IN),
54*c174926fSrie 		    EC_XWORD(ofl->ofl_entercnt), EC_XWORD(ofl->ofl_scopecnt),
55*c174926fSrie 		    EC_XWORD(ofl->ofl_elimcnt));
567c478bd9Sstevel@tonic-gate 	}
577c478bd9Sstevel@tonic-gate 
58*c174926fSrie 	if (ofl->ofl_outrelscnt) {
59*c174926fSrie 		dbg_print(MSG_INTL(MSG_STATS_RELOCS_OUT),
60*c174926fSrie 		    EC_XWORD(ofl->ofl_outrelscnt));
61*c174926fSrie 	}
62*c174926fSrie 	if (ofl->ofl_entrelscnt || ofl->ofl_actrelscnt) {
63*c174926fSrie 		dbg_print(MSG_INTL(MSG_STATS_RELOCS_IN),
64*c174926fSrie 		    EC_XWORD(ofl->ofl_entrelscnt),
657c478bd9Sstevel@tonic-gate 		    EC_XWORD(ofl->ofl_actrelscnt));
667c478bd9Sstevel@tonic-gate 	}
677c478bd9Sstevel@tonic-gate }
687c478bd9Sstevel@tonic-gate 
697c478bd9Sstevel@tonic-gate void
707c478bd9Sstevel@tonic-gate Dbg_statistics_ar(Ofl_desc *ofl)
717c478bd9Sstevel@tonic-gate {
727c478bd9Sstevel@tonic-gate 	Listnode	*lnp;
737c478bd9Sstevel@tonic-gate 	Ar_desc		*adp;
747c478bd9Sstevel@tonic-gate 	Elf_Arsym	*arsym;
757c478bd9Sstevel@tonic-gate 	Ar_aux		*aux;
767c478bd9Sstevel@tonic-gate 
777c478bd9Sstevel@tonic-gate 	if (DBG_NOTCLASS(DBG_STATISTICS | DBG_UNUSED))
787c478bd9Sstevel@tonic-gate 		return;
797c478bd9Sstevel@tonic-gate 
807c478bd9Sstevel@tonic-gate 	dbg_print(MSG_ORIG(MSG_STR_EMPTY));
817c478bd9Sstevel@tonic-gate 	for (LIST_TRAVERSE(&ofl->ofl_ars, lnp, adp)) {
827c478bd9Sstevel@tonic-gate 		size_t	poffset = 0;
837c478bd9Sstevel@tonic-gate 		uint_t	count = 0, used = 0;
847c478bd9Sstevel@tonic-gate 
857c478bd9Sstevel@tonic-gate 		if ((adp->ad_flags & FLG_ARD_EXTRACT) == 0) {
867c478bd9Sstevel@tonic-gate 			Dbg_unused_file(adp->ad_name, 0);
877c478bd9Sstevel@tonic-gate 			continue;
887c478bd9Sstevel@tonic-gate 		}
897c478bd9Sstevel@tonic-gate 
907c478bd9Sstevel@tonic-gate 		if (DBG_NOTCLASS(DBG_STATISTICS))
917c478bd9Sstevel@tonic-gate 			continue;
927c478bd9Sstevel@tonic-gate 
937c478bd9Sstevel@tonic-gate 		arsym = adp->ad_start;
947c478bd9Sstevel@tonic-gate 		aux = adp->ad_aux;
957c478bd9Sstevel@tonic-gate 		while (arsym->as_off) {
967c478bd9Sstevel@tonic-gate 			/*
977c478bd9Sstevel@tonic-gate 			 * Assume that symbols from the same member file are
987c478bd9Sstevel@tonic-gate 			 * adjacent within the archive symbol table.
997c478bd9Sstevel@tonic-gate 			 */
1007c478bd9Sstevel@tonic-gate 			if (poffset != arsym->as_off) {
1017c478bd9Sstevel@tonic-gate 				count++;
1027c478bd9Sstevel@tonic-gate 				poffset = arsym->as_off;
1037c478bd9Sstevel@tonic-gate 				if (aux->au_mem == FLG_ARMEM_PROC)
1047c478bd9Sstevel@tonic-gate 					used++;
1057c478bd9Sstevel@tonic-gate 			}
1067c478bd9Sstevel@tonic-gate 			aux++, arsym++;
1077c478bd9Sstevel@tonic-gate 		}
1087c478bd9Sstevel@tonic-gate 		if ((count == 0) || (used == 0))
1097c478bd9Sstevel@tonic-gate 			continue;
1107c478bd9Sstevel@tonic-gate #ifndef	UDIV_NOT_SUPPORTED
1117c478bd9Sstevel@tonic-gate 		dbg_print(MSG_INTL(MSG_STATS_AR), adp->ad_name, count, used,
1127c478bd9Sstevel@tonic-gate 		    ((used * 100) / count));
1137c478bd9Sstevel@tonic-gate #endif
1147c478bd9Sstevel@tonic-gate 	}
1157c478bd9Sstevel@tonic-gate 	dbg_print(MSG_ORIG(MSG_STR_EMPTY));
1167c478bd9Sstevel@tonic-gate }
117