33 u32 record_size_in_cache_lines;
34 u64 file_size_in_records;
47 record_size_in_cache_lines =
51 file_size_in_records =
a->file_size_in_bytes
57 a->file_size_in_bytes = file_size_in_records * record_size_in_cache_lines
71 if (
a->maplog_is_circular)
82 for (
i = 0;
i < limit;
i++)
88 fd = open ((
char *) mm->
filenames[
i], O_CREAT | O_RDWR | O_TRUNC, 0600);
95 if (lseek (fd,
a->file_size_in_bytes - 1, SEEK_SET) == (off_t) - 1)
100 if (write (fd, &zero, 1) != 1)
107 PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
120 h->application_id =
a->application_id;
121 h->application_major_version =
a->application_major_version;
122 h->application_minor_version =
a->application_minor_version;
123 h->application_patch_version =
a->application_patch_version;
124 h->record_size_in_cachelines = record_size_in_cache_lines;
126 h->file_size_in_records = file_size_in_records;
127 h->number_of_records = ~0ULL;
128 h->number_of_files = ~0ULL;
129 h->maplog_flag_circular =
a->maplog_is_circular;
135 fd = open ((
char *) mm->
header_filename, O_CREAT | O_RDWR | O_TRUNC, 0600);
142 rv = write (fd,
h,
sizeof (*
h));
143 if (
rv !=
sizeof (*
h))
156 for (
i = 0;
i < limit;
i++)
198 (void) munmap ((
u8 *) mm->
file_baseva[unmap_index], file_size_in_bytes);
201 fd = open ((
char *) mm->
filenames[unmap_index],
202 O_CREAT | O_RDWR | O_TRUNC, 0600);
211 if (lseek (fd, file_size_in_bytes - 1, SEEK_SET) == (off_t) - 1)
216 if (write (fd, &zero, 1) != 1)
223 mmap (0, file_size_in_bytes, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
263 rv = read (fd,
h,
sizeof (*
h));
264 if (
rv !=
sizeof (*
h))
275 if (lseek (fd, 0, SEEK_SET) < 0)
281 rv = write (fd,
h,
sizeof (*
h));
282 if (
rv !=
sizeof (*
h))
302 u64 file_size_in_bytes;
316 for (
i = 0;
i < limit;
i++)
338 int verbose = va_arg (*args,
int);
342 s =
format (s,
"basename %s ",
h->file_basename);
343 s =
format (s,
"log ver %d.%d.%d app id %u ver %d.%d.%d %s %s\n",
344 h->maplog_major_version,
345 h->maplog_minor_version,
346 h->maplog_patch_version,
348 h->application_major_version,
349 h->application_minor_version,
h->application_patch_version,
350 h->maplog_flag_circular ?
"circular" :
"linear",
351 h->maplog_flag_wrapped ?
"wrapped" :
"not wrapped");
352 s =
format (s,
" records are %d %d-byte cachelines\n",
353 h->record_size_in_cachelines,
h->cacheline_size);
354 s =
format (s,
" files are %lld records long, %lld files\n",
355 h->file_size_in_records,
h->number_of_files);
356 s =
format (s,
" %lld records total\n",
h->number_of_records);
360 s =
format (s,
"%s %lld records %lld files %lld records/file",
361 h->file_basename,
h->number_of_records,
h->number_of_files,
362 h->file_size_in_records);
389 u64 file_size_in_bytes;
390 u8 *header_filename, *this_filename = 0;
393 u64 records_this_file, records_left;
398 header_filename =
format (0,
"%s_header%c", file_basename, 0);
400 fd = open ((
char *) header_filename, O_RDONLY, 0600);
407 rv = read (fd,
h,
sizeof (*
h));
408 if (
rv !=
sizeof (*
h))
417 file_size_in_bytes =
h->file_size_in_records
420 records_left =
h->number_of_records;
422 for (file_index = 0; file_index <
h->number_of_files; file_index++)
425 this_filename =
format (this_filename,
"%s_%llu%c", file_basename,
427 fd = open ((
char *) this_filename, O_RDONLY, 0600);
435 mmap (0, file_size_in_bytes, PROT_READ, MAP_SHARED, fd, 0);
438 if (file_baseva == (
u8 *) MAP_FAILED)
445 records_this_file = (records_left >
h->file_size_in_records) ?
446 h->file_size_in_records : records_left;
452 if (
h->maplog_flag_circular == 0 ||
h->maplog_flag_wrapped == 0 ||
453 ((
h->number_of_records %
h->file_size_in_records) == 0))
454 (*fp) (
h, file_baseva, records_this_file);
458 u64 first_chunk_record_index =
h->number_of_records &
459 (
h->file_size_in_records - 1);
460 u64 first_chunk_number_of_records = records_this_file -
461 first_chunk_record_index;
462 u8 *chunk_baseva = file_baseva +
463 first_chunk_record_index *
h->record_size_in_cachelines *
465 (*fp) (
h, chunk_baseva, first_chunk_number_of_records);
466 (*fp) (
h, file_baseva,
467 records_this_file - first_chunk_number_of_records);
470 if (munmap (file_baseva, file_size_in_bytes) < 0)
476 records_left -= records_this_file;
477 if (records_left == 0)