Write lockstat results to the lockstat.last file

上级 8312d2c6
...@@ -17,14 +17,21 @@ stats(void) ...@@ -17,14 +17,21 @@ stats(void)
{ {
static const u64 sz = sizeof(struct lockstat); static const u64 sz = sizeof(struct lockstat);
struct lockstat ls; struct lockstat ls;
int fd; int sfd, fd;
int r; int r;
fd = open("/dev/lockstat", O_RDONLY); fd = open("/dev/lockstat", O_RDONLY);
if (fd < 0) if (fd < 0)
die("lockstat: open failed"); die("lockstat: open failed");
unlink("/lockstat.last");
sfd = open("/lockstat.last", O_RDWR|O_CREATE);
if (sfd < 0)
die("lockstat: open failed");
printf(1, "## name acquires contends locking locked\n"); printf(1, "## name acquires contends locking locked\n");
printf(sfd, "## name acquires contends locking locked\n");
while (1) { while (1) {
r = read(fd, &ls, sz); r = read(fd, &ls, sz);
if (r < 0) if (r < 0)
...@@ -43,10 +50,15 @@ stats(void) ...@@ -43,10 +50,15 @@ stats(void)
locking += ls.cpu[i].locking; locking += ls.cpu[i].locking;
locked += ls.cpu[i].locked; locked += ls.cpu[i].locked;
} }
if (contends > 0) if (contends > 0) {
printf(1, "%s %lu %lu %lu %lu\n", printf(1, "%s %lu %lu %lu %lu\n",
ls.name, acquires, contends, locking, locked); ls.name, acquires, contends, locking, locked);
printf(sfd, "%s %lu %lu %lu %lu\n",
ls.name, acquires, contends, locking, locked);
}
} }
close(sfd);
} }
int int
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论