bring back some md tools

This commit is contained in:
Eric Harding committed 2017-10-03 13:46:03 -04:00
1 parent c3c296f787
commit 10247a65db
5 files changed
+93 -21

No files matched your search

+5 -2
View File
@@ -10,17 +10,20 @@
#include "setup/BootstrapActor.h"
#include "fabric/Domain.h"
#include "testing/catch_test_runner.h"
#include <vector>
int main( int argc, const char*argv[] )
{
using namespace bts;
os::set_thread_name("main");
if (argc > 1 && strcmp(argv[1], "configcheck")==0) {
configcheck(argc-2, argv+2);
}
else if (argc > 1 && std::string(argv[1]) == "record") {
run_recorder("./", "futures.coconut");
else if (argc > 1 && strcmp(argv[1], "md") == 0) {
std::vector<std::string> args(argv+2, argv+argc);
bts::md::md_tool(args);
}
else if (argc > 1 && std::string(argv[1]) == "test") {
bts::run_tests(--argc, argv+1);
+79 -16
View File
@@ -1,28 +1,31 @@
#include "run_md.h"
#include "lib/md/relay/RelayRecorder.h"
#include "lib/md/PlatformLoader.h"
#include "lib/md/relay/RelayRecorder.h"
#include "lib/utils/bts_assert.h"
#include "lib/config/config.h"
#include "lib/config/protos/MarketData.pb.h"
#include "lib/logging/logging.h"
#include "lib/md/get_symbols.h"
#include "lib/md/UserSymbol.h"
#include "lib/md/Diag/ShmDumper.h"
#include "platforms/mdp3_onixs/MDP3Main.h"
#include <boost/filesystem.hpp>
#include <iostream>
#include <thread>
#include <boost/filesystem.hpp>
#include <set>
using namespace bts;
using namespace md;
using namespace md2;
using namespace std;
namespace bts {
namespace md {
void clean_dir(const std::string base_path) {
LOG(MarketData, Info, "Cleaning shared memory");
namespace fs = boost::filesystem;
const fs::path p(base_path);
auto file_prefix = "bts_edge_" + config::get<md::PublisherNamespace>().shared_memory_namespace() + "_";
auto file_prefix = "bts_edge_" + config::get<PublisherNamespace>().shared_memory_namespace() + "_";
if (fs::is_directory(p)) {
fs::directory_iterator end_iter;
for (fs::directory_iterator dir_iter(p); dir_iter != end_iter; ++dir_iter) {
@@ -42,11 +45,12 @@ void clean_dir(const std::string base_path) {
}
}
void run_relay() {
auto naggle_ms = config::get<md::RelayOptions>().naggle_ms();
void run_replay() {
auto naggle_ms = config::get<RelayOptions>().naggle_ms();
auto file = "http://mdreplay/spark/futures.coconut";
replay_recording(file, naggle_ms);
}
void run_onixs() {
// get all glbx symbols
std::vector<UserSymbol> symbols;
@@ -55,25 +59,84 @@ void run_onixs() {
main.run(symbols);
}
void run_cleanup() {
clean_dir("/dev/shm");
}
std::thread* _md_thread;
void run_market_datapublishers() {
bts_assert(_md_thread == nullptr);
// start a thread for the md
_md_thread = new std::thread([]() {
os::set_thread_name("md publisher");
clean_dir("/dev/shm");
run_cleanup();
if (config::get<MarketDataConfig>().use_replay()) {
run_relay();
}
else {
run_onixs();
}
if (config::get<MarketDataConfig>().use_replay()) {
run_replay();
}
else {
run_onixs();
}
});
}
void run_recorder(const char* path, const char* filename) {
run_market_datapublishers();
record_everything(path, filename);
void run_record(const std::string& arg){
boost::filesystem::path p(arg);
record_everything(p.parent_path().string(), p.filename().string());
}
void run_dump(const std::string& name, const std::string& hotcold) {
if (name.empty()) return;
string temp = name;
if (name.find("bts_edge_") == string::npos) temp = "bts_edge_" + config::get<PublisherNamespace>().shared_memory_namespace() + "_" + name;
ShmDumper dumper(temp);
if (hotcold.empty() || hotcold == "cold" || hotcold == "c") {
dumper.dump_cold();
}
else {
dumper.dump_hot();
}
}
void run_rectool(const vector<string> args) {
if (args.size() < 2) {
cout << "rectool use: " << endl;
cout << "\tbtscmd md rectool print <filepath>" << endl;
cout << "\tbtscmd md rectool unprint <input> <output>" << endl;
cout << "\tbtscmd md rectool trace <filepath> <security_key>" << endl;
return;
}
if (args[0] == "print") {
print_recording(args[1]);
} else
if (args[0] == "unprint") {
unprint_recording(args[1], args[2]);
} else
if (args[0] == "trace") {
trace_recording(args[1], atoi(args[2].c_str()));
}
}
string help() {
return "Coconut 2.0 market data tools:\n" ;
}
void printhelp() {
cout << help() << endl;
}
void md_tool(std::vector<std::string>& args) {
const string& cmd = args.empty() ? "" : args[0];
if (args.empty()) printhelp();
else if (cmd == "record") run_record(args.size() > 1 ? args[1] : "");
else if (cmd == "rectool") run_rectool(vector<string>(args.begin()+1, args.end()));
else if (cmd == "cleanup") run_cleanup();
else if (cmd == "dump") run_dump(args.size() > 1 ? args[1] : "", args.size() > 2 ? args[2] : "");
else if (cmd == "relay") relay_everything();
else printhelp();
}
}}//namespace
+7 -1
View File
@@ -1,5 +1,11 @@
#pragma once
#include <vector>
#include <string>
namespace bts {
namespace md {
void run_market_datapublishers();
void md_tool(std::vector<std::string>& args);
void run_recorder(const char* path, const char* filename);
}}
+1 -1
View File
@@ -31,7 +31,7 @@ struct ServiceHostActor::PImpl
md_query_server()
{
run_market_datapublishers();
md::run_market_datapublishers();
md_query_server = md::run_query_server(service_context);
}
qbus::Quickbus quickbus;