diff options
author | Karel Zak <kzak@redhat.com> | 2006-12-07 00:26:16 +0100 |
---|---|---|
committer | Karel Zak <kzak@redhat.com> | 2006-12-07 00:26:16 +0100 |
commit | c129767e063c5c9839cc9d94c34fd88dac3fb9a6 (patch) | |
tree | 13dd85577b43ec1be3cf51a8d913282c2a92259c /sys-utils | |
parent | d03dd60840f0a08464d5266539ad356aefe24b03 (diff) | |
download | util-linux-old-c129767e063c5c9839cc9d94c34fd88dac3fb9a6.tar.gz |
Imported from util-linux-2.12b tarball.
Diffstat (limited to 'sys-utils')
-rw-r--r-- | sys-utils/dmesg.c | 57 | ||||
-rw-r--r-- | sys-utils/readprofile.c | 75 |
2 files changed, 98 insertions, 34 deletions
diff --git a/sys-utils/dmesg.c b/sys-utils/dmesg.c index b9a978ee..d7adc0ae 100644 --- a/sys-utils/dmesg.c +++ b/sys-utils/dmesg.c @@ -11,6 +11,24 @@ * */ +/* + * Commands to sys_syslog: + * + * 0 -- Close the log. Currently a NOP. + * 1 -- Open the log. Currently a NOP. + * 2 -- Read from the log. + * 3 -- Read all messages remaining in the ring buffer. + * 4 -- Read and clear all messages remaining in the ring buffer + * 5 -- Clear ring buffer. + * 6 -- Disable printk's to console + * 7 -- Enable printk's to console + * 8 -- Set level of messages printed to console + * 9 -- Return number of unread characters in the log buffer + * [supported since 2.4.10] + * + * Only function 3 is allowed to non-root processes. + */ + #include <linux/unistd.h> #include <stdio.h> #include <getopt.h> @@ -41,13 +59,14 @@ usage(void) { int main(int argc, char *argv[]) { char *buf; - int bufsize = 16392; + int sz; + int bufsize = 0; int i; int n; int c; int level = 0; int lastc; - int cmd = 3; + int cmd = 3; /* Read all messages in the ring buffer */ setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); @@ -57,14 +76,16 @@ main(int argc, char *argv[]) { while ((c = getopt(argc, argv, "cn:s:")) != -1) { switch (c) { case 'c': - cmd = 4; + cmd = 4; /* Read and clear all messages */ break; case 'n': - cmd = 8; + cmd = 8; /* Set level of messages */ level = atoi(optarg); break; case 's': bufsize = atoi(optarg); + if (bufsize < 4096) + bufsize = 4096; break; case '?': default: @@ -89,9 +110,31 @@ main(int argc, char *argv[]) { exit(0); } - if (bufsize < 4096) bufsize = 4096; - buf = (char*)malloc(bufsize); - n = klogctl(cmd, buf, bufsize); + if (!bufsize) { + n = klogctl(10, NULL, 0); /* read ringbuffer size */ + if (n > 0) + bufsize = n; + } + + if (bufsize) { + sz = bufsize + 8; + buf = (char *) malloc(sz); + n = klogctl(cmd, buf, sz); + } else { + sz = 16392; + while (1) { + buf = (char *) malloc(sz); + n = klogctl(3, buf, sz); /* read only */ + if (n != sz || sz > (1<<28)) + break; + free(buf); + sz *= 4; + } + + if (n > 0 && cmd == 4) + n = klogctl(cmd, buf, sz); /* read and clear */ + } + if (n < 0) { perror("klogctl"); exit(1); diff --git a/sys-utils/readprofile.c b/sys-utils/readprofile.c index de3de946..efb15658 100644 --- a/sys-utils/readprofile.c +++ b/sys-utils/readprofile.c @@ -35,6 +35,9 @@ * - also try /boot/System.map-`uname -r` * 2003-04-09 Werner Almesberger <wa@almesberger.net> * - fixed off-by eight error and improved heuristics in byte order detection + * 2003-08-12 Nikita Danilov <Nikita@Namesys.COM> + * - added -s option; example of use: + * "readprofile -s -m /boot/System.map-test | grep __d_lookup | sort -n -k3" */ #include <errno.h> @@ -55,7 +58,7 @@ static char *prgname; /* These are the defaults */ static char defaultmap[]="/usr/src/linux/System.map"; static char defaultpro[]="/proc/profile"; -static char optstring[]="M:m:np:itvarVb"; +static char optstring[]="M:m:np:itvarVbs"; static void * xmalloc (size_t size) { @@ -111,18 +114,19 @@ boot_uname_r_str(void) { static void usage(void) { - fprintf(stderr, - _("%s: Usage: \"%s [options]\n" - "\t -m <mapfile> (defaults: \"%s\" and\n\t\t\t\t \"%s\")\n" - "\t -p <pro-file> (default: \"%s\")\n" - "\t -M <mult> set the profiling multiplier to <mult>\n" - "\t -i print only info about the sampling step\n" - "\t -v print verbose data\n" - "\t -a print all symbols, even if count is 0\n" - "\t -b print individual histogram-bin counts\n" - "\t -r reset all the counters (root only)\n" - "\t -n disable byte order auto-detection\n" - "\t -V print version and exit\n"), + fprintf(stderr, _( + "%s: Usage: \"%s [options]\n" + "\t -m <mapfile> (defaults: \"%s\" and\n\t\t\t\t \"%s\")\n" + "\t -p <pro-file> (default: \"%s\")\n" + "\t -M <mult> set the profiling multiplier to <mult>\n" + "\t -i print only info about the sampling step\n" + "\t -v print verbose data\n" + "\t -a print all symbols, even if count is 0\n" + "\t -b print individual histogram-bin counts\n" + "\t -s print individual counters within functions\n" + "\t -r reset all the counters (root only)\n" + "\t -n disable byte order auto-detection\n" + "\t -V print version and exit\n"), prgname, prgname, defaultmap, boot_uname_r_str(), defaultpro); exit(1); } @@ -140,7 +144,8 @@ main(int argc, char **argv) { char fn_name[S_LEN], next_name[S_LEN]; /* current and next name */ char mode[8]; int c; - int optAll=0, optInfo=0, optReset=0, optVerbose=0, optNative=0, optBins=0; + int optAll=0, optInfo=0, optReset=0, optVerbose=0, optNative=0; + int optBins=0, optSub=0; char mapline[S_LEN]; int maplineno=1; int popenMap; /* flag to tell if popen() has been used */ @@ -173,6 +178,9 @@ main(int argc, char **argv) { case 'b': optBins++; break; + case 's': + optSub++; + break; case 'i': optInfo++; break; @@ -228,8 +236,8 @@ main(int argc, char **argv) { * Use an fd for the profiling buffer, to skip stdio overhead */ if (((proFd=open(proFile,O_RDONLY)) < 0) - || ((int)(len=lseek(proFd,0,SEEK_END)) < 0) - || (lseek(proFd,0,SEEK_SET) < 0)) { + || ((int)(len=lseek(proFd,0,SEEK_END)) < 0) + || (lseek(proFd,0,SEEK_SET) < 0)) { fprintf(stderr,"%s: %s: %s\n",prgname,proFile,strerror(errno)); exit(1); } @@ -258,7 +266,7 @@ main(int argc, char **argv) { } if (big > small) { fprintf(stderr,"Assuming reversed byte order. " - "Use -n to force native byte order.\n"); + "Use -n to force native byte order.\n"); for (p = buf; p < buf+entries; p++) for (i = 0; i < sizeof(*buf)/2; i++) { unsigned char *b = (unsigned char *) p; @@ -352,18 +360,31 @@ main(int argc, char **argv) { if (optBins) { if (optVerbose || this > 0) printf (" total\t\t\t\t%u\n", this); - } else { - fn_len = next_add-fn_add; - if (fn_len && (this || optAll)) { - if (optVerbose) - printf("%016llx %-40s %6i %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); + } else if ((this || 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); + else + printf("%6i %-40s %8.4f\n", + this,fn_name,this/(double)fn_len); + if (optSub) { + unsigned long long scan; + + for (scan = (fn_add-add0)/step + 1; + scan < (next_add-add0)/step; scan++) { + unsigned long long addr; + + addr = (scan - 1)*step + add0; + printf("\t%#llx\t%s+%#llx\t%u\n", + addr, fn_name, addr - fn_add, + buf[scan]); + } } } - fn_add=next_add; strcpy(fn_name,next_name); + + fn_add = next_add; + strcpy(fn_name,next_name); maplineno++; } |