1995-03-10 08:53:55 +00:00
|
|
|
/*
|
|
|
|
* ----------------------------------------------------------------------------
|
|
|
|
* "THE BEER-WARE LICENSE" (Revision 42):
|
|
|
|
* <phk@FreeBSD.org> wrote this file. As long as you retain this notice you
|
|
|
|
* can do whatever you want with this stuff. If we meet some day, and you think
|
|
|
|
* this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
|
|
|
|
* ----------------------------------------------------------------------------
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
1997-09-22 07:30:04 +01:00
|
|
|
#ifndef lint
|
|
|
|
static const char rcsid[] =
|
1999-08-28 02:35:59 +01:00
|
|
|
"$FreeBSD$";
|
1997-09-22 07:30:04 +01:00
|
|
|
#endif /* not lint */
|
|
|
|
|
|
|
|
#include <err.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <kvm.h>
|
1995-03-10 08:53:55 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
1997-09-22 07:30:04 +01:00
|
|
|
#include <unistd.h>
|
1995-03-10 08:53:55 +00:00
|
|
|
|
|
|
|
#define MAXBB 32768
|
|
|
|
|
|
|
|
struct bb {
|
|
|
|
u_long zero_one;
|
|
|
|
u_long filename;
|
|
|
|
u_long counts;
|
|
|
|
u_long ncounts;
|
|
|
|
u_long next;
|
|
|
|
u_long addr;
|
|
|
|
u_long nwords;
|
|
|
|
u_long func;
|
|
|
|
u_long lineno;
|
|
|
|
u_long file;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct nlist namelist[] = {
|
1999-03-21 12:32:17 +00:00
|
|
|
{ "bbhead" },
|
1995-03-10 08:53:55 +00:00
|
|
|
{ NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
u_long lineno[MAXBB];
|
|
|
|
u_long counts[MAXBB];
|
|
|
|
u_long addr[MAXBB];
|
|
|
|
u_long func[MAXBB];
|
|
|
|
u_long file[MAXBB];
|
|
|
|
char *fn[MAXBB];
|
|
|
|
char *pn[MAXBB];
|
|
|
|
|
|
|
|
kvm_t *kv;
|
1995-10-22 19:45:28 +00:00
|
|
|
|
|
|
|
int
|
1995-03-10 08:53:55 +00:00
|
|
|
main()
|
|
|
|
{
|
|
|
|
int i,j;
|
1997-08-14 11:36:02 +01:00
|
|
|
u_long l1,l2,l3,l4;
|
1995-03-10 08:53:55 +00:00
|
|
|
struct bb bb;
|
|
|
|
char buf[128];
|
|
|
|
|
|
|
|
kv = kvm_open(NULL,NULL,NULL,O_RDWR,"dnc");
|
1995-10-22 19:45:28 +00:00
|
|
|
if (!kv)
|
|
|
|
err(1,"kvm_open");
|
1995-03-10 08:53:55 +00:00
|
|
|
i = kvm_nlist(kv,namelist);
|
1995-10-22 19:45:28 +00:00
|
|
|
if (i)
|
|
|
|
err(1,"kvm_nlist");
|
1995-03-10 08:53:55 +00:00
|
|
|
|
|
|
|
l1 = namelist[0].n_value;
|
|
|
|
kvm_read(kv,l1,&l2,sizeof l2);
|
1999-03-21 12:32:17 +00:00
|
|
|
while(l2) {
|
1995-03-10 08:53:55 +00:00
|
|
|
l1 += sizeof l1;
|
1999-03-21 12:32:17 +00:00
|
|
|
kvm_read(kv,l2,&bb,sizeof bb);
|
|
|
|
l2 = bb.next;
|
1995-03-10 08:53:55 +00:00
|
|
|
if (!bb.ncounts)
|
|
|
|
continue;
|
1997-09-22 07:30:04 +01:00
|
|
|
if (bb.ncounts > MAXBB)
|
|
|
|
errx(1, "found %lu counts above limit of %u",
|
1995-03-10 08:53:55 +00:00
|
|
|
bb.ncounts, MAXBB);
|
|
|
|
kvm_read(kv,bb.lineno,lineno, bb.ncounts * sizeof lineno[0]);
|
|
|
|
kvm_read(kv,bb.counts,counts, bb.ncounts * sizeof counts[0]);
|
|
|
|
kvm_read(kv,bb.addr, addr, bb.ncounts * sizeof addr[0]);
|
|
|
|
kvm_read(kv,bb.file, file, bb.ncounts * sizeof file[0]);
|
|
|
|
kvm_read(kv,bb.func, func, bb.ncounts * sizeof func[0]);
|
1997-08-14 11:36:02 +01:00
|
|
|
l4 = 0;
|
1997-01-14 10:30:45 +00:00
|
|
|
for (i=0; i < bb.ncounts; i++) {
|
1997-08-14 11:36:02 +01:00
|
|
|
if (counts[i])
|
|
|
|
l4++;
|
|
|
|
if (!func[i] && i+1 < bb.ncounts)
|
|
|
|
func[i] = func[i+1];
|
|
|
|
}
|
|
|
|
if (!l4)
|
|
|
|
continue;
|
|
|
|
for (i=0; i < bb.ncounts; i++) {
|
|
|
|
|
|
|
|
if (0 && !counts[i])
|
1995-10-22 19:45:28 +00:00
|
|
|
continue;
|
1997-08-14 11:36:02 +01:00
|
|
|
|
1995-04-28 05:58:19 +01:00
|
|
|
if (!pn[i] && func[i]) {
|
1995-03-10 08:53:55 +00:00
|
|
|
kvm_read(kv,func[i], buf, sizeof buf);
|
|
|
|
buf[sizeof buf -1] = 0;
|
1995-10-22 19:45:28 +00:00
|
|
|
pn[i] = strdup(buf);
|
1995-03-10 08:53:55 +00:00
|
|
|
for(j=i+1;j<bb.ncounts;j++)
|
|
|
|
if (func[j] == func[i]) {
|
|
|
|
pn[j] = pn[i];
|
|
|
|
func[j] = 0;
|
|
|
|
}
|
|
|
|
}
|
1997-08-14 11:36:31 +01:00
|
|
|
if (!pn[i])
|
1995-04-28 05:58:19 +01:00
|
|
|
pn[i] = "-";
|
|
|
|
if (!fn[i] && file[i]) {
|
1995-03-10 08:53:55 +00:00
|
|
|
kvm_read(kv,file[i], buf, sizeof buf);
|
|
|
|
buf[sizeof buf -1] = 0;
|
1995-10-22 19:45:28 +00:00
|
|
|
fn[i] = strdup(buf);
|
1995-03-10 08:53:55 +00:00
|
|
|
for(j=i+1;j<bb.ncounts;j++)
|
|
|
|
if (file[j] == file[i]) {
|
|
|
|
fn[j] = fn[i];
|
|
|
|
file[j] = 0;
|
|
|
|
}
|
|
|
|
}
|
1995-04-28 05:58:19 +01:00
|
|
|
if (!fn[i])
|
|
|
|
fn[i] = "-";
|
1997-08-14 11:36:02 +01:00
|
|
|
l4 = 0;
|
|
|
|
if (i+1 < bb.ncounts)
|
|
|
|
l4 = addr[i+1] - addr[i];
|
|
|
|
printf("%s %5lu %s %lu %lu %lu %lu\n",
|
|
|
|
fn[i], lineno[i], pn[i], addr[i], counts[i], l4, counts[i] * l4);
|
1995-03-10 08:53:55 +00:00
|
|
|
}
|
|
|
|
for(i=0;i<bb.ncounts;i++) {
|
1995-10-22 19:45:28 +00:00
|
|
|
if (func[i] && pn[i])
|
1995-03-10 08:53:55 +00:00
|
|
|
free(pn[i]);
|
1995-10-22 19:45:28 +00:00
|
|
|
if (file[i] && fn[i])
|
1995-03-10 08:53:55 +00:00
|
|
|
free(fn[i]);
|
|
|
|
pn[i] = 0;
|
|
|
|
fn[i] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|