clang 22.0.0git
EntryPointStats.h
Go to the documentation of this file.
1// EntryPointStats.h - Tracking statistics per entry point ------*- 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 CLANG_INCLUDE_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_ENTRYPOINTSTATS_H
10#define CLANG_INCLUDE_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_ENTRYPOINTSTATS_H
11
13#include "llvm/ADT/Statistic.h"
14#include "llvm/ADT/StringRef.h"
15
16namespace llvm {
17class raw_ostream;
18} // namespace llvm
19
20namespace clang {
21class Decl;
22
23namespace ento {
24
26public:
27 llvm::StringLiteral name() const { return Name; }
28
29 static void lockRegistry(llvm::StringRef CPPFileName, ASTContext &Ctx);
30
31 static void takeSnapshot(const Decl *EntryPoint);
32 static void dumpStatsAsCSV(llvm::raw_ostream &OS);
33 static void dumpStatsAsCSV(llvm::StringRef FileName);
34
35protected:
36 explicit EntryPointStat(llvm::StringLiteral Name) : Name{Name} {}
37 EntryPointStat(const EntryPointStat &) = delete;
41
42private:
43 llvm::StringLiteral Name;
44};
45
46// used by CounterEntryPointTranslationUnitStat
47class CounterEPStat : public EntryPointStat {
49 unsigned Value = {};
50
51public:
52 explicit CounterEPStat(llvm::StringLiteral Name);
53 unsigned value() const { return Value; }
54 void reset() { Value = {}; }
56 ++Value;
57 return *this;
58 }
59
61 // No difference as you can't extract the value
62 return ++(*this);
63 }
64
65 CounterEPStat &operator+=(unsigned Inc) {
66 Value += Inc;
67 return *this;
68 }
69};
70
71// used by UnsignedMaxEtryPointTranslationUnitStatistic
72class UnsignedMaxEPStat : public EntryPointStat {
74 unsigned Value = {};
75
76public:
77 explicit UnsignedMaxEPStat(llvm::StringLiteral Name);
78 unsigned value() const { return Value; }
79 void reset() { Value = {}; }
80 void updateMax(unsigned X) { Value = std::max(Value, X); }
81};
82
83class UnsignedEPStat : public EntryPointStat {
85 std::optional<unsigned> Value = {};
86
87public:
88 explicit UnsignedEPStat(llvm::StringLiteral Name);
89 std::optional<unsigned> value() const { return Value; }
90 void reset() { Value.reset(); }
91 void set(unsigned V) {
92 assert(!Value.has_value());
93 Value = V;
94 }
95};
96
99 llvm::TrackingStatistic S;
100
101public:
103 llvm::StringLiteral Name,
104 llvm::StringLiteral Desc)
105 : M(Name), S(DebugType, Name.data(), Desc.data()) {}
107 ++M;
108 ++S;
109 return *this;
110 }
111
113 // No difference with prefix as the value is not observable.
114 return ++(*this);
115 }
116
118 M += Inc;
119 S += Inc;
120 return *this;
121 }
122};
123
126 llvm::TrackingStatistic S;
127
128public:
130 llvm::StringLiteral Name,
131 llvm::StringLiteral Desc)
132 : M(Name), S(DebugType, Name.data(), Desc.data()) {}
133 void updateMax(uint64_t Value) {
134 M.updateMax(static_cast<unsigned>(Value));
135 S.updateMax(Value);
136 }
137};
138
139#define STAT_COUNTER(VARNAME, DESC) \
140 static clang::ento::CounterEntryPointTranslationUnitStat VARNAME = { \
141 DEBUG_TYPE, #VARNAME, DESC}
142
143#define STAT_MAX(VARNAME, DESC) \
144 static clang::ento::UnsignedMaxEntryPointTranslationUnitStatistic VARNAME = \
145 {DEBUG_TYPE, #VARNAME, DESC}
146
147} // namespace ento
148} // namespace clang
149
150#endif // CLANG_INCLUDE_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_ENTRYPOINTSTATS_H
Defines the clang::ASTContext interface.
#define V(N, I)
#define X(type, name)
Definition Value.h:97
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition ASTContext.h:220
Decl - This represents one declaration (or definition), e.g.
Definition DeclBase.h:86
CounterEPStat & operator++()
CounterEPStat & operator++(int)
CounterEPStat & operator+=(unsigned Inc)
CounterEPStat(llvm::StringLiteral Name)
CounterEntryPointTranslationUnitStat & operator++(int)
CounterEntryPointTranslationUnitStat & operator+=(unsigned Inc)
CounterEntryPointTranslationUnitStat & operator++()
CounterEntryPointTranslationUnitStat(const char *DebugType, llvm::StringLiteral Name, llvm::StringLiteral Desc)
static void dumpStatsAsCSV(llvm::raw_ostream &OS)
static void lockRegistry(llvm::StringRef CPPFileName, ASTContext &Ctx)
EntryPointStat & operator=(EntryPointStat &)=delete
EntryPointStat & operator=(EntryPointStat &&)=delete
static void takeSnapshot(const Decl *EntryPoint)
llvm::StringLiteral name() const
EntryPointStat(llvm::StringLiteral Name)
EntryPointStat(const EntryPointStat &)=delete
EntryPointStat(EntryPointStat &&)=delete
UnsignedEPStat(llvm::StringLiteral Name)
std::optional< unsigned > value() const
UnsignedMaxEPStat(llvm::StringLiteral Name)
UnsignedMaxEntryPointTranslationUnitStatistic(const char *DebugType, llvm::StringLiteral Name, llvm::StringLiteral Desc)
@ OS
Indicates that the tracking object is a descendant of a referenced-counted OSObject,...
The JSON file list parser is used to communicate input to InstallAPI.
Diagnostic wrappers for TextAPI types for error reporting.
Definition Dominators.h:30