1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2014 Adam Crume <adamcrume@gmail.com>
8 * This is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License version 2.1, as published by the Free Software
11 * Foundation. See file COPYING.
16 #include <boost/thread.hpp>
17 #include "common/ceph_argparse.h"
18 #include "global/global_init.h"
19 #include "Replayer.hpp"
20 #include "rbd_replay_debug.hpp"
21 #include "ImageNameMap.hpp"
25 using namespace rbd_replay;
28 static const char* get_remainder(const char *string, const char *prefix) {
30 if (*prefix++ != *string++) {
37 static void usage(const char* program) {
38 cout << "Usage: " << program << " --conf=<config_file> <replay_file>" << std::endl;
39 cout << "Options:" << std::endl;
40 cout << " -p, --pool-name <pool> Name of the pool to use. Default: rbd" << std::endl;
41 cout << " --latency-multiplier <float> Multiplies inter-request latencies. Default: 1" << std::endl;
42 cout << " --read-only Only perform non-destructive operations." << std::endl;
43 cout << " --map-image <rule> Add a rule to map image names in the trace to" << std::endl;
44 cout << " image names in the replay cluster." << std::endl;
45 cout << " --dump-perf-counters *Experimental*" << std::endl;
46 cout << " Dump performance counters to standard out before" << std::endl;
47 cout << " an image is closed. Performance counters may be dumped" << std::endl;
48 cout << " multiple times if multiple images are closed, or if" << std::endl;
49 cout << " the same image is opened and closed multiple times." << std::endl;
50 cout << " Performance counters and their meaning may change between" << std::endl;
51 cout << " versions." << std::endl;
53 cout << "Image mapping rules:" << std::endl;
54 cout << "A rule of image1@snap1=image2@snap2 would map snap1 of image1 to snap2 of" << std::endl;
55 cout << "image2." << std::endl;
58 int main(int argc, const char **argv) {
59 vector<const char*> args;
61 argv_to_vec(argc, argv, args);
63 auto cct = global_init(NULL, args, CEPH_ENTITY_TYPE_CLIENT,
64 CODE_ENVIRONMENT_UTILITY, 0);
66 std::vector<const char*>::iterator i;
68 float latency_multiplier = 1;
69 bool readonly = false;
70 ImageNameMap image_name_map;
72 std::ostringstream err;
73 bool dump_perf_counters = false;
74 for (i = args.begin(); i != args.end(); ) {
75 if (ceph_argparse_double_dash(args, i)) {
77 } else if (ceph_argparse_witharg(args, i, &val, "-p", "--pool", (char*)NULL)) {
79 } else if (ceph_argparse_witharg(args, i, &latency_multiplier, err, "--latency-multiplier",
81 if (!err.str().empty()) {
82 cerr << err.str() << std::endl;
85 } else if (ceph_argparse_flag(args, i, "--read-only", (char*)NULL)) {
87 } else if (ceph_argparse_witharg(args, i, &val, "--map-image", (char*)NULL)) {
88 ImageNameMap::Mapping mapping;
89 if (image_name_map.parse_mapping(val, &mapping)) {
90 image_name_map.add_mapping(mapping);
92 cerr << "Unable to parse mapping string: '" << val << "'" << std::endl;
95 } else if (ceph_argparse_flag(args, i, "-h", "--help", (char*)NULL)) {
98 } else if (ceph_argparse_flag(args, i, "--dump-perf-counters", (char*)NULL)) {
99 dump_perf_counters = true;
100 } else if (get_remainder(*i, "-")) {
101 cerr << "Unrecognized argument: " << *i << std::endl;
108 common_init_finish(g_ceph_context);
112 replay_file = args[0];
115 if (replay_file.empty()) {
116 cerr << "No replay file specified." << std::endl;
120 unsigned int nthreads = boost::thread::hardware_concurrency();
121 Replayer replayer(2 * nthreads + 1);
122 replayer.set_latency_multiplier(latency_multiplier);
123 replayer.set_pool_name(pool_name);
124 replayer.set_readonly(readonly);
125 replayer.set_image_name_map(image_name_map);
126 replayer.set_dump_perf_counters(dump_perf_counters);
127 replayer.run(replay_file);