Percy++
A C++ implementation of Private Information Retrieval (PIR) protocols
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Pages
percystats.h
1 // Percy++ Copyright 2007,2012,2013,2014
2 // Ian Goldberg <iang@cs.uwaterloo.ca>,
3 // Casey Devet <cjdevet@uwaterloo.ca>,
4 // Wouter Lueks <wouter@telox.net>
5 //
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of version 2 of the GNU General Public License as
8 // published by the Free Software Foundation.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // There is a copy of the GNU General Public License in the COPYING file
16 // packaged with this plugin; if you cannot find it, write to the Free
17 // Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 // 02110-1301 USA
19 
20 #ifndef __PERCYSTATS_H__
21 #define __PERCYSTATS_H__
22 
23 #include <sys/time.h>
24 #include <vector>
25 #include <map>
26 #include "percytypes.h"
27 #include "percyparams.h"
28 
29 extern void sub_timevals (timeval& result, const timeval& t1, const timeval& t2);
30 extern std::ostream& operator<< (std::ostream& os, const timeval& t);
31 
33  // Batch Size
34  nqueries_t batch_size;
35  nqueries_t blocks_per_query;
36 
37  // Timing
38  timeval start_time;
39  timeval encode_start_time;
40  timeval encode_done_time;
41  timeval ctos_start_time; // client -> server communication start
42  timeval ctos_done_time; // client -> server communication done
43  timeval stoc_start_time; // server -> client communication start
44  timeval stoc_done_time; // server -> client communication done
45  timeval decode_start_time;
46  timeval decode_done_time;
47  timeval end_time;
48 
49  // Communication Amounts
50  dbsize_t ctos_bytes; // client -> server bytes sent
51  dbsize_t stoc_bytes; // server -> client bytes sent
52 
53  // Success/Failure
54  bool num_unsuccessful;
55 
56  // Maximal strassen level reached
57  nqueries_t strassen_level_reached;
58 
59  QueryBatchStats(): batch_size(), blocks_per_query(), start_time(),
60  encode_start_time(), encode_done_time(), ctos_start_time(),
61  ctos_done_time(), stoc_start_time(), stoc_done_time(),
62  decode_start_time(), decode_done_time(), end_time(), ctos_bytes(),
63  stoc_bytes(), num_unsuccessful(), strassen_level_reached() {}
64 };
65 
66 class PercyStats {
67 public:
68  PercyStats (const char * appendix = NULL);
69  PercyStats (std::ostream& os, const char * appendix = NULL);
70  virtual ~PercyStats ();
71 
72  void clear_batches () { query_batches.clear(); }
73 
74  nqueries_t start_query_batch (nqueries_t batch_size,
75  nqueries_t blocks_per_query = 1);
76  bool encode_start (nqueries_t batch_number);
77  bool encode_done (nqueries_t batch_number);
78  bool client_to_server_start (nqueries_t batch_number);
79  bool client_to_server_done (nqueries_t batch_number, dbsize_t bytes_sent);
80  bool server_to_client_start (nqueries_t batch_number);
81  bool server_to_client_done (nqueries_t batch_number, dbsize_t bytes_sent);
82  bool decode_start (nqueries_t batch_number);
83  bool decode_done (nqueries_t batch_number, nqueries_t num_unsuccessful = 0);
84  bool strassen_level_reached (nqueries_t batch_number,
85  nqueries_t strassen_level_reached = 0);
86  bool finish_query_batch (nqueries_t batch_number, bool print_head = false);
87 
88  bool time_communication_separately () const { return time_communication; }
89 
90  virtual void print_header () = 0;
91 
92 protected:
93  nqueries_t next_batch_number;
94 
95  // Query information
96  std::map<nqueries_t, QueryBatchStats> query_batches;
97 
98  // Print functions
99  virtual bool print (nqueries_t batch_number, bool print_head = false) = 0;
100  bool print_and_delete (nqueries_t batch_number, bool print_head = false);
101  void print_all (bool print_head = false);
102 
103  std::ostream& os;
104  const char * appendix;
105  bool time_communication;
106 };
107 
108 
109 class PercyClientStats : public PercyStats {
110 public:
111  PercyClientStats (const PercyClientParams * params,
112  const char * appendix = NULL);
113  PercyClientStats (const PercyClientParams * params, std::ostream& os,
114  const char * appendix = NULL);
115  virtual ~PercyClientStats ();
116 
117  virtual void print_header ();
118 
119 protected:
120  virtual bool print (nqueries_t batch_number, bool print_head = false);
121 
122  const PercyClientParams * params;
123 };
124 
125 
126 class PercyServerStats : public PercyStats {
127 public:
128  PercyServerStats (const PercyServerParams * params,
129  const char * appendix = NULL);
130  PercyServerStats (const PercyServerParams * params, std::ostream& os,
131  const char * appendix = NULL);
132  virtual ~PercyServerStats ();
133 
134  virtual void print_header ();
135 
136 protected:
137  virtual bool print (nqueries_t batch_number, bool print_head = false);
138 
139  const PercyServerParams * params;
140 };
141 
142 #endif
Client parameters.
Definition: percyparams.h:189
std::ostream & operator<<(std::ostream &os, PercyMode mode)
Prints a PercyMode string to a stream.
Definition: percystats.h:66
This header contains typedefs for seamless switching between 32- and 64-bit builds of Percy++...
Definition: percystats.h:109
Server parameters.
Definition: percyparams.h:251
Definition: percystats.h:126
Defines the basic structure of protocol parameters (PercyParams), client parameters (PercyClientParam...
Definition: percystats.h:32