aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Boberg <[email protected]>2021-09-29 23:04:22 +0200
committerStefan Boberg <[email protected]>2021-09-29 23:04:22 +0200
commita8731fea7bff836f83b8bd82d47f14a0067ad5fe (patch)
treef4fc1fd0b06a70bd76bafaa6b0e6398fc2be46f3
parentthread: Marked some members noexcept and [[nodiscard]] (diff)
downloadzen-a8731fea7bff836f83b8bd82d47f14a0067ad5fe.tar.xz
zen-a8731fea7bff836f83b8bd82d47f14a0067ad5fe.zip
timer: cleaned up Stopwatch, removed GetCpuTimerValue
-rw-r--r--zen/chunk/chunk.cpp6
-rw-r--r--zen/cmds/copy.cpp2
-rw-r--r--zen/cmds/dedup.cpp4
-rw-r--r--zen/cmds/hash.cpp2
-rw-r--r--zencore/include/zencore/timer.h17
-rw-r--r--zencore/timer.cpp12
-rw-r--r--zenserver-test/zenserver-test.cpp12
-rw-r--r--zenserver/experimental/usnjournal.cpp2
-rw-r--r--zenserver/projectstore.cpp4
9 files changed, 20 insertions, 41 deletions
diff --git a/zen/chunk/chunk.cpp b/zen/chunk/chunk.cpp
index 18748e921..3283a8b66 100644
--- a/zen/chunk/chunk.cpp
+++ b/zen/chunk/chunk.cpp
@@ -1015,7 +1015,7 @@ ChunkCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv)
}
#endif
- uint64_t ElapsedMs = timer.getElapsedTimeMs();
+ uint64_t ElapsedMs = timer.GetElapsedTimeMs();
ReportSummary(Chunker, ElapsedMs);
}
@@ -1041,7 +1041,7 @@ ChunkCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv)
}
});
- uint64_t ElapsedMs = timer.getElapsedTimeMs();
+ uint64_t ElapsedMs = timer.GetElapsedTimeMs();
ReportSummary(Chunker, ElapsedMs);
}
@@ -1142,7 +1142,7 @@ TEST_CASE("chunking")
}
double Avg = double(BoundarySum) / BoundaryCount;
- const uint64_t ElapsedTimeMs = timer.getElapsedTimeMs();
+ const uint64_t ElapsedTimeMs = timer.GetElapsedTimeMs();
ZEN_INFO("{:9} : Avg {:9} - {:2.5} ({:6}, {})",
i,
diff --git a/zen/cmds/copy.cpp b/zen/cmds/copy.cpp
index 947d54e07..c9b40408e 100644
--- a/zen/cmds/copy.cpp
+++ b/zen/cmds/copy.cpp
@@ -91,7 +91,7 @@ CopyCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv)
CopyOptions.EnableClone = !m_NoClone;
zen::CopyFile(FromPath, ToPath, CopyOptions);
- ZEN_INFO("Copy completed in {}", zen::NiceTimeSpanMs(Timer.getElapsedTimeMs()));
+ ZEN_INFO("Copy completed in {}", zen::NiceTimeSpanMs(Timer.GetElapsedTimeMs()));
}
return 0;
diff --git a/zen/cmds/dedup.cpp b/zen/cmds/dedup.cpp
index e71314622..089212ed9 100644
--- a/zen/cmds/dedup.cpp
+++ b/zen/cmds/dedup.cpp
@@ -118,7 +118,7 @@ DedupCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv)
ZEN_INFO("Gathered {} candidates across {} size buckets. Elapsed: {}",
CandidateCount,
FileSizeMap.size(),
- zen::NiceTimeSpanMs(Timer.getElapsedTimeMs()));
+ zen::NiceTimeSpanMs(Timer.GetElapsedTimeMs()));
}
ZEN_INFO("Sorting buckets by size");
@@ -288,7 +288,7 @@ DedupCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv)
Size.DirEntries->clear();
}
- ZEN_INFO("Elapsed: {} Deduped: {}", zen::NiceTimeSpanMs(Timer.getElapsedTimeMs()), zen::NiceBytes(DupeBytes));
+ ZEN_INFO("Elapsed: {} Deduped: {}", zen::NiceTimeSpanMs(Timer.GetElapsedTimeMs()), zen::NiceBytes(DupeBytes));
return 0;
}
diff --git a/zen/cmds/hash.cpp b/zen/cmds/hash.cpp
index 0a7989ffc..7d234c2da 100644
--- a/zen/cmds/hash.cpp
+++ b/zen/cmds/hash.cpp
@@ -89,7 +89,7 @@ HashCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv)
TotalBytes.combine_each([&](size_t Total) { TotalByteCount += Total; });
- const uint64_t ElapsedMs = Timer.getElapsedTimeMs();
+ const uint64_t ElapsedMs = Timer.GetElapsedTimeMs();
ZEN_INFO("Scanned {} files in {}", FileList.size(), zen::NiceTimeSpanMs(ElapsedMs));
ZEN_INFO("Total bytes {} ({})", zen::NiceBytes(TotalByteCount), zen::NiceByteRate(TotalByteCount, ElapsedMs));
diff --git a/zencore/include/zencore/timer.h b/zencore/include/zencore/timer.h
index eb284eaee..c0f6e20ae 100644
--- a/zencore/include/zencore/timer.h
+++ b/zencore/include/zencore/timer.h
@@ -23,25 +23,16 @@ ZENCORE_API uint64_t GetHifreqTimerFrequencySafe(); // May be used during stati
class Stopwatch
{
public:
- Stopwatch() : m_StartValue(GetHifreqTimerValue()) {}
+ inline Stopwatch() : m_StartValue(GetHifreqTimerValue()) {}
- inline uint64_t getElapsedTimeMs() { return (GetHifreqTimerValue() - m_StartValue) * 1000 / GetHifreqTimerFrequency(); }
-
- inline void reset() { m_StartValue = GetHifreqTimerValue(); }
+ inline uint64_t GetElapsedTimeMs() { return (GetHifreqTimerValue() - m_StartValue) * 1'000 / GetHifreqTimerFrequency(); }
+ inline uint64_t GetElapsedTimeUs() { return (GetHifreqTimerValue() - m_StartValue) * 1'000'000 / GetHifreqTimerFrequency(); }
+ inline void Reset() { m_StartValue = GetHifreqTimerValue(); }
private:
uint64_t m_StartValue;
};
-// CPU timers
-
-inline uint64_t
-GetCpuTimerValue()
-{
- unsigned int foo;
- return __rdtscp(&foo);
-}
-
void timer_forcelink(); // internal
} // namespace zen
diff --git a/zencore/timer.cpp b/zencore/timer.cpp
index 88ec89cb7..b2c6cb6a2 100644
--- a/zencore/timer.cpp
+++ b/zencore/timer.cpp
@@ -73,18 +73,6 @@ timer_forcelink()
{
}
-TEST_CASE("Timer")
-{
- uint64_t s0 = GetHifreqTimerValue();
- uint64_t t0 = GetCpuTimerValue();
- zen::Sleep(1000);
- uint64_t s1 = GetHifreqTimerValue();
- uint64_t t1 = GetCpuTimerValue();
- // double r = double(t1 - t0) / (s1 - s0);
- CHECK_NE(t0, t1);
- CHECK_NE(s0, s1);
-}
-
#endif
} // namespace zen
diff --git a/zenserver-test/zenserver-test.cpp b/zenserver-test/zenserver-test.cpp
index 6461b76c2..0e5e73ffc 100644
--- a/zenserver-test/zenserver-test.cpp
+++ b/zenserver-test/zenserver-test.cpp
@@ -645,8 +645,8 @@ main()
ZEN_INFO("{} requests in {} ({})",
RequestCount,
- zen::NiceTimeSpanMs(timer.getElapsedTimeMs()),
- zen::NiceRate(RequestCount, (uint32_t)timer.getElapsedTimeMs(), "req"));
+ zen::NiceTimeSpanMs(timer.GetElapsedTimeMs()),
+ zen::NiceRate(RequestCount, (uint32_t)timer.GetElapsedTimeMs(), "req"));
return 0;
}
@@ -775,7 +775,7 @@ TEST_CASE("default.single")
IssueTestRequests,
IssueTestRequests);
- uint64_t Elapsed = timer.getElapsedTimeMs();
+ uint64_t Elapsed = timer.GetElapsedTimeMs();
ZEN_INFO("{} requests in {} ({})", RequestCount, zen::NiceTimeSpanMs(Elapsed), zen::NiceRate(RequestCount, (uint32_t)Elapsed, "req"));
}
@@ -826,7 +826,7 @@ TEST_CASE("multi.basic")
[&] { IssueTestRequests(13337); },
[&] { IssueTestRequests(13338); });
- uint64_t Elapsed = timer.getElapsedTimeMs();
+ uint64_t Elapsed = timer.GetElapsedTimeMs();
ZEN_INFO("{} requests in {} ({})", RequestCount, zen::NiceTimeSpanMs(Elapsed), zen::NiceRate(RequestCount, (uint32_t)Elapsed, "req"));
}
@@ -899,7 +899,7 @@ TEST_CASE("cas.basic")
++RequestCount;
}
- uint64_t Elapsed = timer.getElapsedTimeMs();
+ uint64_t Elapsed = timer.GetElapsedTimeMs();
ZEN_INFO("{} requests in {} ({})",
RequestCount,
@@ -1074,7 +1074,7 @@ TEST_CASE("project.basic")
SUBCASE("build store op commit") { ZEN_INFO("-------"); }
}
- const uint64_t Elapsed = timer.getElapsedTimeMs();
+ const uint64_t Elapsed = timer.GetElapsedTimeMs();
ZEN_INFO("{} requests in {} ({})", RequestCount, zen::NiceTimeSpanMs(Elapsed), zen::NiceRate(RequestCount, (uint32_t)Elapsed, "req"));
}
diff --git a/zenserver/experimental/usnjournal.cpp b/zenserver/experimental/usnjournal.cpp
index 1e765fbe5..d575e1779 100644
--- a/zenserver/experimental/usnjournal.cpp
+++ b/zenserver/experimental/usnjournal.cpp
@@ -259,7 +259,7 @@ UsnJournalReader::Initialize(std::filesystem::path VolumePath)
}
}
- const auto ElapsedMs = Timer.getElapsedTimeMs();
+ const auto ElapsedMs = Timer.GetElapsedTimeMs();
ZEN_INFO("MFT enumeration of {} completed after {} ({})",
zen::NiceBytes(MftBytesProcessed),
diff --git a/zenserver/projectstore.cpp b/zenserver/projectstore.cpp
index 1a9eb2c67..7870f9559 100644
--- a/zenserver/projectstore.cpp
+++ b/zenserver/projectstore.cpp
@@ -191,7 +191,7 @@ struct ProjectStore::OplogStorage : public RefCounted
});
ZEN_INFO("Oplog replay completed in {} - Max LSN# {}, Next offset: {}",
- NiceTimeSpanMs(Timer.getElapsedTimeMs()),
+ NiceTimeSpanMs(Timer.GetElapsedTimeMs()),
m_MaxLsn,
m_NextOpsOffset);
}
@@ -502,7 +502,7 @@ ProjectStore::Oplog::RegisterOplogEntry(CbObject Core, const OplogEntry& OpEntry
}
}
- ZEN_DEBUG("added {} file(s) in {}", FileCount, NiceTimeSpanMs(Timer.getElapsedTimeMs()));
+ ZEN_DEBUG("added {} file(s) in {}", FileCount, NiceTimeSpanMs(Timer.GetElapsedTimeMs()));
}
for (CbFieldView& Entry : Core["meta"sv])