33#if defined(ENABLE_MEMSTATS)
43volatile struct mmap_stats *mmap_stats = NULL;
44static char mmap_fn[128];
47mstats_open(
const char *fn)
60 if (strlen(fn) >=
sizeof(mmap_fn))
62 msg(
M_FATAL,
"mstats_open: filename too long");
66 fd = open(fn, O_CREAT | O_TRUNC | O_RDWR, S_IRUSR | S_IWUSR);
69 msg(
M_ERR,
"mstats_open: cannot open: %s", fn);
76 ms.state = MSTATS_ACTIVE;
77 stat =
write(fd, &ms,
sizeof(ms));
78 if (stat !=
sizeof(ms))
80 msg(
M_ERR,
"mstats_open: write error: %s", fn);
86 data = mmap(NULL,
sizeof(
struct mmap_stats), PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
87 if (data == MAP_FAILED)
89 msg(
M_ERR,
"mstats_open: write error: %s", fn);
97 msg(
M_ERR,
"mstats_open: close error: %s", fn);
104 mmap_stats = (
struct mmap_stats *)data;
106 msg(
M_INFO,
"memstats data will be written to %s", fn);
114 mmap_stats->state = MSTATS_EXPIRED;
115 if (munmap((
void *)mmap_stats,
sizeof(
struct mmap_stats)))