inline void MDS_REQUEST_REPLY(const std::string& method, const int& code, const uint64_t& instance_id) { HANDY_COUNTER_INCREMENT(("mds.%s.reply.%d", method.c_str(), code)); HANDY_COUNTER_INCREMENT(("mds.%s.reply.%dxx", method.c_str(), code / 100)); if (code / 100 != 2) { HANDY_TIMER_DISCARD(("mds.%s.time", method.c_str()), instance_id); HANDY_TIMER_DISCARD(("mds.%s.reply.time", method.c_str()), instance_id); } else { HANDY_TIMER_STOP(("mds.%s.reply.time", method.c_str()), instance_id); } }
// command() function is executed in multiple threads // NOTE: rand() function may be not thread-safe. void command() { // 0 .. counters .. counters + gauges .. counters + gauges + timers const double total_metrics = counters + gauges + timers; double counter_prob = double(counters) / total_metrics; double gauge_prob = double(counters + gauges) / total_metrics; // double timer_prob = 1.0; double choice = double(rand()) / RAND_MAX; if (handystats::math_utils::cmp(choice, counter_prob) < 0) { HANDY_COUNTER_INCREMENT(("load_test.counter.%d", rand() % counters), rand()); } else if (handystats::math_utils::cmp(choice, gauge_prob) < 0) { HANDY_GAUGE_SET(("load_test.gauge.%d", rand() % gauges), rand()); } else { if (rand() & 1) { HANDY_TIMER_START(("load_test.timer.%d", rand() % timers), std::hash<std::thread::id>()(std::this_thread::get_id())); } else { HANDY_TIMER_STOP(("load_test.timer.%d", rand() % timers), std::hash<std::thread::id>()(std::this_thread::get_id())); } } }
inline void MDS_REQUEST_START(const std::string& method, const uint64_t& instance_id) { HANDY_COUNTER_INCREMENT(("mds.%s", method.c_str())); HANDY_TIMER_START(("mds.%s.time", method.c_str()), instance_id); HANDY_TIMER_START(("mds.%s.reply.time", method.c_str()), instance_id); }
void run_test_counter(void) { HANDY_COUNTER_INIT(("%s." TEST_COUNTER_NAME, "test"), TEST_COUNTER_INIT_VALUE); int incr_step; for (incr_step = 0; incr_step < TEST_COUNTER_INCR_COUNT; ++incr_step) { HANDY_COUNTER_INCREMENT(("%s." TEST_COUNTER_NAME, "test"), TEST_COUNTER_INCR_DELTA); } int decr_step; for (decr_step = 0; decr_step < TEST_COUNTER_DECR_COUNT; ++decr_step) { HANDY_COUNTER_DECREMENT(("%s." TEST_COUNTER_NAME, "test"), TEST_COUNTER_DECR_DELTA); } }