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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
// Copyright Epic Games, Inc. All Rights Reserved.
#pragma once
#include <zencompute/functionservice.h>
#include <zencompute/zencompute.h>
#include <zencore/basicfile.h>
#include <zencore/compactbinarybuilder.h>
#include <zenstore/cidstore.h>
#include <zenstore/gc.h>
#include <zenstore/zenstore.h>
#include <filesystem>
#include <functional>
#include <unordered_map>
namespace zen {
class CbObject;
class CbPackage;
struct IoHash;
} // namespace zen
#if ZEN_WITH_COMPUTE_SERVICES
namespace zen::compute {
//////////////////////////////////////////////////////////////////////////
class RecordingReaderBase
{
RecordingReaderBase(const RecordingReaderBase&) = delete;
RecordingReaderBase& operator=(const RecordingReaderBase&) = delete;
public:
RecordingReaderBase() = default;
virtual ~RecordingReaderBase() = 0;
virtual std::unordered_map<IoHash, CbPackage> ReadWorkers() = 0;
virtual void IterateActions(std::function<void(CbObject ActionObject, const IoHash& ActionId)>&& Callback, int TargetParallelism) = 0;
virtual size_t GetActionCount() const = 0;
};
//////////////////////////////////////////////////////////////////////////
/**
* Reader for recordings done via the zencompute recording system, which
* have a shared chunk store and a log of actions with pointers into the
* chunk store for their data.
*/
class RecordingReader : public RecordingReaderBase, public ChunkResolver
{
public:
explicit RecordingReader(const std::filesystem::path& RecordingPath);
~RecordingReader();
virtual std::unordered_map<zen::IoHash, zen::CbPackage> ReadWorkers() override;
virtual void IterateActions(std::function<void(CbObject ActionObject, const IoHash& ActionId)>&& Callback,
int TargetParallelism) override;
virtual size_t GetActionCount() const override;
private:
std::filesystem::path m_RecordingLogDir;
BasicFile m_WorkerDataFile;
BasicFile m_ActionDataFile;
GcManager m_Gc;
CidStore m_CidStore{m_Gc};
// ChunkResolver interface
virtual IoBuffer FindChunkByCid(const IoHash& DecompressedId) override;
struct ActionEntry
{
IoHash ActionId;
uint64_t Offset;
uint64_t Size;
};
std::vector<ActionEntry> m_Actions;
void ScanActions();
};
//////////////////////////////////////////////////////////////////////////
struct LocalResolver : public ChunkResolver
{
LocalResolver(const LocalResolver&) = delete;
LocalResolver& operator=(const LocalResolver&) = delete;
LocalResolver() = default;
~LocalResolver() = default;
virtual IoBuffer FindChunkByCid(const IoHash& DecompressedId) override;
void Add(const IoHash& Cid, IoBuffer Data);
private:
RwLock MapLock;
std::unordered_map<IoHash, IoBuffer> Attachments;
};
/**
* This is a reader for UE/DDB recordings, which have a different layout on
* disk (no shared chunk store)
*/
class UeRecordingReader : public RecordingReaderBase, public ChunkResolver
{
public:
explicit UeRecordingReader(const std::filesystem::path& RecordingPath);
~UeRecordingReader();
virtual std::unordered_map<zen::IoHash, zen::CbPackage> ReadWorkers() override;
virtual void IterateActions(std::function<void(CbObject ActionObject, const IoHash& ActionId)>&& Callback,
int TargetParallelism) override;
virtual size_t GetActionCount() const override;
virtual IoBuffer FindChunkByCid(const IoHash& DecompressedId) override;
private:
std::filesystem::path m_RecordingDir;
LocalResolver m_LocalResolver;
std::vector<std::filesystem::path> m_WorkDirs;
CbPackage ReadAction(std::filesystem::path WorkDir);
};
} // namespace zen::compute
#endif // ZEN_WITH_COMPUTE_SERVICES
|