Derecho  0.9
Distributed systems toolkit for RDMA
util.hpp
Go to the documentation of this file.
1 #ifndef RDMC_UTIL_HPP
2 #define RDMC_UTIL_HPP
3 
4 #include <derecho/utils/time.h>
5 
6 #include <cstdlib>
7 #include <map>
8 #include <mutex>
9 #include <string>
10 #include <vector>
11 
12 template <class T, class U>
13 size_t index_of(T container, U elem) {
14  size_t n = 0;
15  for(auto it = begin(container); it != end(container); ++it) {
16  if(*it == elem) return n;
17 
18  n++;
19  }
20  return container.size();
21 }
22 bool file_exists(const std::string &name);
23 void create_directory(const std::string &name);
24 double compute_data_rate(size_t numBytes, uint64_t sTime, uint64_t eTime);
25 void put_flush(const char *str);
26 void reset_epoch();
27 void query_peer_addresses(std::map<uint32_t, std::string> &addresses,
28  uint32_t &node_rank);
29 
30 double compute_mean(std::vector<double> v);
31 double compute_stddev(std::vector<double> v);
32 
33 #define TRACE(x) \
34  do { \
35  put_flush(x); \
36  } while(0)
37 
38 struct event {
39  const char *file;
40  const char *event_name;
41  uint64_t time;
42 
43  int line;
44  uint32_t group_number;
46  size_t block_number;
47 };
48 extern std::vector<event> events;
49 extern std::mutex events_mutex;
50 inline void log_event(const char *file, int line, uint32_t group_number,
51  size_t message_number, size_t block_number,
52  const char *event_name) {
53  std::unique_lock<std::mutex> lock(events_mutex);
54  events.emplace_back(event{file, event_name, get_time(), line, group_number,
55  message_number, block_number});
56 }
57 void flush_events();
58 void start_flush_server();
59 #define DERECHO_LOG(sender, message_number, event_name) \
60  do { \
61  log_event(__FILE__, __LINE__, sender, message_number, -1, event_name); \
62  } while(0)
63 
64 #define LOG_EVENT(group_number, message_number, block_number, event_name) \
65  do { \
66  } while(0)
67 
68 inline void CHECK(bool b) {
69  if(!b) {
70  puts("CHECK failed, aborting.");
71  abort();
72  }
73 }
74 
75 #endif /* UTIL_HPP */
Definition: util.hpp:38
std::vector< event > events
Definition: util.cpp:118
uint64_t get_time()
Definition: time.h:13
void flush_events()
Definition: util.cpp:130
double compute_stddev(std::vector< double > v)
Definition: util.cpp:112
std::mutex events_mutex
Definition: util.cpp:119
double compute_mean(std::vector< double > v)
Definition: util.cpp:108
bool file_exists(const std::string &name)
Definition: util.cpp:34
size_t message_number
Definition: util.hpp:45
uint32_t node_rank
Definition: experiment.cpp:45
void create_directory(const std::string &name)
Definition: util.cpp:39
void reset_epoch()
Definition: util.cpp:102
uint64_t time
Definition: util.hpp:41
double compute_data_rate(size_t numBytes, uint64_t sTime, uint64_t eTime)
Definition: util.cpp:44
const char * file
Definition: util.hpp:39
void log_event(const char *file, int line, uint32_t group_number, size_t message_number, size_t block_number, const char *event_name)
Definition: util.hpp:50
void CHECK(bool b)
Definition: util.hpp:68
void query_peer_addresses(std::map< uint32_t, std::string > &addresses, uint32_t &node_rank)
Definition: util.cpp:85
uint32_t group_number
Definition: util.hpp:44
size_t index_of(T container, U elem)
Definition: util.hpp:13
void put_flush(const char *str)
Definition: util.cpp:47
int line
Definition: util.hpp:43
void start_flush_server()
Definition: util.cpp:120
size_t block_number
Definition: util.hpp:46
const char * event_name
Definition: util.hpp:40