34 #if defined(ENABLE_MEMSTATS)
44 volatile struct mmap_stats *mmap_stats = NULL;
45 static char mmap_fn[128];
48 mstats_open(
const char *fn)
61 if (strlen(fn) >=
sizeof(mmap_fn))
63 msg(
M_FATAL,
"mstats_open: filename too long");
67 fd = open(fn, O_CREAT | O_TRUNC | O_RDWR, S_IRUSR | S_IWUSR);
70 msg(
M_ERR,
"mstats_open: cannot open: %s", fn);
77 ms.state = MSTATS_ACTIVE;
78 stat =
write(fd, &ms,
sizeof(ms));
79 if (stat !=
sizeof(ms))
81 msg(
M_ERR,
"mstats_open: write error: %s", fn);
87 data = mmap(NULL,
sizeof(
struct mmap_stats), PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
88 if (data == MAP_FAILED)
90 msg(
M_ERR,
"mstats_open: write error: %s", fn);
98 msg(
M_ERR,
"mstats_open: close error: %s", fn);
105 mmap_stats = (
struct mmap_stats *)data;
107 msg(
M_INFO,
"memstats data will be written to %s", fn);
115 mmap_stats->state = MSTATS_EXPIRED;
116 if (munmap((
void *)mmap_stats,
sizeof(
struct mmap_stats)))