mirror of https://github.com/ericonr/sndio.git
expose CPU usage, ie the time spent on calculations compared
to the time spend on sleeping in poll()
This commit is contained in:
parent
e9f2f3757c
commit
534383ee5c
33
aucat/file.c
33
aucat/file.c
|
@ -73,6 +73,9 @@ struct timespec file_ts;
|
||||||
struct filelist file_list;
|
struct filelist file_list;
|
||||||
struct timo *timo_queue;
|
struct timo *timo_queue;
|
||||||
unsigned timo_abstime;
|
unsigned timo_abstime;
|
||||||
|
#ifdef DEBUG
|
||||||
|
long long file_wtime, file_utime;
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* initialise a timeout structure, arguments are callback and argument
|
* initialise a timeout structure, arguments are callback and argument
|
||||||
|
@ -297,6 +300,9 @@ file_poll(void)
|
||||||
struct file *f, *fnext;
|
struct file *f, *fnext;
|
||||||
struct aproc *p;
|
struct aproc *p;
|
||||||
struct timespec ts;
|
struct timespec ts;
|
||||||
|
#ifdef DEBUG
|
||||||
|
struct timespec sleepts;
|
||||||
|
#endif
|
||||||
long long delta_nsec;
|
long long delta_nsec;
|
||||||
int res;
|
int res;
|
||||||
|
|
||||||
|
@ -346,22 +352,35 @@ file_poll(void)
|
||||||
}
|
}
|
||||||
dbg_puts("\n");
|
dbg_puts("\n");
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
#ifdef DEBUG
|
||||||
|
clock_gettime(CLOCK_MONOTONIC, &sleepts);
|
||||||
|
file_utime += 1000000000LL * (sleepts.tv_sec - file_ts.tv_sec);
|
||||||
|
file_utime += sleepts.tv_nsec - file_ts.tv_nsec;
|
||||||
#endif
|
#endif
|
||||||
res = poll(pfds, nfds, -1);
|
res = poll(pfds, nfds, -1);
|
||||||
if (res < 0 && errno != EINTR)
|
if (res < 0 && errno != EINTR)
|
||||||
err(1, "poll");
|
err(1, "poll");
|
||||||
clock_gettime(CLOCK_MONOTONIC, &ts);
|
clock_gettime(CLOCK_MONOTONIC, &ts);
|
||||||
|
#ifdef DEBUG
|
||||||
|
file_wtime += 1000000000LL * (ts.tv_sec - sleepts.tv_sec);
|
||||||
|
file_wtime += ts.tv_nsec - sleepts.tv_nsec;
|
||||||
|
#endif
|
||||||
delta_nsec = 1000000000LL * (ts.tv_sec - file_ts.tv_sec);
|
delta_nsec = 1000000000LL * (ts.tv_sec - file_ts.tv_sec);
|
||||||
delta_nsec += ts.tv_nsec - file_ts.tv_nsec;
|
delta_nsec += ts.tv_nsec - file_ts.tv_nsec;
|
||||||
if (delta_nsec > 0) {
|
|
||||||
file_ts = ts;
|
|
||||||
if (delta_nsec < 1000000000LL)
|
|
||||||
timo_update(delta_nsec / 1000);
|
|
||||||
else {
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
dbg_puts("ignored huge clock delta\n");
|
if (delta_nsec < 0) {
|
||||||
|
dbg_puts("file_poll: negative time interval\n");
|
||||||
|
dbg_panic();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
file_ts = ts;
|
||||||
|
if (delta_nsec < 1000000000LL)
|
||||||
|
timo_update(delta_nsec / 1000);
|
||||||
|
else {
|
||||||
|
#ifdef DEBUG
|
||||||
|
dbg_puts("ignored huge clock delta\n");
|
||||||
#endif
|
#endif
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (res <= 0)
|
if (res <= 0)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* $OpenBSD: file.h,v 1.10 2010/07/06 20:06:35 ratchov Exp $ */
|
/* $OpenBSD$ */
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org>
|
* Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org>
|
||||||
*
|
*
|
||||||
|
@ -69,6 +69,10 @@ LIST_HEAD(filelist,file);
|
||||||
|
|
||||||
extern struct filelist file_list;
|
extern struct filelist file_list;
|
||||||
|
|
||||||
|
#ifdef DEBUG
|
||||||
|
extern long long file_wtime, file_utime;
|
||||||
|
#endif
|
||||||
|
|
||||||
void timo_set(struct timo *, void (*)(void *), void *);
|
void timo_set(struct timo *, void (*)(void *), void *);
|
||||||
void timo_add(struct timo *, unsigned);
|
void timo_add(struct timo *, unsigned);
|
||||||
void timo_del(struct timo *);
|
void timo_del(struct timo *);
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* $OpenBSD: siofile.c,v 1.6 2010/06/04 06:15:28 ratchov Exp $ */
|
/* $OpenBSD$ */
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org>
|
* Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org>
|
||||||
*
|
*
|
||||||
|
@ -42,6 +42,9 @@ struct siofile {
|
||||||
unsigned rtickets, rbpf;
|
unsigned rtickets, rbpf;
|
||||||
unsigned bufsz;
|
unsigned bufsz;
|
||||||
int started;
|
int started;
|
||||||
|
#ifdef DEBUG
|
||||||
|
long long wtime, utime;
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
void siofile_close(struct file *);
|
void siofile_close(struct file *);
|
||||||
|
@ -173,8 +176,14 @@ siofile_cb(void *addr, int delta)
|
||||||
file_dbg(&f->file);
|
file_dbg(&f->file);
|
||||||
dbg_puts(": tick, delta = ");
|
dbg_puts(": tick, delta = ");
|
||||||
dbg_puti(delta);
|
dbg_puti(delta);
|
||||||
|
dbg_puts(", load = ");
|
||||||
|
dbg_puti((file_utime - f->utime) / 1000);
|
||||||
|
dbg_puts(" + ");
|
||||||
|
dbg_puti((file_wtime - f->wtime) / 1000);
|
||||||
dbg_puts("\n");
|
dbg_puts("\n");
|
||||||
}
|
}
|
||||||
|
f->wtime = file_wtime;
|
||||||
|
f->utime = file_utime;
|
||||||
#endif
|
#endif
|
||||||
if (delta != 0) {
|
if (delta != 0) {
|
||||||
p = f->file.wproc;
|
p = f->file.wproc;
|
||||||
|
@ -308,6 +317,8 @@ siofile_start(struct file *file)
|
||||||
f->wtickets = f->bufsz * f->wbpf;
|
f->wtickets = f->bufsz * f->wbpf;
|
||||||
f->rtickets = 0;
|
f->rtickets = 0;
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
|
f->wtime = file_wtime;
|
||||||
|
f->utime = file_utime;
|
||||||
if (debug_level >= 3) {
|
if (debug_level >= 3) {
|
||||||
file_dbg(&f->file);
|
file_dbg(&f->file);
|
||||||
dbg_puts(": started\n");
|
dbg_puts(": started\n");
|
||||||
|
|
Loading…
Reference in New Issue