Skip to content

Commit

Permalink
rbd-replay: Convert prep-for-replay.py to rbd-replay-prep.cc
Browse files Browse the repository at this point in the history
Signed-off-by: Adam Crume <[email protected]>
  • Loading branch information
adamcrume authored and liewegas committed Aug 21, 2014
1 parent e18748e commit 0f052f8
Show file tree
Hide file tree
Showing 10 changed files with 1,189 additions and 539 deletions.
3 changes: 0 additions & 3 deletions examples/rbd-replay/run-prep-for-replay

This file was deleted.

3 changes: 3 additions & 0 deletions examples/rbd-replay/run-rbd-replay-prep
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

../../src/rbd-replay-prep traces/ust/uid/10002/64-bit replay.bin
1 change: 1 addition & 0 deletions src/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ Makefile
/rbd
/rbd-fuse
/rbd-replay
/rbd-replay-prep
/rest-bench
/sample.fetch_config
/TAGS
Expand Down
18 changes: 16 additions & 2 deletions src/rbd_replay/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ librbd_replay_la_SOURCES = rbd_replay/actions.cc \
rbd_replay/ImageNameMap.cc \
rbd_replay/PendingIO.cc \
rbd_replay/rbd_loc.cc \
rbd_replay/Replayer.cc
rbd_replay/Replayer.cc \
rbd_replay/Ser.cc
librbd_replay_la_LIBADD = $(LIBRBD) \
$(LIBRADOS) \
$(CEPH_GLOBAL)
Expand All @@ -16,7 +17,9 @@ noinst_HEADERS += rbd_replay/BoundedBuffer.hpp \
rbd_replay/PendingIO.hpp \
rbd_replay/rbd_loc.hpp \
rbd_replay/rbd_replay_debug.hpp \
rbd_replay/Replayer.hpp
rbd_replay/Replayer.hpp \
rbd_replay/Ser.hpp


rbd_replay_SOURCES = rbd_replay/rbd-replay.cc
rbd_replay_LDADD = $(LIBRBD) \
Expand All @@ -27,3 +30,14 @@ rbd_replay_LDADD = $(LIBRBD) \
if LINUX
bin_PROGRAMS += rbd-replay
endif #LINUX

# TODO: See if we need any new dependencies
rbd_replay_prep_SOURCES = rbd_replay/rbd-replay-prep.cc
rbd_replay_prep_LDADD = $(LIBRBD) \
$(LIBRADOS) \
$(CEPH_GLOBAL) \
librbd_replay.la \
-lbabeltrace \
-lbabeltrace-ctf \
-lboost_date_time
bin_PROGRAMS += rbd-replay-prep
53 changes: 53 additions & 0 deletions src/rbd_replay/Ser.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
/*
* Ceph - scalable distributed file system
*
* Copyright (C) 2014 Adam Crume <[email protected]>
*
* This is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1, as published by the Free Software
* Foundation. See file COPYING.
*
*/

#include "Ser.hpp"
#include <arpa/inet.h>
#include <cstdlib>
#include <endian.h>


rbd_replay::Ser::Ser(std::ostream &out)
: m_out(out) {
}

void rbd_replay::Ser::write_uint8_t(uint8_t data) {
m_out.write(reinterpret_cast<char*>(&data), sizeof(data));
}

void rbd_replay::Ser::write_uint16_t(uint16_t data) {
data = htons(data);
m_out.write(reinterpret_cast<char*>(&data), sizeof(data));
}

void rbd_replay::Ser::write_uint32_t(uint32_t data) {
data = htonl(data);
m_out.write(reinterpret_cast<char*>(&data), sizeof(data));
}

void rbd_replay::Ser::write_uint64_t(uint64_t data) {
#if __BYTE_ORDER == __LITTLE_ENDIAN
data = (static_cast<uint64_t>(htonl(data)) << 32 | htonl(data >> 32));
#endif
m_out.write(reinterpret_cast<char*>(&data), sizeof(data));
}

void rbd_replay::Ser::write_string(const std::string& data) {
write_uint32_t(data.length());
m_out.write(data.data(), data.length());
}

void rbd_replay::Ser::write_bool(bool data) {
write_uint8_t(data ? 1 : 0);
}
45 changes: 45 additions & 0 deletions src/rbd_replay/Ser.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
/*
* Ceph - scalable distributed file system
*
* Copyright (C) 2014 Adam Crume <[email protected]>
*
* This is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1, as published by the Free Software
* Foundation. See file COPYING.
*
*/

#ifndef _INCLUDED_RBD_REPLAY_SER_HPP
#define _INCLUDED_RBD_REPLAY_SER_HPP

#include <iostream>
#include <stdint.h>

namespace rbd_replay {

class Ser {
public:
Ser(std::ostream &out);

void write_uint8_t(uint8_t);

void write_uint16_t(uint16_t);

void write_uint32_t(uint32_t);

void write_uint64_t(uint64_t);

void write_string(const std::string&);

void write_bool(bool b);

private:
std::ostream &m_out;
};

}

#endif
16 changes: 8 additions & 8 deletions src/rbd_replay/actions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,21 +56,21 @@ Action::ptr Action::read_from(Deser &d) {
}
DummyAction dummy(ionum, thread_id, num_successors, num_completion_successors, deps);
switch (type) {
case 0:
case IO_START_THREAD:
return StartThreadAction::read_from(dummy, d);
case 1:
case IO_STOP_THREAD:
return StopThreadAction::read_from(dummy, d);
case 2:
case IO_READ:
return ReadAction::read_from(dummy, d);
case 3:
case IO_WRITE:
return WriteAction::read_from(dummy, d);
case 4:
case IO_ASYNC_READ:
return AioReadAction::read_from(dummy, d);
case 5:
case IO_ASYNC_WRITE:
return AioWriteAction::read_from(dummy, d);
case 6:
case IO_OPEN_IMAGE:
return OpenImageAction::read_from(dummy, d);
case 7:
case IO_CLOSE_IMAGE:
return CloseImageAction::read_from(dummy, d);
default:
cerr << "Invalid action type: " << type << std::endl;
Expand Down
12 changes: 12 additions & 0 deletions src/rbd_replay/actions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,18 @@ struct dependency_d {
}
};

// These are written to files, so don't change existing assignments.
enum io_type {
IO_START_THREAD,
IO_STOP_THREAD,
IO_READ,
IO_WRITE,
IO_ASYNC_READ,
IO_ASYNC_WRITE,
IO_OPEN_IMAGE,
IO_CLOSE_IMAGE,
};


class PendingIO;

Expand Down
Loading

0 comments on commit 0f052f8

Please sign in to comment.