*
* Copyright (C) 1994,1996 Alessandro Rubini (rubini@ipvvis.unipv.it)
*
- * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
+ * Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
/*
* Paul Mundt <lethal@linux-sh.org>.
*/
+//usage:#define readprofile_trivial_usage
+//usage: "[OPTIONS]"
+//usage:#define readprofile_full_usage "\n\n"
+//usage: " -m mapfile (Default: /boot/System.map)"
+//usage: "\n -p profile (Default: /proc/profile)"
+//usage: "\n -M NUM Set the profiling multiplier to NUM"
+//usage: "\n -i Print only info about the sampling step"
+//usage: "\n -v Verbose"
+//usage: "\n -a Print all symbols, even if count is 0"
+//usage: "\n -b Print individual histogram-bin counts"
+//usage: "\n -s Print individual counters within functions"
+//usage: "\n -r Reset all the counters (root only)"
+//usage: "\n -n Disable byte order auto-detection"
+
#include "libbb.h"
#include <sys/utsname.h>
static const char defaultpro[] ALIGN1 = "/proc/profile";
int readprofile_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
-int readprofile_main(int argc ATTRIBUTE_UNUSED, char **argv)
+int readprofile_main(int argc UNUSED_PARAM, char **argv)
{
FILE *map;
const char *mapFile, *proFile;
*/
to_write = sizeof(int);
if (!optMult)
- to_write = 1; /* sth different from sizeof(int) */
+ to_write = 1; /* sth different from sizeof(int) */
fd = xopen(defaultpro, O_WRONLY);
xwrite(fd, &multiplier, to_write);
* Use an fd for the profiling buffer, to skip stdio overhead
*/
len = MAXINT(ssize_t);
- buf = xmalloc_open_read_close(proFile, &len);
+ buf = xmalloc_xopen_read_close(proFile, &len);
if (!optNative) {
- int entries = len/sizeof(*buf);
+ int entries = len / sizeof(*buf);
int big = 0, small = 0, i;
unsigned *p;
step = buf[0];
if (optInfo) {
- printf("Sampling_step: %i\n", step);
+ printf("Sampling_step: %u\n", step);
return EXIT_SUCCESS;
}
total = 0;
- map = xfopen(mapFile, "r");
+ map = xfopen_for_read(mapFile);
while (fgets(mapline, S_LEN, map)) {
if (sscanf(mapline, "%llx %s %s", &fn_add, mode, fn_name) != 3)
bb_error_msg_and_die("%s(%i): wrong map line",
- mapFile, maplineno);
+ mapFile, maplineno);
if (!strcmp(fn_name, "_stext")) /* only elf works like this */ {
add0 = fn_add;
/* ignore any LEADING (before a '[tT]' symbol is found)
Absolute symbols */
if ((*mode == 'A' || *mode == '?') && total == 0) continue;
- if (*mode != 'T' && *mode != 't' &&
- *mode != 'W' && *mode != 'w')
- break; /* only text is profiled */
+ if (*mode != 'T' && *mode != 't'
+ && *mode != 'W' && *mode != 'w'
+ ) {
+ break; /* only text is profiled */
+ }
if (indx >= len / sizeof(*buf))
bb_error_msg_and_die("profile address out of range. "
- "Wrong map file?");
+ "Wrong map file?");
while (indx < (next_add-add0)/step) {
if (optBins && (buf[indx] || optAll)) {
&& (fn_len = next_add-fn_add) != 0
) {
if (optVerbose)
- printf("%016llx %-40s %6i %8.4f\n", fn_add,
- fn_name, this, this/(double)fn_len);
+ printf("%016llx %-40s %6u %8.4f\n", fn_add,
+ fn_name, this, this/(double)fn_len);
else
- printf("%6i %-40s %8.4f\n",
- this, fn_name, this/(double)fn_len);
+ printf("%6u %-40s %8.4f\n",
+ this, fn_name, this/(double)fn_len);
if (optSub) {
unsigned long long scan;
addr = (scan - 1)*step + add0;
printf("\t%#llx\t%s+%#llx\t%u\n",
- addr, fn_name, addr - fn_add,
- buf[scan]);
+ addr, fn_name, addr - fn_add,
+ buf[scan]);
}
}
}
}
/* clock ticks, out of kernel text - probably modules */
- printf("%6i %s\n", buf[len/sizeof(*buf)-1], "*unknown*");
+ printf("%6u %s\n", buf[len/sizeof(*buf)-1], "*unknown*");
/* trailer */
if (optVerbose)
- printf("%016x %-40s %6i %8.4f\n",
- 0, "total", total, total/(double)(fn_add-add0));
+ printf("%016x %-40s %6u %8.4f\n",
+ 0, "total", total, total/(double)(fn_add-add0));
else
- printf("%6i %-40s %8.4f\n",
- total, "total", total/(double)(fn_add-add0));
+ printf("%6u %-40s %8.4f\n",
+ total, "total", total/(double)(fn_add-add0));
fclose(map);
free(buf);