LLVM 24.0.0git
OutputAggregator.h
Go to the documentation of this file.
1//===- DwarfTransformer.h ---------------------------------------*- 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_DEBUGINFO_GSYM_OUTPUTAGGREGATOR_H
10#define LLVM_DEBUGINFO_GSYM_OUTPUTAGGREGATOR_H
11
12#include "llvm/ADT/StringRef.h"
14
15#include <map>
16#include <string>
17
18namespace llvm {
19
20class raw_ostream;
21
22namespace gsym {
23
25protected:
26 // A std::map is preferable over an llvm::StringMap for presenting results
27 // in a predictable order.
28 std::map<std::string, unsigned> Aggregation;
30 // Whether to suppress printing the detail messages passed to Report().
31 // Anything written through operator<< is unaffected, as is the aggregated
32 // summary.
33 bool Quiet;
34
35public:
37 : Out(out), Quiet(Quiet) {}
38
39 size_t GetNumCategories() const { return Aggregation.size(); }
40
41 bool IsQuiet() const { return Quiet; }
42
43 void Report(StringRef s, std::function<void(raw_ostream &o)> detailCallback) {
44 Aggregation[std::string(s)]++;
45 if (GetOS() && !Quiet)
46 detailCallback(*Out);
47 }
48
50 std::function<void(StringRef, unsigned)> handleCounts) const {
51 for (auto &&[name, count] : Aggregation)
52 handleCounts(name, count);
53 }
54
55 raw_ostream *GetOS() const { return Out; }
56
57 // You can just use the stream, and if it's null, nothing happens.
58 // Don't do a lot of stuff like this, but it's convenient for silly stuff.
59 // It doesn't work with things that have custom insertion operators, though.
60 template <typename T> OutputAggregator &operator<<(T &&value) {
61 if (Out != nullptr)
62 *Out << value;
63 return *this;
64 }
65
66 // For multi-threaded usage, we can collect stuff in another aggregator,
67 // then merge it in here. Note that this is *not* thread safe. It is up to
68 // the caller to ensure that this is only called from one thread at a time.
69 void Merge(const OutputAggregator &other) {
70 for (auto &&[name, count] : other.Aggregation)
72 }
73};
74
75} // namespace gsym
76} // namespace llvm
77
78#endif // LLVM_DEBUGINFO_GSYM_OUTPUTAGGREGATOR_H
#define T
static const char * name
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
void Report(StringRef s, std::function< void(raw_ostream &o)> detailCallback)
OutputAggregator(raw_ostream *out, bool Quiet=false)
OutputAggregator & operator<<(T &&value)
void EnumerateResults(std::function< void(StringRef, unsigned)> handleCounts) const
std::map< std::string, unsigned > Aggregation
raw_ostream * GetOS() const
void Merge(const OutputAggregator &other)
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
This is an optimization pass for GlobalISel generic memory operations.
auto count(R &&Range, const E &Element)
Wrapper function around std::count to count the number of times an element Element occurs in the give...
Definition STLExtras.h:2012