Exemplo n.º 1
0
monitor::~monitor()
{
	//TODO: is node still alive here? If so, add shutdown log messages
	// for both monitoring and handystats
	stop();
#if defined(HAVE_HANDYSTATS) && !defined(HANDYSTATS_DISABLE)
	HANDY_FINALIZE();
#endif
}
Exemplo n.º 2
0
int main(int argc, char** argv) {
	HANDY_CONFIG_JSON("{\"metrics-dump\":{\"interval\": 20}}");
	HANDY_INIT();

	run_test_gauge();
	run_test_counter();
	run_test_scoped_counter();
	run_test_timer();
	run_test_scoped_timer();
	run_test_attr();

	int ret = check_tests(argc, argv);

	HANDY_FINALIZE();

	return ret;
}
Exemplo n.º 3
0
int main(int argc, char** argv) {
	namespace po = boost::program_options;
	po::options_description desc("Options");
	desc.add_options()
		("help", "Print help messages")
		("handystats-config", po::value<std::string>(),
			"Handystats configuration (in JSON format)"
		)
		("threads", po::value<uint64_t>(&threads)->default_value(threads),
			"Number of worker threads"
		)
		("step", po::value<std::vector<uint64_t>>(&steps)->multitoken()->required(),
			"Load step pairs (rate, seconds), e.g. --step 100 10 --step 200 10"
		)
		("timers", po::value<uint64_t>(&timers)->default_value(timers),
			"Number of different timers (0 for no timers)"
		)
		("counters", po::value<uint64_t>(&counters)->default_value(counters),
			"Number of different counters (0 for no counters)"
		)
		("gauges", po::value<uint64_t>(&gauges)->default_value(gauges),
			"Number of different gauges (0 for no gauges)"
		)
		("output-interval", po::value<uint64_t>()->default_value(output_interval.count()),
			"Stats output interval (in milliseconds)"
		)
	;

	po::variables_map vm;
	try {
		po::store(po::parse_command_line(argc, argv, desc), vm);
		if (vm.count("help")) {
			std::cout << desc << std::endl;
			return 0;
		}
		po::notify(vm);
	}
	catch(po::error& e) {
		std::cerr << "ERROR: " << e.what() << std::endl << std::endl;
		std::cerr << desc << std::endl;
		return 1;
	}

	if (vm["threads"].as<uint64_t>() == 0) {
		std::cerr << "ERROR: number of threads must be greater than 0" << std::endl;
		return 1;
	}

	if (!vm["timers"].as<uint64_t>() && !vm["counters"].as<uint64_t>() && !vm["gauges"].as<uint64_t>()) {
		std::cerr << "ERROR: at least one metric type must be specified (timers, counters, gauges)" << std::endl;
		return 1;
	}

	if (vm.count("handystats-config")) {
		HANDY_CONFIG_JSON(vm["handystats-config"].as<std::string>().c_str());
	}

	output_interval = std::chrono::milliseconds(vm["output-interval"].as<uint64_t>());

	HANDY_INIT();

	std::atomic<bool> stop_flag(false);
	std::thread stats_printer(
			[&stop_flag] () {
				while (!stop_flag.load()) {
					const auto& start_time = handystats::chrono::tsc_clock::now();
					print_stats();
					const auto& end_time = handystats::chrono::tsc_clock::now();

					const auto& call_time = handystats::chrono::duration::convert_to(
							handystats::chrono::time_unit::NSEC, end_time - start_time
						);
					std::this_thread::sleep_for(output_interval - std::chrono::nanoseconds(call_time.count()));
				}
			}
		);

	std::vector<std::thread> workers(threads);
	for (size_t step_index = 0; step_index < steps.size(); step_index += 2) {
		uint64_t step_rate = steps[step_index];
		uint64_t step_time_limit = steps[step_index + 1];

		if (step_time_limit == 0) {
			continue;
		}

		rate.store(step_rate);
		end_time.store(
				handystats::chrono::duration::convert_to(handystats::chrono::time_unit::USEC,
					(
						handystats::chrono::tsc_clock::now() +
						handystats::chrono::duration(step_time_limit, handystats::chrono::time_unit::SEC)
					).time_since_epoch()
				).count()
			);

		if (step_rate == 0) {
			std::this_thread::sleep_for(std::chrono::seconds(step_time_limit));
			continue;
		}

		handystats::chrono::duration command_time_limit =
			handystats::chrono::duration::convert_to(
					handystats::chrono::time_unit::NSEC,
					handystats::chrono::duration(1, handystats::chrono::time_unit::SEC)
				) * threads / step_rate;
		handystats::chrono::duration time_limit(step_time_limit, handystats::chrono::time_unit::SEC);

		for (auto& worker : workers) {
			worker = std::thread(
					[command_time_limit, time_limit]
					() {
						handystats::benchmarks::command_executor::run_for(
							[] () {
								command();
							},
							command_time_limit,
							time_limit
						);
					}
				);
		}

		for (auto& worker : workers) {
			worker.join();
		}
	}

	stop_flag.store(true);
	stats_printer.join();

	HANDY_FINALIZE();
}
Exemplo n.º 4
0
	virtual void TearDown() {
		HANDY_FINALIZE();
	}