Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/include/llvm/Support/TimeProfiler.h
Line
Count
Source
1
//===- llvm/Support/TimeProfiler.h - Hierarchical Time Profiler -*- C++ -*-===//
2
//
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
// See https://llvm.org/LICENSE.txt for license information.
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
//
7
//===----------------------------------------------------------------------===//
8
9
#ifndef LLVM_SUPPORT_TIME_PROFILER_H
10
#define LLVM_SUPPORT_TIME_PROFILER_H
11
12
#include "llvm/Support/raw_ostream.h"
13
14
namespace llvm {
15
16
struct TimeTraceProfiler;
17
extern TimeTraceProfiler *TimeTraceProfilerInstance;
18
19
/// Initialize the time trace profiler.
20
/// This sets up the global \p TimeTraceProfilerInstance
21
/// variable to be the profiler instance.
22
void timeTraceProfilerInitialize();
23
24
/// Cleanup the time trace profiler, if it was initialized.
25
void timeTraceProfilerCleanup();
26
27
/// Is the time trace profiler enabled, i.e. initialized?
28
991k
inline bool timeTraceProfilerEnabled() {
29
991k
  return TimeTraceProfilerInstance != nullptr;
30
991k
}
31
32
/// Write profiling data to output file.
33
/// Data produced is JSON, in Chrome "Trace Event" format, see
34
/// https://docs.google.com/document/d/1CvAClvFfyA5R-PhYUmn5OOQtYMH4h6I0nSsKchNAySU/preview
35
void timeTraceProfilerWrite(raw_pwrite_stream &OS);
36
37
/// Manually begin a time section, with the given \p Name and \p Detail.
38
/// Profiler copies the string data, so the pointers can be given into
39
/// temporaries. Time sections can be hierarchical; every Begin must have a
40
/// matching End pair but they can nest.
41
void timeTraceProfilerBegin(StringRef Name, StringRef Detail);
42
void timeTraceProfilerBegin(StringRef Name,
43
                            llvm::function_ref<std::string()> Detail);
44
45
/// Manually end the last time section.
46
void timeTraceProfilerEnd();
47
48
/// The TimeTraceScope is a helper class to call the begin and end functions
49
/// of the time trace profiler.  When the object is constructed, it begins
50
/// the section; and when it is destroyed, it stops it. If the time profiler
51
/// is not initialized, the overhead is a single branch.
52
struct TimeTraceScope {
53
54
  TimeTraceScope() = delete;
55
  TimeTraceScope(const TimeTraceScope &) = delete;
56
  TimeTraceScope &operator=(const TimeTraceScope &) = delete;
57
  TimeTraceScope(TimeTraceScope &&) = delete;
58
  TimeTraceScope &operator=(TimeTraceScope &&) = delete;
59
60
175M
  TimeTraceScope(StringRef Name, StringRef Detail) {
61
175M
    if (TimeTraceProfilerInstance != nullptr)
62
60
      timeTraceProfilerBegin(Name, Detail);
63
175M
  }
64
3.29M
  TimeTraceScope(StringRef Name, llvm::function_ref<std::string()> Detail) {
65
3.29M
    if (TimeTraceProfilerInstance != nullptr)
66
3
      timeTraceProfilerBegin(Name, Detail);
67
3.29M
  }
68
178M
  ~TimeTraceScope() {
69
178M
    if (TimeTraceProfilerInstance != nullptr)
70
63
      timeTraceProfilerEnd();
71
178M
  }
72
};
73
74
} // end namespace llvm
75
76
#endif