home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
-
- #define PAGE_SIZE 4096
-
- #define addr_to_i(a) (((a) - histo_addr) / PAGE_SIZE)
- #define i_to_addr(i) (((i) * PAGE_SIZE) + histo_addr)
-
- extern char *calloc();
- extern void couldnot();
-
- extern FILE *outfp;
- extern int Hflag;
-
- static int *histo_buf;
- static int histo_length;
- static unsigned long histo_addr;
-
- int
- histo_init(first, length)
- unsigned long first;
- int length;
- {
- histo_length = (length + PAGE_SIZE - 1) / PAGE_SIZE;
-
- if ((histo_buf = (int *)calloc(histo_length, sizeof(int))) == (int *)0)
- {
- couldnot("allocate memory for histogram buffer of %d entries", histo_length);
- return -1;
- }
-
- histo_addr = first;
-
- return 0;
- }
-
- void
- histo_log(addr)
- unsigned long addr;
- {
- histo_buf[addr_to_i(addr)]++;
- }
-
- void
- histo_dump()
- {
- int i;
- int p;
-
- p = getpid();
-
- if (Hflag)
- {
- for (i = 0; i < histo_length; i++)
- fprintf(outfp, "%d:\t%d\t%d\n", p, i_to_addr(i), histo_buf[i]);
- }
- }
-