Merge "storaged: Fix deprecated usages of protobuf API."
This commit is contained in:
commit
27bccbfdef
1 changed files with 16 additions and 16 deletions
|
|
@ -27,6 +27,7 @@
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
#include <aidl/android/hardware/health/BnHealthInfoCallback.h>
|
#include <aidl/android/hardware/health/BnHealthInfoCallback.h>
|
||||||
#include <android-base/file.h>
|
#include <android-base/file.h>
|
||||||
|
|
@ -62,7 +63,7 @@ constexpr int USER_SYSTEM = 0;
|
||||||
|
|
||||||
constexpr ssize_t benchmark_unit_size = 16 * 1024; // 16KB
|
constexpr ssize_t benchmark_unit_size = 16 * 1024; // 16KB
|
||||||
|
|
||||||
constexpr ssize_t min_benchmark_size = 128 * 1024; // 128KB
|
constexpr size_t min_benchmark_size = 128 * 1024; // 128KB
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
|
@ -244,9 +245,10 @@ void storaged_t::load_proto(userid_t user_id) {
|
||||||
proto.ParseFromString(ss.str());
|
proto.ParseFromString(ss.str());
|
||||||
|
|
||||||
const UidIOUsage& uid_io_usage = proto.uid_io_usage();
|
const UidIOUsage& uid_io_usage = proto.uid_io_usage();
|
||||||
uint32_t computed_crc = crc32(current_version,
|
uint32_t computed_crc =
|
||||||
reinterpret_cast<const Bytef*>(uid_io_usage.SerializeAsString().c_str()),
|
crc32(current_version,
|
||||||
uid_io_usage.ByteSize());
|
reinterpret_cast<const Bytef*>(uid_io_usage.SerializeAsString().c_str()),
|
||||||
|
uid_io_usage.ByteSizeLong());
|
||||||
if (proto.crc() != computed_crc) {
|
if (proto.crc() != computed_crc) {
|
||||||
LOG(WARNING) << "CRC mismatch in " << proto_file;
|
LOG(WARNING) << "CRC mismatch in " << proto_file;
|
||||||
return;
|
return;
|
||||||
|
|
@ -264,31 +266,29 @@ char* storaged_t:: prepare_proto(userid_t user_id, StoragedProto* proto) {
|
||||||
|
|
||||||
const UidIOUsage& uid_io_usage = proto->uid_io_usage();
|
const UidIOUsage& uid_io_usage = proto->uid_io_usage();
|
||||||
proto->set_crc(crc32(current_version,
|
proto->set_crc(crc32(current_version,
|
||||||
reinterpret_cast<const Bytef*>(uid_io_usage.SerializeAsString().c_str()),
|
reinterpret_cast<const Bytef*>(uid_io_usage.SerializeAsString().c_str()),
|
||||||
uid_io_usage.ByteSize()));
|
uid_io_usage.ByteSizeLong()));
|
||||||
|
|
||||||
uint32_t pagesize = sysconf(_SC_PAGESIZE);
|
uint32_t pagesize = sysconf(_SC_PAGESIZE);
|
||||||
if (user_id == USER_SYSTEM) {
|
if (user_id == USER_SYSTEM) {
|
||||||
proto->set_padding("", 1);
|
proto->set_padding("", 1);
|
||||||
vector<char> padding;
|
vector<char> padding;
|
||||||
ssize_t size = ROUND_UP(MAX(min_benchmark_size, proto->ByteSize()),
|
ssize_t size = ROUND_UP(std::max(min_benchmark_size, proto->ByteSizeLong()), pagesize);
|
||||||
pagesize);
|
padding = vector<char>(size - proto->ByteSizeLong(), 0xFD);
|
||||||
padding = vector<char>(size - proto->ByteSize(), 0xFD);
|
|
||||||
proto->set_padding(padding.data(), padding.size());
|
proto->set_padding(padding.data(), padding.size());
|
||||||
while (!IS_ALIGNED(proto->ByteSize(), pagesize)) {
|
while (!IS_ALIGNED(proto->ByteSizeLong(), pagesize)) {
|
||||||
padding.push_back(0xFD);
|
padding.push_back(0xFD);
|
||||||
proto->set_padding(padding.data(), padding.size());
|
proto->set_padding(padding.data(), padding.size());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
char* data = nullptr;
|
char* data = nullptr;
|
||||||
if (posix_memalign(reinterpret_cast<void**>(&data),
|
if (posix_memalign(reinterpret_cast<void**>(&data), pagesize, proto->ByteSizeLong())) {
|
||||||
pagesize, proto->ByteSize())) {
|
PLOG(ERROR) << "Faied to alloc aligned buffer (size: " << proto->ByteSizeLong() << ")";
|
||||||
PLOG(ERROR) << "Faied to alloc aligned buffer (size: " << proto->ByteSize() << ")";
|
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
proto->SerializeToArray(data, proto->ByteSize());
|
proto->SerializeToArray(data, proto->ByteSizeLong());
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -314,7 +314,7 @@ void storaged_t::flush_proto_data(userid_t user_id,
|
||||||
|
|
||||||
while (size > 0) {
|
while (size > 0) {
|
||||||
start = steady_clock::now();
|
start = steady_clock::now();
|
||||||
ret = write(fd, data, MIN(benchmark_unit_size, size));
|
ret = write(fd, data, std::min(benchmark_unit_size, size));
|
||||||
if (ret <= 0) {
|
if (ret <= 0) {
|
||||||
PLOG(ERROR) << "Faied to write tmp file: " << tmp_file;
|
PLOG(ERROR) << "Faied to write tmp file: " << tmp_file;
|
||||||
return;
|
return;
|
||||||
|
|
@ -352,7 +352,7 @@ void storaged_t::flush_proto(userid_t user_id, StoragedProto* proto) {
|
||||||
unique_ptr<char> proto_data(prepare_proto(user_id, proto));
|
unique_ptr<char> proto_data(prepare_proto(user_id, proto));
|
||||||
if (proto_data == nullptr) return;
|
if (proto_data == nullptr) return;
|
||||||
|
|
||||||
flush_proto_data(user_id, proto_data.get(), proto->ByteSize());
|
flush_proto_data(user_id, proto_data.get(), proto->ByteSizeLong());
|
||||||
}
|
}
|
||||||
|
|
||||||
void storaged_t::flush_protos(unordered_map<int, StoragedProto>* protos) {
|
void storaged_t::flush_protos(unordered_map<int, StoragedProto>* protos) {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue