diff --git a/velox/common/file/FileInputStream.cpp b/velox/common/file/FileInputStream.cpp index 73fdb2692c24..e680733c637b 100644 --- a/velox/common/file/FileInputStream.cpp +++ b/velox/common/file/FileInputStream.cpp @@ -56,9 +56,9 @@ void FileInputStream::readNextRange() { current_ = nullptr; int32_t readBytes{0}; - uint64_t readTimeUs{0}; + uint64_t readTimeNs{0}; { - MicrosecondTimer timer{&readTimeUs}; + NanosecondTimer timer{&readTimeNs}; if (readAheadWait_.valid()) { readBytes = std::move(readAheadWait_) .via(&folly::QueuedImmediateExecutor::instance()) @@ -72,7 +72,7 @@ void FileInputStream::readNextRange() { readBytes = readSize(); VELOX_CHECK_LT( 0, readBytes, "Read past end of FileInputStream {}", fileSize_); - MicrosecondTimer timer{&readTimeUs}; + NanosecondTimer timer{&readTimeNs}; file_->pread(fileOffset_, readBytes, buffer()->asMutable()); } } @@ -82,7 +82,7 @@ void FileInputStream::readNextRange() { current_ = ranges_.data(); fileOffset_ += readBytes; - updateStats(readBytes, readTimeUs); + updateStats(readBytes, readTimeNs); maybeIssueReadahead(); } @@ -222,9 +222,9 @@ void FileInputStream::maybeIssueReadahead() { VELOX_CHECK(readAheadWait_.valid()); } -void FileInputStream::updateStats(uint64_t readBytes, uint64_t readTimeUs) { +void FileInputStream::updateStats(uint64_t readBytes, uint64_t readTimeNs) { stats_.readBytes += readBytes; - stats_.readTimeUs += readTimeUs; + stats_.readTimeNs += readTimeNs; ++stats_.numReads; } @@ -243,15 +243,15 @@ FileInputStream::Stats FileInputStream::stats() const { bool FileInputStream::Stats::operator==( const FileInputStream::Stats& other) const { - return std::tie(numReads, readBytes, readTimeUs) == - std::tie(other.numReads, other.readBytes, other.readTimeUs); + return std::tie(numReads, readBytes, readTimeNs) == + std::tie(other.numReads, other.readBytes, other.readTimeNs); } std::string FileInputStream::Stats::toString() const { return fmt::format( - "numReads: {}, readBytes: {}, readTimeUs: {}", + "numReads: {}, readBytes: {}, readTimeNs: {}", numReads, succinctBytes(readBytes), - succinctMicros(readTimeUs)); + succinctMicros(readTimeNs)); } } // namespace facebook::velox::common diff --git a/velox/common/file/FileInputStream.h b/velox/common/file/FileInputStream.h index 4d9b7d83b9ac..6daf9f84e109 100644 --- a/velox/common/file/FileInputStream.h +++ b/velox/common/file/FileInputStream.h @@ -63,7 +63,7 @@ class FileInputStream : public ByteInputStream { struct Stats { uint32_t numReads{0}; uint64_t readBytes{0}; - uint64_t readTimeUs{0}; + uint64_t readTimeNs{0}; bool operator==(const Stats& other) const; @@ -106,7 +106,7 @@ class FileInputStream : public ByteInputStream { return buffers_[nextBufferIndex()].get(); } - void updateStats(uint64_t readBytes, uint64_t readTimeUs); + void updateStats(uint64_t readBytes, uint64_t readTimeNs); const std::unique_ptr file_; const uint64_t fileSize_; diff --git a/velox/common/file/tests/FileInputStreamTest.cpp b/velox/common/file/tests/FileInputStreamTest.cpp index 74cf27de55e0..18ab5733900e 100644 --- a/velox/common/file/tests/FileInputStreamTest.cpp +++ b/velox/common/file/tests/FileInputStreamTest.cpp @@ -96,7 +96,7 @@ TEST_F(FileInputStreamTest, stats) { ASSERT_EQ( byteStream->stats().readBytes, std::min(testData.streamSize, testData.bufferSize)); - ASSERT_GE(byteStream->stats().readTimeUs, 0); + ASSERT_GT(byteStream->stats().readTimeNs, 0); uint8_t buffer[testData.streamSize / 8]; for (int offset = 0; offset < testData.streamSize;) { byteStream->readBytes(buffer, testData.streamSize / 8); @@ -110,6 +110,6 @@ TEST_F(FileInputStreamTest, stats) { bits::roundUp(testData.streamSize, testData.bufferSize) / testData.bufferSize); ASSERT_EQ(byteStream->stats().readBytes, testData.streamSize); - ASSERT_GE(byteStream->stats().readTimeUs, 0); + ASSERT_GT(byteStream->stats().readTimeNs, 0); } } diff --git a/velox/exec/SpillFile.cpp b/velox/exec/SpillFile.cpp index 8aaf6a2f86d5..0d16005b20f4 100644 --- a/velox/exec/SpillFile.cpp +++ b/velox/exec/SpillFile.cpp @@ -328,13 +328,10 @@ void SpillReadFile::recordSpillStats() { VELOX_CHECK(input_->atEnd()); const auto readStats = input_->stats(); common::updateGlobalSpillReadStats( - readStats.numReads, - readStats.readBytes, - readStats.readTimeUs * Timestamp::kNanosecondsInMicrosecond); + readStats.numReads, readStats.readBytes, readStats.readTimeNs); auto lockedSpillStats = stats_->wlock(); lockedSpillStats->spillReads += readStats.numReads; - lockedSpillStats->spillReadTimeNanos += - readStats.readTimeUs * Timestamp::kNanosecondsInMicrosecond; + lockedSpillStats->spillReadTimeNanos += readStats.readTimeNs; lockedSpillStats->spillReadBytes += readStats.readBytes; } } // namespace facebook::velox::exec