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 #pragma ident "%Z%%M% %I% %E% SMI"
28
29 /*
30 * All routines in this file are for processing new-style, *versioned*
31 * mon.out format. Together with rdelf.c, lookup.c and profv.h, these
32 * form the complete set of files to profile new-style mon.out files.
33 */
34
35 #include <stdlib.h>
36 #include <string.h>
37 #include "conv.h"
38 #include "profv.h"
39
40 bool time_in_ticks = FALSE;
41 size_t n_pcsamples, n_accounted_ticks, n_zeros, total_funcs;
42 unsigned char sort_flag;
43
44 mod_info_t modules;
45 size_t n_modules = 1; /* always include the aout object */
46
47 struct stat aout_stat, monout_stat;
48 profrec_t *profsym;
57 }
58
59 static void
60 setup_demangled_names(void)
61 {
62 const char *p;
63 char *nbp, *nbe, *namebuf;
64 size_t cur_len = 0, namebuf_sz = BUCKET_SZ;
65 size_t i, namelen;
66
67 if ((namebuf = malloc(namebuf_sz)) == NULL) {
68 (void) fprintf(stderr, "%s: can't allocate %d bytes\n",
69 cmdname, namebuf_sz);
70 exit(ERR_MEMORY);
71 }
72
73 nbp = namebuf;
74 nbe = namebuf + namebuf_sz;
75
76 for (i = 0; i < total_funcs; i++) {
77 if ((p = conv_demangle_name(profsym[i].name)) == NULL)
78 continue;
79
80 namelen = strlen(p);
81 if ((nbp + namelen + 1) > nbe) {
82 namebuf_sz += BUCKET_SZ;
83 namebuf = realloc(namebuf, namebuf_sz);
84 if (namebuf == NULL) {
85 (void) fprintf(stderr,
86 "%s: can't alloc %d bytes\n",
87 cmdname, BUCKET_SZ);
88 exit(ERR_MEMORY);
89 }
90
91 nbp = namebuf + cur_len;
92 nbe = namebuf + namebuf_sz;
93 }
94
95 (void) strcpy(nbp, p);
96 profsym[i].demangled_name = nbp;
97
98 nbp += namelen + 1;
99 cur_len += namelen + 1;
100 }
101 }
102
103 int
104 cmp_by_time(const void *arg1, const void *arg2)
105 {
106 profrec_t *a = (profrec_t *)arg1;
107 profrec_t *b = (profrec_t *)arg2;
108
109 if (a->percent_time > b->percent_time)
110 return (-1);
111 else if (a->percent_time < b->percent_time)
112 return (1);
113 else
114 return (0);
115 }
116
117 int
118 cmp_by_ncalls(const void *arg1, const void *arg2)
119 {
|
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 * Copyright 2018, Joyent, Inc.
27 */
28
29 /*
30 * All routines in this file are for processing new-style, *versioned*
31 * mon.out format. Together with rdelf.c, lookup.c and profv.h, these
32 * form the complete set of files to profile new-style mon.out files.
33 */
34
35 #include <stdlib.h>
36 #include <string.h>
37 #include "conv.h"
38 #include "profv.h"
39
40 bool time_in_ticks = FALSE;
41 size_t n_pcsamples, n_accounted_ticks, n_zeros, total_funcs;
42 unsigned char sort_flag;
43
44 mod_info_t modules;
45 size_t n_modules = 1; /* always include the aout object */
46
47 struct stat aout_stat, monout_stat;
48 profrec_t *profsym;
57 }
58
59 static void
60 setup_demangled_names(void)
61 {
62 const char *p;
63 char *nbp, *nbe, *namebuf;
64 size_t cur_len = 0, namebuf_sz = BUCKET_SZ;
65 size_t i, namelen;
66
67 if ((namebuf = malloc(namebuf_sz)) == NULL) {
68 (void) fprintf(stderr, "%s: can't allocate %d bytes\n",
69 cmdname, namebuf_sz);
70 exit(ERR_MEMORY);
71 }
72
73 nbp = namebuf;
74 nbe = namebuf + namebuf_sz;
75
76 for (i = 0; i < total_funcs; i++) {
77 p = conv_demangle_name(profsym[i].name);
78 if (p == profsym[i].name)
79 continue;
80
81 namelen = strlen(p);
82 if ((nbp + namelen + 1) > nbe) {
83 namebuf_sz += BUCKET_SZ;
84 namebuf = realloc(namebuf, namebuf_sz);
85 if (namebuf == NULL) {
86 (void) fprintf(stderr,
87 "%s: can't alloc %d bytes\n",
88 cmdname, BUCKET_SZ);
89 exit(ERR_MEMORY);
90 }
91
92 nbp = namebuf + cur_len;
93 nbe = namebuf + namebuf_sz;
94 }
95
96 (void) strcpy(nbp, p);
97 profsym[i].demangled_name = nbp;
98
99 nbp += namelen + 1;
100 cur_len += namelen + 1;
101 free((void *)p);
102 }
103 }
104
105 int
106 cmp_by_time(const void *arg1, const void *arg2)
107 {
108 profrec_t *a = (profrec_t *)arg1;
109 profrec_t *b = (profrec_t *)arg2;
110
111 if (a->percent_time > b->percent_time)
112 return (-1);
113 else if (a->percent_time < b->percent_time)
114 return (1);
115 else
116 return (0);
117 }
118
119 int
120 cmp_by_ncalls(const void *arg1, const void *arg2)
121 {
|