"configreader.cc",
"cpuconfig.cc",
"perfprofdcore.cc",
+ "perfprofd_io.cc",
"symbolizer.cc"
],
#include "config.h"
#include "perfprofdcore.h"
+#include "perfprofd_io.h"
namespace android {
namespace perfprofd {
std::string data_file_path(config->destination_directory);
data_file_path += "/perf.data";
std::string path = android::base::StringPrintf("%s.encoded.%d", data_file_path.c_str(), seq_);
- PROFILE_RESULT result = SerializeProtobuf(encodedProfile, path.c_str());
- if (result != PROFILE_RESULT::OK_PROFILE_COLLECTION) {
+ if (!SerializeProtobuf(encodedProfile, path.c_str())) {
return false;
}
--- /dev/null
+/*
+**
+** Copyright 2015, The Android Open Source Project
+**
+** Licensed under the Apache License, Version 2.0 (the "License");
+** you may not use this file except in compliance with the License.
+** You may obtain a copy of the License at
+**
+** http://www.apache.org/licenses/LICENSE-2.0
+**
+** Unless required by applicable law or agreed to in writing, software
+** distributed under the License is distributed on an "AS IS" BASIS,
+** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+** See the License for the specific language governing permissions and
+** limitations under the License.
+*/
+
+#include "perfprofd_io.h"
+
+#include <fcntl.h>
+#include <unistd.h>
+
+#include <memory>
+
+#include <android-base/file.h>
+#include <android-base/logging.h>
+#include <android-base/unique_fd.h>
+
+#include "perfprofd_record.pb.h"
+
+namespace android {
+namespace perfprofd {
+
+bool SerializeProtobuf(PerfprofdRecord* encodedProfile,
+ const char* encoded_file_path) {
+ //
+ // Serialize protobuf to array
+ //
+ size_t size = encodedProfile->ByteSize();
+ std::unique_ptr<uint8_t[]> data(new uint8_t[size]);
+ encodedProfile->SerializeWithCachedSizesToArray(data.get());
+
+ //
+ // Open file and write encoded data to it
+ //
+ unlink(encoded_file_path); // Attempt to unlink for a clean slate.
+ constexpr int kFlags = O_CREAT | O_WRONLY | O_TRUNC | O_NOFOLLOW | O_CLOEXEC;
+ android::base::unique_fd fd(open(encoded_file_path, kFlags, 0664));
+ if (fd.get() == -1) {
+ PLOG(WARNING) << "Could not open " << encoded_file_path << " for serialization";
+ return false;
+ }
+ if (!android::base::WriteFully(fd.get(), data.get(), size)) {
+ PLOG(WARNING) << "Could not write to " << encoded_file_path;
+ return false;
+ }
+
+ return true;
+}
+
+} // namespace perfprofd
+} // namespace android
--- /dev/null
+/*
+**
+** Copyright 2018, The Android Open Source Project
+**
+** Licensed under the Apache License, Version 2.0 (the "License");
+** you may not use this file except in compliance with the License.
+** You may obtain a copy of the License at
+**
+** http://www.apache.org/licenses/LICENSE-2.0
+**
+** Unless required by applicable law or agreed to in writing, software
+** distributed under the License is distributed on an "AS IS" BASIS,
+** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+** See the License for the specific language governing permissions and
+** limitations under the License.
+*/
+
+#ifndef SYSTEM_EXTRAS_PERFPROFD_PERFPROFD_IO_H_
+#define SYSTEM_EXTRAS_PERFPROFD_PERFPROFD_IO_H_
+
+#include "perfprofd_record-fwd.h"
+
+namespace android {
+namespace perfprofd {
+
+bool SerializeProtobuf(android::perfprofd::PerfprofdRecord* encodedProfile,
+ const char* encoded_file_path);
+
+} // namespace perfprofd
+} // namespace android
+
+#endif
#include "cpuconfig.h"
#include "perf_data_converter.h"
#include "perfprofdcore.h"
+#include "perfprofd_io.h"
#include "symbolizer.h"
//
}
}
-PROFILE_RESULT SerializeProtobuf(android::perfprofd::PerfprofdRecord* encodedProfile,
- const char* encoded_file_path) {
- //
- // Serialize protobuf to array
- //
- size_t size = encodedProfile->ByteSize();
- std::unique_ptr<uint8_t[]> data(new uint8_t[size]);
- encodedProfile->SerializeWithCachedSizesToArray(data.get());
-
- //
- // Open file and write encoded data to it
- //
- unlink(encoded_file_path); // Attempt to unlink for a clean slate.
- constexpr int kFlags = O_CREAT | O_WRONLY | O_TRUNC | O_NOFOLLOW | O_CLOEXEC;
- android::base::unique_fd fd(open(encoded_file_path, kFlags, 0664));
- if (fd.get() == -1) {
- PLOG(WARNING) << "Could not open " << encoded_file_path << " for serialization";
- return ERR_OPEN_ENCODED_FILE_FAILED;
- }
- if (!android::base::WriteFully(fd.get(), data.get(), size)) {
- PLOG(WARNING) << "Could not write to " << encoded_file_path;
- return ERR_WRITE_ENCODED_FILE_FAILED;
- }
-
- return OK_PROFILE_COLLECTION;
-}
-
static ProtoUniquePtr encode_to_proto(const std::string &data_file_path,
const Config& config,
unsigned cpu_utilization,
return ERR_PERF_ENCODE_FAILED;
}
- return SerializeProtobuf(encodedProfile.get(), encoded_file_path);
+ return android::perfprofd::SerializeProtobuf(encodedProfile.get(), encoded_file_path)
+ ? OK_PROFILE_COLLECTION
+ : ERR_WRITE_ENCODED_FILE_FAILED;
}
//
data_file_path += "/";
data_file_path += PERF_OUTPUT;
std::string path = android::base::StringPrintf("%s.encoded.%d", data_file_path.c_str(), seq);
- PROFILE_RESULT result = SerializeProtobuf(proto, path.c_str());
- if (result != PROFILE_RESULT::OK_PROFILE_COLLECTION) {
+ if (!android::perfprofd::SerializeProtobuf(proto, path.c_str())) {
return false;
}
unsigned cpu_utilization,
perfprofd::Symbolizer* symbolizer);
-PROFILE_RESULT SerializeProtobuf(android::perfprofd::PerfprofdRecord* encodedProfile,
- const char* encoded_file_path);
-
using HandlerFn = std::function<bool(android::perfprofd::PerfprofdRecord* proto,
Config* config)>;