Print this page
libconv


   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  24  * Use is subject to license terms.

  25  */
  26 
  27 /*      Copyright (c) 1988 AT&T     */
  28 /*        All Rights Reserved   */
  29 
  30 /*
  31  *      Program profiling report generator.
  32  *
  33  *      Usage:
  34  *
  35  *      prof [-ChsVz] [-a | c | n | t]  [-o  |  x]   [-g  |  l]
  36  *          [-m mdata] [prog]
  37  *
  38  *      Where "prog" is the program that was profiled; "a.out" by default.
  39  *      Options are:
  40  *
  41  *      -n      Sort by symbol name.
  42  *      -t      Sort by decreasing time.
  43  *      -c      Sort by decreasing number of calls.
  44  *      -a      Sort by increasing symbol address.


1294         struct slist *p1 = (struct slist *)arg1;
1295         struct slist *p2 = (struct slist *)arg2;
1296         int diff;
1297 
1298                 /* flex names has variable length strings for names */
1299         diff = strcmp(p1->sl_name, p2->sl_name);
1300         return (CMP1(diff));
1301 }
1302 
1303 #define STRSPACE 2400           /* guess at amount of string space */
1304 
1305 char *format_buf;
1306 #define FORMAT_BUF      "%s\n\t\t\t\t\t    [%s]"
1307 
1308 static char *
1309 demangled_name(char *s)
1310 {
1311         const char *name;
1312         size_t  len;
1313 
1314         name = conv_demangle_name(s);
1315 
1316         if (strcmp(name, s) == 0)
1317                 return (s);
1318 
1319         if (format_buf != NULL)
1320                 free(format_buf);
1321 
1322         len = strlen(name) + strlen(FORMAT_BUF) + strlen(s) + 1;
1323         format_buf = malloc(len);
1324         if (format_buf == NULL)
1325                 return (s);
1326         (void) snprintf(format_buf, len, FORMAT_BUF, name, s);

1327         return (format_buf);
1328 }
1329 
1330 /* getname - get the name of a symbol in a permanent fashion */
1331 static char *
1332 getname(PROF_FILE *ldpter, PROF_SYMBOL symbol)
1333 {
1334         static char *strtable = NULL;   /* space for names */
1335         static int sp_used = 0;         /* space used so far */
1336         static int size = 0;            /* size of string table */
1337         char *name;                     /* name to store */
1338         int lth;                        /* space needed for name */
1339         int get;                        /* amount of space to get */
1340 
1341         name = elf_strptr(ldpter->pf_elf_p, ldpter->pf_symstr_ndx,
1342             symbol.ps_sym.st_name);
1343         if (name == NULL)
1344                 return ("<<bad symbol name>>");
1345 
1346         if (Cflag)




   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  24  * Use is subject to license terms.
  25  * Copyright 2018 Jason King
  26  */
  27 
  28 /*      Copyright (c) 1988 AT&T     */
  29 /*        All Rights Reserved   */
  30 
  31 /*
  32  *      Program profiling report generator.
  33  *
  34  *      Usage:
  35  *
  36  *      prof [-ChsVz] [-a | c | n | t]  [-o  |  x]   [-g  |  l]
  37  *          [-m mdata] [prog]
  38  *
  39  *      Where "prog" is the program that was profiled; "a.out" by default.
  40  *      Options are:
  41  *
  42  *      -n      Sort by symbol name.
  43  *      -t      Sort by decreasing time.
  44  *      -c      Sort by decreasing number of calls.
  45  *      -a      Sort by increasing symbol address.


1295         struct slist *p1 = (struct slist *)arg1;
1296         struct slist *p2 = (struct slist *)arg2;
1297         int diff;
1298 
1299                 /* flex names has variable length strings for names */
1300         diff = strcmp(p1->sl_name, p2->sl_name);
1301         return (CMP1(diff));
1302 }
1303 
1304 #define STRSPACE 2400           /* guess at amount of string space */
1305 
1306 char *format_buf;
1307 #define FORMAT_BUF      "%s\n\t\t\t\t\t    [%s]"
1308 
1309 static char *
1310 demangled_name(char *s)
1311 {
1312         const char *name;
1313         size_t  len;
1314 
1315         if ((name = conv_demangle_name(s)) == s)


1316                 return (s);
1317 
1318         if (format_buf != NULL)
1319                 free(format_buf);
1320 
1321         len = strlen(name) + strlen(FORMAT_BUF) + strlen(s) + 1;
1322         format_buf = malloc(len);
1323         if (format_buf == NULL)
1324                 return (s);
1325         (void) snprintf(format_buf, len, FORMAT_BUF, name, s);
1326         free((void *)name);
1327         return (format_buf);
1328 }
1329 
1330 /* getname - get the name of a symbol in a permanent fashion */
1331 static char *
1332 getname(PROF_FILE *ldpter, PROF_SYMBOL symbol)
1333 {
1334         static char *strtable = NULL;   /* space for names */
1335         static int sp_used = 0;         /* space used so far */
1336         static int size = 0;            /* size of string table */
1337         char *name;                     /* name to store */
1338         int lth;                        /* space needed for name */
1339         int get;                        /* amount of space to get */
1340 
1341         name = elf_strptr(ldpter->pf_elf_p, ldpter->pf_symstr_ndx,
1342             symbol.ps_sym.st_name);
1343         if (name == NULL)
1344                 return ("<<bad symbol name>>");
1345 
1346         if (Cflag)