blob: 46a7243685fa358e3941d7c8a998aabe33d1b0d0 [file] [log] [blame]
Andrew Scull0372a572018-11-16 15:47:06 +00001//===- BlockIndexer.h - FDR Block Indexing Visitor ------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// An implementation of the RecordVisitor which generates a mapping between a
11// thread and a range of records representing a block.
12//
13//===----------------------------------------------------------------------===//
14#ifndef LLVM_LIB_XRAY_BLOCKINDEXER_H_
15#define LLVM_LIB_XRAY_BLOCKINDEXER_H_
16
17#include "llvm/ADT/DenseMap.h"
18#include "llvm/XRay/FDRRecords.h"
19#include <cstdint>
20#include <vector>
21
22namespace llvm {
23namespace xray {
24
25// The BlockIndexer will gather all related records associated with a
26// process+thread and group them by 'Block'.
27class BlockIndexer : public RecordVisitor {
28public:
29 struct Block {
30 uint64_t ProcessID;
31 int32_t ThreadID;
32 WallclockRecord *WallclockTime;
33 std::vector<Record *> Records;
34 };
35
36 // This maps the process + thread combination to a sequence of blocks.
37 using Index = DenseMap<std::pair<uint64_t, int32_t>, std::vector<Block>>;
38
39private:
40 Index &Indices;
41
42 Block CurrentBlock{0, 0, nullptr, {}};
43
44public:
45 explicit BlockIndexer(Index &I) : RecordVisitor(), Indices(I) {}
46
47 Error visit(BufferExtents &) override;
48 Error visit(WallclockRecord &) override;
49 Error visit(NewCPUIDRecord &) override;
50 Error visit(TSCWrapRecord &) override;
51 Error visit(CustomEventRecord &) override;
52 Error visit(CallArgRecord &) override;
53 Error visit(PIDRecord &) override;
54 Error visit(NewBufferRecord &) override;
55 Error visit(EndBufferRecord &) override;
56 Error visit(FunctionRecord &) override;
57
58 /// The flush() function will clear out the current state of the visitor, to
59 /// allow for explicitly flushing a block's records to the currently
60 /// recognized thread and process combination.
61 Error flush();
62};
63
64} // namespace xray
65} // namespace llvm
66
67#endif // LLVM_LIB_XRAY_BLOCKINDEXER_H_