-
Notifications
You must be signed in to change notification settings - Fork 111
/
llvm_propeller_perf_data_provider.h
65 lines (53 loc) · 2.41 KB
/
llvm_propeller_perf_data_provider.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#ifndef AUTOFDO_LLVM_PROPELLER_PERF_DATA_PROVIDER_H_
#define AUTOFDO_LLVM_PROPELLER_PERF_DATA_PROVIDER_H_
#if defined(HAVE_LLVM)
#include <memory>
#include <optional>
#include <string>
#include <utility>
#include <vector>
#include "third_party/abseil/absl/status/statusor.h"
#include "llvm/Support/MemoryBuffer.h"
#include "base/status_macros.h"
namespace devtools_crosstool_autofdo {
// Interface for raw perf data providers. They may read preexisting perf data
// from files or collect them on the fly from currently running binaries.
class PerfDataProvider {
public:
// Handle to a potentially named memory buffer.
struct BufferHandle {
// The description of this buffer if available, e.g. the file name for
// file-based buffers, or a description of when and where the profile has
// been collected from for on-the-fly profiling. Can be used for debug
// logging, but there is no guarantee of any particular format of this field
// and especially no guarantee that the format will not change.
std::string description;
// Buffer containing the perf.data file.
std::unique_ptr<llvm::MemoryBuffer> buffer;
template <typename Sink>
friend void AbslStringify(Sink& sink, const BufferHandle& handle) {
absl::Format(&sink, "[%s]", handle.description);
}
};
virtual ~PerfDataProvider() = default;
// Returns the next perf data file, represented as an llvm::MemoryBuffer,
// so that file-based providers can mmap the file instead. If there are no
// more perf data files to be processed, returns `std::nullopt`.
virtual absl::StatusOr<std::optional<BufferHandle>> GetNext() = 0;
// Returns all perf data currently available, or the next perf data file if
// there is none available. If there are no more perf data to be processed,
// returns an empty vector. The base implementation assumes there are no
// perf data available and calls `GetNext()` to get the next profile.
virtual absl::StatusOr<std::vector<PerfDataProvider::BufferHandle>>
GetAllAvailableOrNext() {
std::vector<PerfDataProvider::BufferHandle> result = {};
ASSIGN_OR_RETURN(std::optional<BufferHandle> next, GetNext());
// If no more profiles, return the empty vector.
if (!next.has_value()) return result;
result.push_back(std::move(*next));
return result;
}
};
} // namespace devtools_crosstool_autofdo
#endif // HAVE_LLVM
#endif // AUTOFDO_LLVM_PROPELLER_PERF_DATA_PROVIDER_H_