Deleted Added
full compact
kgmon.c (133249) kgmon.c (134505)
1/*
2 * Copyright (c) 1983, 1992, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 24 unchanged lines hidden (view full) ---

33 The Regents of the University of California. All rights reserved.\n";
34#endif /* not lint */
35
36#ifndef lint
37#if 0
38static char sccsid[] = "@(#)kgmon.c 8.1 (Berkeley) 6/6/93";
39#endif
40static const char rcsid[] =
1/*
2 * Copyright (c) 1983, 1992, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 24 unchanged lines hidden (view full) ---

33 The Regents of the University of California. All rights reserved.\n";
34#endif /* not lint */
35
36#ifndef lint
37#if 0
38static char sccsid[] = "@(#)kgmon.c 8.1 (Berkeley) 6/6/93";
39#endif
40static const char rcsid[] =
41 "$FreeBSD: head/usr.sbin/kgmon/kgmon.c 133249 2004-08-07 04:28:56Z imp $";
41 "$FreeBSD: head/usr.sbin/kgmon/kgmon.c 134505 2004-08-30 03:11:46Z marcel $";
42#endif /* not lint */
43
44#include <sys/param.h>
45#include <sys/file.h>
46#include <sys/time.h>
47#include <sys/sysctl.h>
48#include <sys/gmon.h>
49#include <ctype.h>

--- 338 unchanged lines hidden (view full) ---

388 kvp->gpm.kcountsize);
389 } else {
390 mib[2] = GPROF_COUNT;
391 i = kvp->gpm.kcountsize;
392 if (sysctl(mib, 3, tickbuf, &i, NULL, 0) < 0)
393 i = 0;
394 }
395 if (i != kvp->gpm.kcountsize)
42#endif /* not lint */
43
44#include <sys/param.h>
45#include <sys/file.h>
46#include <sys/time.h>
47#include <sys/sysctl.h>
48#include <sys/gmon.h>
49#include <ctype.h>

--- 338 unchanged lines hidden (view full) ---

388 kvp->gpm.kcountsize);
389 } else {
390 mib[2] = GPROF_COUNT;
391 i = kvp->gpm.kcountsize;
392 if (sysctl(mib, 3, tickbuf, &i, NULL, 0) < 0)
393 i = 0;
394 }
395 if (i != kvp->gpm.kcountsize)
396 errx(6, "read ticks: read %u, got %d: %s",
397 kvp->gpm.kcountsize, i,
396 errx(6, "read ticks: read %lu, got %ld: %s",
397 kvp->gpm.kcountsize, (long)i,
398 kflag ? kvm_geterr(kvp->kd) : strerror(errno));
399 if ((fwrite(tickbuf, kvp->gpm.kcountsize, 1, fp)) != 1)
400 err(7, "writing tocks to gmon.out");
401 free(tickbuf);
402
403 /*
404 * Write out the arc info.
405 */

--- 4 unchanged lines hidden (view full) ---

410 kvp->gpm.fromssize);
411 } else {
412 mib[2] = GPROF_FROMS;
413 i = kvp->gpm.fromssize;
414 if (sysctl(mib, 3, froms, &i, NULL, 0) < 0)
415 i = 0;
416 }
417 if (i != kvp->gpm.fromssize)
398 kflag ? kvm_geterr(kvp->kd) : strerror(errno));
399 if ((fwrite(tickbuf, kvp->gpm.kcountsize, 1, fp)) != 1)
400 err(7, "writing tocks to gmon.out");
401 free(tickbuf);
402
403 /*
404 * Write out the arc info.
405 */

--- 4 unchanged lines hidden (view full) ---

410 kvp->gpm.fromssize);
411 } else {
412 mib[2] = GPROF_FROMS;
413 i = kvp->gpm.fromssize;
414 if (sysctl(mib, 3, froms, &i, NULL, 0) < 0)
415 i = 0;
416 }
417 if (i != kvp->gpm.fromssize)
418 errx(9, "read froms: read %u, got %d: %s",
419 kvp->gpm.fromssize, i,
418 errx(9, "read froms: read %lu, got %ld: %s",
419 kvp->gpm.fromssize, (long)i,
420 kflag ? kvm_geterr(kvp->kd) : strerror(errno));
421 if ((tos = (struct tostruct *)malloc(kvp->gpm.tossize)) == NULL)
422 errx(10, "cannot allocate tos space");
423 if (kflag) {
424 i = kvm_read(kvp->kd, (u_long)kvp->gpm.tos, (void *)tos,
425 kvp->gpm.tossize);
426 } else {
427 mib[2] = GPROF_TOS;
428 i = kvp->gpm.tossize;
429 if (sysctl(mib, 3, tos, &i, NULL, 0) < 0)
430 i = 0;
431 }
432 if (i != kvp->gpm.tossize)
420 kflag ? kvm_geterr(kvp->kd) : strerror(errno));
421 if ((tos = (struct tostruct *)malloc(kvp->gpm.tossize)) == NULL)
422 errx(10, "cannot allocate tos space");
423 if (kflag) {
424 i = kvm_read(kvp->kd, (u_long)kvp->gpm.tos, (void *)tos,
425 kvp->gpm.tossize);
426 } else {
427 mib[2] = GPROF_TOS;
428 i = kvp->gpm.tossize;
429 if (sysctl(mib, 3, tos, &i, NULL, 0) < 0)
430 i = 0;
431 }
432 if (i != kvp->gpm.tossize)
433 errx(11, "read tos: read %u, got %d: %s",
434 kvp->gpm.tossize, i,
433 errx(11, "read tos: read %lu, got %ld: %s",
434 kvp->gpm.tossize, (long)i,
435 kflag ? kvm_geterr(kvp->kd) : strerror(errno));
436 if (debug)
435 kflag ? kvm_geterr(kvp->kd) : strerror(errno));
436 if (debug)
437 warnx("lowpc 0x%x, textsize 0x%x",
438 kvp->gpm.lowpc, kvp->gpm.textsize);
437 warnx("lowpc 0x%lx, textsize 0x%lx",
438 (unsigned long)kvp->gpm.lowpc, kvp->gpm.textsize);
439 endfrom = kvp->gpm.fromssize / sizeof(*froms);
440 for (fromindex = 0; fromindex < endfrom; ++fromindex) {
441 if (froms[fromindex] == 0)
442 continue;
443 frompc = (u_long)kvp->gpm.lowpc +
444 (fromindex * kvp->gpm.hashfraction * sizeof(*froms));
445 for (toindex = froms[fromindex]; toindex != 0;
439 endfrom = kvp->gpm.fromssize / sizeof(*froms);
440 for (fromindex = 0; fromindex < endfrom; ++fromindex) {
441 if (froms[fromindex] == 0)
442 continue;
443 frompc = (u_long)kvp->gpm.lowpc +
444 (fromindex * kvp->gpm.hashfraction * sizeof(*froms));
445 for (toindex = froms[fromindex]; toindex != 0;
446 toindex = tos[toindex].link) {
446 toindex = tos[toindex].link) {
447 if (debug)
447 if (debug)
448 warnx("[mcleanup] frompc 0x%x selfpc 0x%x count %d",
449 frompc, tos[toindex].selfpc,
450 tos[toindex].count);
448 warnx("[mcleanup] frompc 0x%lx selfpc 0x%lx "
449 "count %ld", frompc, tos[toindex].selfpc,
450 tos[toindex].count);
451 rawarc.raw_frompc = frompc;
452 rawarc.raw_selfpc = (u_long)tos[toindex].selfpc;
453 rawarc.raw_count = tos[toindex].count;
454 fwrite((char *)&rawarc, sizeof(rawarc), 1, fp);
455 }
456 }
457 fclose(fp);
458}

--- 76 unchanged lines hidden ---
451 rawarc.raw_frompc = frompc;
452 rawarc.raw_selfpc = (u_long)tos[toindex].selfpc;
453 rawarc.raw_count = tos[toindex].count;
454 fwrite((char *)&rawarc, sizeof(rawarc), 1, fp);
455 }
456 }
457 fclose(fp);
458}

--- 76 unchanged lines hidden ---