Beispiel #1
0
void print_alerts(lt::session& ses
	, std::function<void(lt::session&, lt::alert const*)> on_alert)
{
	lt::time_point start_time = lt::clock_type::now();

	ses.set_alert_notify([&ses,start_time,on_alert] {
		ses.get_io_service().post([&ses,start_time,on_alert] {

		try {
			std::vector<lt::alert*> alerts;
			ses.pop_alerts(&alerts);

			for (lt::alert const* a : alerts)
			{
				std::printf("%-3d [0] %s\n", int(lt::duration_cast<lt::seconds>(a->timestamp()
					- start_time).count()), a->message().c_str());
				// call the user handler
				on_alert(ses, a);
			}
		} catch (std::exception const& e) {
			std::printf("print alerts: ERROR failed with exception: %s"
				, e.what());
		} catch (...) {
			std::printf("print alerts: ERROR failed with (unknown) exception");
		}
	} ); } );
}
Beispiel #2
0
void print_alerts(lt::session& ses
	, std::function<void(lt::session&, lt::alert const*)> on_alert)
{
	lt::time_point start_time = lt::clock_type::now();

	ses.set_alert_notify([&ses,start_time,on_alert] {
		ses.get_io_service().post([&ses,start_time,on_alert] {

		std::vector<lt::alert*> alerts;
		ses.pop_alerts(&alerts);

		for (lt::alert const* a : alerts)
		{
			printf("%-3d [0] %s\n", int(lt::duration_cast<lt::seconds>(a->timestamp()
				- start_time).count()), a->message().c_str());
			// call the user handler
			on_alert(ses, a);
		}
	} ); } );
}
Beispiel #3
0
int get_cache_size(lt::session& ses)
{
	std::vector<stats_metric> stats = session_stats_metrics();
	int const read_cache_idx = find_metric_idx("disk.read_cache_blocks");
	int const write_cache_idx = find_metric_idx("disk.write_cache_blocks");
	TEST_CHECK(read_cache_idx >= 0);
	TEST_CHECK(write_cache_idx >= 0);
	ses.set_alert_notify([](){});
	ses.post_session_stats();
	std::vector<alert*> alerts;
	ses.pop_alerts(&alerts);
	int cache_size = -1;
	for (auto const a : alerts)
	{
		if (auto const* st = alert_cast<session_stats_alert>(a))
		{
			cache_size = st->values[read_cache_idx];
			cache_size += st->values[write_cache_idx];
			break;
		}
	}
	return cache_size;
}