1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-26 04:32:44 +01:00
llvm-mirror/include/llvm/XRay/BlockIndexer.h
Dean Michael Berris 76f5aab534 [XRay] Use FDR Records+Visitors for Trace Loading
Summary:
In this change, we overhaul the implementation for loading
`llvm::xray::Trace` objects from files by using the combination of
specific FDR Record types and visitors breaking up the logic to
reconstitute an execution trace from flight-data recorder mode traces.

This change allows us to handle out-of-temporal order blocks as written
in files, and more consistently recreate an execution trace spanning
multiple blocks and threads. To do this, we use the `WallclockRecord`
associated with each block to maintain temporal order of blocks, before
attempting to recreate an execution trace.

The new addition in this change is the `TraceExpander` type which can be
thought of as a decompression/decoding routine. This allows us to
maintain the state of an execution environment (thread+process) and
create `XRayRecord` instances that fit nicely into the `Trace`
container. We don't have a specific unit test for the TraceExpander
type, since the end-to-end tests for the `llvm-xray convert` tools
already cover precisely this codepath.

This change completes the refactoring started with D50441.

Depends on D51911.

Reviewers: mboerger, eizan

Subscribers: mgorny, hiraditya, mgrang, llvm-commits

Differential Revision: https://reviews.llvm.org/D51912

llvm-svn: 341906
2018-09-11 06:45:59 +00:00

71 lines
2.2 KiB
C++

//===- BlockIndexer.h - FDR Block Indexing Visitor ------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// An implementation of the RecordVisitor which generates a mapping between a
// thread and a range of records representing a block.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_LIB_XRAY_BLOCKINDEXER_H_
#define LLVM_LIB_XRAY_BLOCKINDEXER_H_
#include "llvm/ADT/DenseMap.h"
#include "llvm/XRay/FDRRecords.h"
#include <cstdint>
#include <vector>
namespace llvm {
namespace xray {
// The BlockIndexer will gather all related records associated with a
// process+thread and group them by 'Block'.
class BlockIndexer : public RecordVisitor {
public:
struct Block {
uint64_t ProcessID;
int32_t ThreadID;
WallclockRecord *WallclockTime;
std::vector<Record *> Records;
};
// This maps the process + thread combination to a sequence of blocks.
using Index = DenseMap<std::pair<uint64_t, int32_t>, std::vector<Block>>;
private:
Index &Indices;
enum class State : unsigned { SeekExtents, ExtentsFound, ThreadIDFound };
State CurrentState = State::SeekExtents;
Block CurrentBlock{0, 0, nullptr, {}};
public:
explicit BlockIndexer(Index &I) : RecordVisitor(), Indices(I) {}
Error visit(BufferExtents &) override;
Error visit(WallclockRecord &) override;
Error visit(NewCPUIDRecord &) override;
Error visit(TSCWrapRecord &) override;
Error visit(CustomEventRecord &) override;
Error visit(CallArgRecord &) override;
Error visit(PIDRecord &) override;
Error visit(NewBufferRecord &) override;
Error visit(EndBufferRecord &) override;
Error visit(FunctionRecord &) override;
/// The flush() function will clear out the current state of the visitor, to
/// allow for explicitly flushing a block's records to the currently
/// recognized thread and process combination.
Error flush();
};
} // namespace xray
} // namespace llvm
#endif // LLVM_LIB_XRAY_BLOCKINDEXER_H_