2018-08-01 07:14:43 +00:00
|
|
|
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
|
|
|
|
// This source code is licensed under both the GPLv2 (found in the
|
|
|
|
// COPYING file in the root directory) and Apache 2.0 License
|
|
|
|
// (found in the LICENSE.Apache file in the root directory).
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "rocksdb/trace_reader_writer.h"
|
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
namespace ROCKSDB_NAMESPACE {
|
2018-08-01 07:14:43 +00:00
|
|
|
|
|
|
|
class RandomAccessFileReader;
|
|
|
|
class WritableFileWriter;
|
|
|
|
|
|
|
|
// FileTraceReader allows reading RocksDB traces from a file.
|
|
|
|
class FileTraceReader : public TraceReader {
|
|
|
|
public:
|
|
|
|
explicit FileTraceReader(std::unique_ptr<RandomAccessFileReader>&& reader);
|
|
|
|
~FileTraceReader();
|
|
|
|
|
|
|
|
virtual Status Read(std::string* data) override;
|
|
|
|
virtual Status Close() override;
|
|
|
|
|
|
|
|
private:
|
2018-11-09 19:17:34 +00:00
|
|
|
std::unique_ptr<RandomAccessFileReader> file_reader_;
|
2018-08-01 07:14:43 +00:00
|
|
|
Slice result_;
|
|
|
|
size_t offset_;
|
|
|
|
char* const buffer_;
|
|
|
|
|
|
|
|
static const unsigned int kBufferSize;
|
|
|
|
};
|
|
|
|
|
|
|
|
// FileTraceWriter allows writing RocksDB traces to a file.
|
|
|
|
class FileTraceWriter : public TraceWriter {
|
|
|
|
public:
|
|
|
|
explicit FileTraceWriter(std::unique_ptr<WritableFileWriter>&& file_writer)
|
|
|
|
: file_writer_(std::move(file_writer)) {}
|
|
|
|
~FileTraceWriter();
|
|
|
|
|
|
|
|
virtual Status Write(const Slice& data) override;
|
|
|
|
virtual Status Close() override;
|
2018-11-27 22:24:24 +00:00
|
|
|
virtual uint64_t GetFileSize() override;
|
2018-08-01 07:14:43 +00:00
|
|
|
|
|
|
|
private:
|
2018-11-09 19:17:34 +00:00
|
|
|
std::unique_ptr<WritableFileWriter> file_writer_;
|
2018-08-01 07:14:43 +00:00
|
|
|
};
|
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
} // namespace ROCKSDB_NAMESPACE
|