[PATCH] D70904: Tidy-ups to TimeProfiler.cpp [NFC]

Russell Gallop via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 2 07:04:33 PST 2019


russell.gallop created this revision.
russell.gallop added a reviewer: anton-afanasyev.
Herald added a subscriber: hiraditya.
Herald added a project: LLVM.

This patch has a few changes to the time trace profiler which I made working towards implementing LLD time-trace (https://reviews.llvm.org/D69043). Not strictly required, just small tidying up changes. Putting as separate patch to avoid the main patch being too big.

  Remove unused include
  Make member variables const where possible
  Move initialisation to initializer list

Should be NFC.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D70904

Files:
  llvm/lib/Support/TimeProfiler.cpp


Index: llvm/lib/Support/TimeProfiler.cpp
===================================================================
--- llvm/lib/Support/TimeProfiler.cpp
+++ llvm/lib/Support/TimeProfiler.cpp
@@ -13,7 +13,6 @@
 #include "llvm/Support/TimeProfiler.h"
 #include "llvm/ADT/StringMap.h"
 #include "llvm/Support/CommandLine.h"
-#include "llvm/Support/FileSystem.h"
 #include "llvm/Support/JSON.h"
 #include <cassert>
 #include <chrono>
@@ -33,14 +32,14 @@
     NameAndCountAndDurationType;
 
 struct Entry {
-  TimePointType Start;
+  const TimePointType Start;
   TimePointType End;
-  std::string Name;
-  std::string Detail;
+  const std::string Name;
+  const std::string Detail;
 
   Entry(TimePointType &&S, TimePointType &&E, std::string &&N, std::string &&Dt)
       : Start(std::move(S)), End(std::move(E)), Name(std::move(N)),
-        Detail(std::move(Dt)){};
+        Detail(std::move(Dt)){}
 
   // Calculate timings for FlameGraph. Cast time points to microsecond precision
   // rather than casting duration. This avoid truncation issues causing inner
@@ -60,9 +59,8 @@
 
 struct TimeTraceProfiler {
   TimeTraceProfiler(unsigned TimeTraceGranularity = 0)
-      : TimeTraceGranularity(TimeTraceGranularity) {
-    StartTime = steady_clock::now();
-  }
+      : StartTime(steady_clock::now()),
+        TimeTraceGranularity(TimeTraceGranularity) {}
 
   void begin(std::string Name, llvm::function_ref<std::string()> Detail) {
     Stack.emplace_back(steady_clock::now(), TimePointType(), std::move(Name),
@@ -180,10 +178,10 @@
   SmallVector<Entry, 16> Stack;
   SmallVector<Entry, 128> Entries;
   StringMap<CountAndDurationType> CountAndTotalPerName;
-  TimePointType StartTime;
+  const TimePointType StartTime;
 
   // Minimum time granularity (in microseconds)
-  unsigned TimeTraceGranularity;
+  const unsigned TimeTraceGranularity;
 };
 
 void timeTraceProfilerInitialize(unsigned TimeTraceGranularity) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D70904.231703.patch
Type: text/x-patch
Size: 1917 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191202/7036f51d/attachment.bin>


More information about the llvm-commits mailing list