libtasks Documentation  1.6
thrift_server/stats.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013-2014 ADTECH GmbH
3  * Licensed under MIT (https://github.com/adtechlabs/libtasks/blob/master/COPYING)
4  *
5  * Author: Andreas Pohl
6  */
7 
8 #include <iostream>
9 #include "stats.h"
10 
11 std::atomic<int> stats::m_req_count;
12 std::atomic<int> stats::m_clients;
13 
14 bool stats::handle_event(tasks::worker* worker, int events) {
15  std::time_t now = std::time(nullptr);
16  std::time_t diff = now - m_last;
17  int count;
18  count = m_req_count.exchange(0, std::memory_order_relaxed);
19  m_last = now;
20  int qps = count / diff;
21  std::cout << qps << " req/s, num of clients " << m_clients << std::endl;
22  return true;
23 }
bool handle_event(tasks::worker *, int revents)
Definition: echoserver.cpp:72
static std::atomic< int > m_req_count
Definition: echoserver.h:32
static std::atomic< int > m_clients
Definition: echoserver.h:33
std::time_t m_last
Definition: echoserver.h:34