Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/lib/libc/gmon - KNF
details: https://anonhg.NetBSD.org/src/rev/e372beb926ac
branches: trunk
changeset: 752583:e372beb926ac
user: christos <christos%NetBSD.org@localhost>
date: Mon Mar 01 19:52:38 2010 +0000
description:
- KNF
- fix hertz()
- fix error and warning messages
diffstat:
lib/libc/gmon/gmon.c | 95 +++++++++++++++++++++++++++++----------------------
1 files changed, 54 insertions(+), 41 deletions(-)
diffs (203 lines):
diff -r dce2be95c795 -r e372beb926ac lib/libc/gmon/gmon.c
--- a/lib/libc/gmon/gmon.c Mon Mar 01 19:12:49 2010 +0000
+++ b/lib/libc/gmon/gmon.c Mon Mar 01 19:52:38 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: gmon.c,v 1.31 2010/01/17 23:09:02 wiz Exp $ */
+/* $NetBSD: gmon.c,v 1.32 2010/03/01 19:52:38 christos Exp $ */
/*
* Copyright (c) 2003, 2004 Wasabi Systems, Inc.
@@ -69,7 +69,7 @@
#if 0
static char sccsid[] = "@(#)gmon.c 8.1 (Berkeley) 6/4/93";
#else
-__RCSID("$NetBSD: gmon.c,v 1.31 2010/01/17 23:09:02 wiz Exp $");
+__RCSID("$NetBSD: gmon.c,v 1.32 2010/03/01 19:52:38 christos Exp $");
#endif
#endif
@@ -104,24 +104,21 @@
/* see profil(2) where this is describe (incorrectly) */
#define SCALE_1_TO_1 0x10000L
-#define ERR(s) write(STDERR_FILENO, s, sizeof(s))
-
-void moncontrol __P((int));
-void monstartup __P((u_long, u_long));
-void _mcleanup __P((void));
-static int hertz __P((void));
+void moncontrol(int);
+void monstartup(u_long, u_long);
+void _mcleanup(void);
+static int hertz(void);
#ifdef _REENTRANT
static void _m_gmon_destructor(void *);
-struct gmonparam *_m_gmon_alloc(void) __attribute__((__no_instrument_function__));
+struct gmonparam *_m_gmon_alloc(void)
+ __attribute__((__no_instrument_function__));
static void _m_gmon_merge(void);
static void _m_gmon_merge_two(struct gmonparam *, struct gmonparam *);
#endif
void
-monstartup(lowpc, highpc)
- u_long lowpc;
- u_long highpc;
+monstartup(u_long lowpc, u_long highpc)
{
u_long o;
char *cp;
@@ -146,11 +143,11 @@
cp = sbrk((intptr_t)(p->kcountsize + p->fromssize + p->tossize));
if (cp == (char *)-1) {
- ERR("monstartup: out of memory\n");
+ warnx("%s: out of memory", __func__);
return;
}
#ifdef notdef
- memset(cp, 0, p->kcountsize + p->fromssize + p->tossize);
+ (void)memset(cp, 0, p->kcountsize + p->fromssize + p->tossize);
#endif
p->tos = (struct tostruct *)(void *)cp;
cp += (size_t)p->tossize;
@@ -350,10 +347,12 @@
mutex_lock(&_gmonlock);
- for (q = _gmonfree; q != NULL; q = (struct gmonparam *)(void *)q->kcount)
+ for (q = _gmonfree; q != NULL;
+ q = (struct gmonparam *)(void *)q->kcount)
_m_gmon_merge_two(&_gmonparam, q);
- for (q = _gmoninuse; q != NULL; q = (struct gmonparam *)(void *)q->kcount) {
+ for (q = _gmoninuse; q != NULL;
+ q = (struct gmonparam *)(void *)q->kcount) {
q->state = GMON_PROF_OFF;
_m_gmon_merge_two(&_gmonparam, q);
}
@@ -363,7 +362,7 @@
#endif
void
-_mcleanup()
+_mcleanup(void)
{
int fd;
int fromindex;
@@ -390,13 +389,13 @@
* our real one.
*/
if (issetugid() && (geteuid() != getuid() || getegid() != getgid())) {
- warnx("mcount: Profiling of set{u,g}id binaries is not"
- " allowed");
+ warnx("%s: Profiling of set{u,g}id binaries is not"
+ " allowed", __func__);
return;
}
if (p->state == GMON_PROF_ERROR)
- ERR("_mcleanup: tos overflow\n");
+ warnx("%s: tos overflow", __func__);
size = sizeof(clockinfo);
mib[0] = CTL_KERN;
@@ -422,8 +421,9 @@
return;
if (snprintf(buf, sizeof buf, "%s/%d.%s",
- profdir, getpid(), getprogname()) >= (int)(sizeof buf)) {
- warnx("_mcleanup: internal buffer overflow, PROFDIR too long");
+ profdir, getpid(), getprogname()) >= (int)(sizeof buf)) {
+ warnx("%s: internal buffer overflow, PROFDIR too long",
+ __func__);
return;
}
@@ -434,13 +434,13 @@
fd = open(proffile , O_CREAT|O_TRUNC|O_WRONLY, 0666);
if (fd < 0) {
- warn("mcount: Cannot open `%s'", proffile);
+ warn("%s: Cannot open `%s'", __func__, proffile);
return;
}
#ifdef DEBUG
logfd = open("gmon.log", O_CREAT|O_TRUNC|O_WRONLY, 0664);
if (logfd < 0) {
- warn("mcount: Cannot open `gmon.log'");
+ warn("%s: Cannot open `%s'", __func__, "gmon.log");
return;
}
len = snprintf(buf2, sizeof buf2, "[mcleanup1] kcount %p ssiz %lu\n",
@@ -477,12 +477,12 @@
rawarc.raw_frompc = frompc;
rawarc.raw_selfpc = p->tos[toindex].selfpc;
rawarc.raw_count = p->tos[toindex].count;
- write(fd, &rawarc, sizeof rawarc);
+ (void)write(fd, &rawarc, sizeof rawarc);
}
}
- close(fd);
+ (void)close(fd);
#ifdef DEBUG
- close(logfd);
+ (void)close(logfd);
#endif
}
@@ -492,8 +492,7 @@
* all the data structures are ready.
*/
void
-moncontrol(mode)
- int mode;
+moncontrol(int mode)
{
struct gmonparam *p = &_gmonparam;
@@ -514,17 +513,31 @@
* if something goes wrong, we return 0, an impossible hertz.
*/
static int
-hertz()
+hertz(void)
{
- struct itimerval tim;
-
- tim.it_interval.tv_sec = 0;
- tim.it_interval.tv_usec = 1;
- tim.it_value.tv_sec = 0;
- tim.it_value.tv_usec = 0;
- setitimer(ITIMER_REAL, &tim, 0);
- setitimer(ITIMER_REAL, 0, &tim);
- if (tim.it_interval.tv_usec < 2)
- return(0);
- return (int)(1000000 / tim.it_interval.tv_usec);
+ struct itimerspec tim;
+ timer_t t;
+ int rv = 0;
+
+ tim.it_interval.tv_sec = 0;
+ tim.it_interval.tv_nsec = 1;
+ tim.it_value.tv_sec = 0;
+ tim.it_value.tv_nsec = 0;
+
+ if (timer_create(CLOCK_REALTIME, NULL, &t) == -1)
+ return 0;
+
+ if (timer_settime(t, 0, &tim, NULL) == -1)
+ goto out;
+
+ if (timer_gettime(t, &tim) == -1)
+ goto out;
+
+ if (tim.it_interval.tv_nsec < 2)
+ goto out;
+
+ rv = (int)(1000000000LL / tim.it_interval.tv_nsec);
+out:
+ (void)timer_delete(t);
+ return rv;
}
Home |
Main Index |
Thread Index |
Old Index