Skip to content

Commit

Permalink
Fixed issue #36 regarding negative timestamps
Browse files Browse the repository at this point in the history
Previously, the decompressor would output negative timestamps when it
encountered a log message with a timestamp earlier than the conversion
time marked in the log file's checkpoint. This patch fixes this issue
by checking for this case and adjusting the output as necessary.
  • Loading branch information
syang0 committed Jul 17, 2020
1 parent 4d1afc8 commit c5618cf
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
10 changes: 9 additions & 1 deletion runtime/Log.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (c) 2017-2018 Stanford University
/* Copyright (c) 2017-2020 Stanford University
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
Expand Down Expand Up @@ -1352,6 +1352,14 @@ Log::Decoder::BufferFragment::decompressNextLogStatement(FILE *outputFd,
int64_t wholeSeconds = static_cast<int64_t>(secondsSinceCheckpoint);
nanos = 1.0e9 * (secondsSinceCheckpoint
- static_cast<double>(wholeSeconds));

// If the timestamp occurred before the checkpoint, we may have to
// adjust the times so that nanos remains positive.
if (nanos < 0.0) {
wholeSeconds--;
nanos += 1.0e9;
}

std::time_t absTime = wholeSeconds + checkpoint.unixTime;
std::tm *tm = localtime(&absTime);
strftime(timeString, sizeof(timeString), "%Y-%m-%d %H:%M:%S", tm);
Expand Down
6 changes: 3 additions & 3 deletions runtime/LogTest.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (c) 2016-2018 Stanford University
/* Copyright (c) 2016-2020 Stanford University
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
Expand Down Expand Up @@ -1918,7 +1918,7 @@ TEST_F(LogTest, Decoder_decompressNextLogStatement_timeTravel) {
LogMessage logMsg;

UncompressedEntry* ue = reinterpret_cast<UncompressedEntry*>(inputBuffer);
ue->timestamp = 10e9;
ue->timestamp = 10e9 + 1;
ue->fmtId = noParamsId;
ue->entrySize = sizeof(UncompressedEntry);

Expand Down Expand Up @@ -1959,7 +1959,7 @@ TEST_F(LogTest, Decoder_decompressNextLogStatement_timeTravel) {
ASSERT_TRUE(iFile.good());

const char* expectedLines[] = {
"1969-12-31 16:00:20.000000000 testHelper/client.cc:20 NOTICE[1]: Simple log message with 0 parameters\r"
"1969-12-31 16:00:20.000000001 testHelper/client.cc:20 NOTICE[1]: Simple log message with 0 parameters\r"
};

std::string iLine;
Expand Down

0 comments on commit c5618cf

Please sign in to comment.