MCPcopy Create free account
hub / github.com/1a1a11a/libCacheSim / reader_set_read_pos

Function reader_set_read_pos

libCacheSim/traceReader/reader.c:607–632  ·  view source on GitHub ↗

* jump to given position in the trace, such as 0.2, 0.5, 1.0, etc. * because certain functions require reader to be read sequentially, * this function should not be used in the middle of reading the trace */

Source from the content-addressed store, hash-verified

605 * this function should not be used in the middle of reading the trace
606 */
607void reader_set_read_pos(reader_t *const reader, double pos) {
608 /* jason (202004): this may not work for CSV
609 */
610 if (pos > 1) pos = 1;
611
612 size_t offset = (double)reader->file_size * pos;
613 if (reader->trace_format == TXT_TRACE_FORMAT) {
614 fseek(reader->file, offset, SEEK_SET);
615 if (offset != 0 && offset != reader->file_size) {
616 go_back_one_req(reader);
617 }
618 if (offset == reader->file_size) {
619 char c;
620 fseek(reader->file, -1, SEEK_CUR);
621 int _v = fread(&c, 1, 1, reader->file);
622 while (isspace(c)) {
623 fseek(reader->file, -2, SEEK_CUR);
624 _v = fread(&c, 1, 1, reader->file);
625 DEBUG_ASSERT(_v == 1);
626 }
627 }
628 } else {
629 reader->mmap_offset = offset;
630 reader->mmap_offset -= reader->mmap_offset % reader->item_size;
631 }
632}
633
634void read_first_req(reader_t *reader, request_t *req) {
635 uint64_t offset = reader->mmap_offset;

Callers 5

test_reader_more1Function · 0.85
read_last_reqFunction · 0.85
runMethod · 0.85
convert_to_oracleGeneralFunction · 0.85
convert_to_lcsFunction · 0.85

Calls 1

go_back_one_reqFunction · 0.85

Tested by 1

test_reader_more1Function · 0.68