0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
ProfileDataScanner.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2007-2015 Hypertable, Inc.
3  *
4  * This file is part of Hypertable.
5  *
6  * Hypertable is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; version 3
9  * of the License.
10  *
11  * Hypertable is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19  * 02110-1301, USA.
20  */
21 
26 
27 #include <Common/Compat.h>
28 
29 #include "ProfileDataScanner.h"
30 
31 #include <Common/Serialization.h>
32 #include <Common/StringExt.h>
33 
34 using namespace Hypertable;
35 using namespace Hypertable::Serialization;
36 using namespace std;
37 
39  return 1;
40 }
41 
43  size_t length = 52;
44  if (!servers.empty()) {
45  for (auto & str : servers)
46  length += encoded_length_vstr(str);
47  }
48  return length;
49 }
50 
51 void ProfileDataScanner::encode_internal(uint8_t **bufp) const {
52  encode_i32(bufp, (uint32_t)subscanners);
53  encode_i32(bufp, (uint32_t)scanblocks);
54  encode_i64(bufp, (uint64_t)cells_scanned);
55  encode_i64(bufp, (uint64_t)cells_returned);
56  encode_i64(bufp, (uint64_t)bytes_scanned);
57  encode_i64(bufp, (uint64_t)bytes_returned);
58  encode_i64(bufp, (uint64_t)disk_read);
59  encode_i32(bufp, (uint32_t)servers.size());
60  if (!servers.empty()) {
61  for (auto & str : servers)
62  encode_vstr(bufp, str);
63  }
64 }
65 
66 void ProfileDataScanner::decode_internal(uint8_t version, const uint8_t **bufp,
67  size_t *remainp) {
68  (void)version;
69  subscanners = (int32_t)decode_i32(bufp, remainp);
70  scanblocks = (int32_t)decode_i32(bufp, remainp);
71  cells_scanned = (int64_t)decode_i64(bufp, remainp);
72  cells_returned = (int64_t)decode_i64(bufp, remainp);
73  bytes_scanned = (int64_t)decode_i64(bufp, remainp);
74  bytes_returned = (int64_t)decode_i64(bufp, remainp);
75  disk_read = (int64_t)decode_i64(bufp, remainp);
76  size_t count = (size_t)decode_i32(bufp, remainp);
77  for (size_t i=0; i<count; i++)
78  servers.insert( decode_vstr(bufp, remainp) );
79 }
80 
81 
83  subscanners += other.subscanners;
84  scanblocks += other.scanblocks;
85  cells_scanned += other.cells_scanned;
86  cells_returned += other.cells_returned;
87  bytes_scanned += other.bytes_scanned;
88  bytes_returned += other.bytes_returned;
89  disk_read += other.disk_read;
90  servers.insert(other.servers.begin(), other.servers.end());
91  return *this;
92 }
93 
95  subscanners -= other.subscanners;
96  scanblocks -= other.scanblocks;
97  cells_scanned -= other.cells_scanned;
98  cells_returned -= other.cells_returned;
99  bytes_scanned -= other.bytes_scanned;
100  bytes_returned -= other.bytes_returned;
101  disk_read -= other.disk_read;
102  for (auto &server : other.servers)
103  servers.erase(server);
104  return *this;
105 }
106 
108  string str = "{ProfileDataScanner: ";
109  str += string("cells_scanned=") + cells_scanned + " ";
110  str += string("cells_returned=") + cells_returned + " ";
111  str += string("bytes_scanned=") + bytes_scanned + " ";
112  str += string("bytes_returned=") + bytes_returned + " ";
113  str += string("disk_read=") + disk_read + " ";
114  str += string("subscanners=") + subscanners + " ";
115  str += string("scanblocks=") + scanblocks + " ";
116  str += string("servers=");
117  bool first = true;
118  for (auto & server : servers) {
119  if (first)
120  first = false;
121  else
122  str += ",";
123  str += server;
124  }
125  str += "}";
126  return str;
127 }
char * decode_vstr(const uint8_t **bufp, size_t *remainp)
Decode a vstr (vint64, data, null).
int32_t scanblocks
Number of scan blocks returned from RangeServers.
ProfileDataScanner & operator+=(const ProfileDataScanner &other)
Adds profile data from another object.
int32_t subscanners
Number of RangeServer::create_scanner() calls.
int64_t bytes_scanned
Number of bytes scanned while executing scan.
Po::typed_value< String > * str(String *v=0)
Definition: Properties.h:166
STL namespace.
size_t encoded_length_vstr(size_t len)
Computes the encoded length of vstr (vint64, data, null)
uint32_t decode_i32(const uint8_t **bufp, size_t *remainp)
Decode a 32-bit integer in little-endian order.
uint64_t decode_i64(const uint8_t **bufp, size_t *remainp)
Decode a 64-bit integer in little-endian order.
Declarations for ProfileDataScanner.
std::set< std::string > servers
Set of server proxy names participating in scan.
int64_t disk_read
Number of bytes read from disk while executing scan.
void encode_i32(uint8_t **bufp, uint32_t val)
Encode a 32-bit integer in little-endian order.
Compatibility Macros for C/C++.
void encode_internal(uint8_t **bufp) const override
Writes serialized representation of object to a buffer.
void encode_i64(uint8_t **bufp, uint64_t val)
Encode a 64-bit integer in little-endian order.
Functions to serialize/deserialize primitives to/from a memory buffer.
std::string to_string()
Returns human-readible string describing profile data.
ProfileDataScanner & operator-=(const ProfileDataScanner &other)
Subtracts profile data from another object.
void encode_vstr(uint8_t **bufp, const void *buf, size_t len)
Encode a buffer as variable length string (vint64, data, null)
Hypertable definitions
void decode_internal(uint8_t version, const uint8_t **bufp, size_t *remainp) override
Reads serialized representation of object from a buffer.
int64_t cells_scanned
Number of cell scanned while executing scan.
int64_t cells_returned
Number of cell returned while executing scan.
String extensions and helpers: sets, maps, append operators etc.
int64_t bytes_returned
Number of bytes returned while executing scan.
uint8_t encoding_version() const override
Returns encoding version.
size_t encoded_length_internal() const override
Returns internal serialized length.