FlashGraph-ng
A new frontier in large-scale graph analysis and data mining
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
matrix_stats.h
1 #ifndef __MATRIX_STATS_H__
2 #define __MATRIX_STATS_H__
3 
4 /*
5  * Copyright 2015 Open Connectome Project (http://openconnecto.me)
6  * Written by Da Zheng (zhengda1936@gmail.com)
7  *
8  * This file is part of FlashMatrix.
9  *
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  * http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  */
22 
23 namespace fm
24 {
25 
26 namespace detail
27 {
28 
29 /*
30  * This class maintains the statistics of I/O and computation that occurs
31  * to matrices.
32  */
33 class matrix_stats_t
34 {
35  std::atomic<size_t> mem_read_bytes;
36  std::atomic<size_t> mem_write_bytes;
37  std::atomic<size_t> EM_read_bytes;
38  std::atomic<size_t> EM_write_bytes;
39  std::atomic<size_t> double_multiplies;
40 public:
41  matrix_stats_t() {
42  mem_read_bytes = 0;
43  mem_write_bytes = 0;
44  EM_read_bytes = 0;
45  EM_write_bytes = 0;
46  double_multiplies = 0;
47  }
48 
49  matrix_stats_t(const matrix_stats_t &stats) {
50  mem_read_bytes = stats.mem_read_bytes.load();
51  mem_write_bytes = stats.mem_write_bytes.load();
52  EM_read_bytes = stats.EM_read_bytes.load();
53  EM_write_bytes = stats.EM_write_bytes.load();
54  double_multiplies = stats.double_multiplies.load();
55  }
56 
57  size_t inc_read_bytes(size_t bytes, bool in_mem) {
58  if (in_mem) {
59  mem_read_bytes += bytes;
60  return mem_read_bytes;
61  }
62  else {
63  EM_read_bytes += bytes;
64  return EM_read_bytes;
65  }
66  }
67 
68  size_t get_read_bytes(bool in_mem) const {
69  if (in_mem)
70  return mem_read_bytes;
71  else
72  return EM_read_bytes;
73  }
74 
75  size_t inc_write_bytes(size_t bytes, bool in_mem) {
76  if (in_mem) {
77  mem_write_bytes += bytes;
78  return mem_write_bytes;
79  }
80  else {
81  EM_write_bytes += bytes;
82  return EM_write_bytes;
83  }
84  }
85 
86  size_t get_write_bytes(bool in_mem) const {
87  if (in_mem)
88  return mem_write_bytes;
89  else
90  return EM_write_bytes;
91  }
92 
93  size_t inc_multiplies(size_t multiplies) {
94  this->double_multiplies += multiplies;
95  return double_multiplies;
96  }
97 
98  size_t get_multiplies() const {
99  return double_multiplies;
100  }
101 
102  void print_diff(const matrix_stats_t &orig) const;
103 };
104 
105 extern matrix_stats_t matrix_stats;
106 
107 }
108 
109 }
110 
111 #endif