summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYabin Cui <yabinc@google.com>2022-01-20 11:03:14 -0800
committerYabin Cui <yabinc@google.com>2022-01-20 11:03:14 -0800
commit18581af3cda1573e330214f8ecd6cf2753db22a2 (patch)
treeb93576c21d8da92f20f564b7f5fc5d954e7270f8
parent7c1ac352574621daf232d01d6f5960585f2829f9 (diff)
downloadextras-18581af3cda1573e330214f8ecd6cf2753db22a2.tar.gz
simpleperf: move TempSymFile to a impl header file.
So it can be tested later. Bug: 215556268 Test: build Change-Id: I523307bd14b9874c1393b7d3f9aeacaec5651df9
-rw-r--r--simpleperf/JITDebugReader.cpp48
-rw-r--r--simpleperf/JITDebugReader_impl.h77
2 files changed, 78 insertions, 47 deletions
diff --git a/simpleperf/JITDebugReader.cpp b/simpleperf/JITDebugReader.cpp
index 3b58407d..52db2959 100644
--- a/simpleperf/JITDebugReader.cpp
+++ b/simpleperf/JITDebugReader.cpp
@@ -33,6 +33,7 @@
#include <android-base/stringprintf.h>
#include <android-base/strings.h>
+#include "JITDebugReader_impl.h"
#include "dso.h"
#include "environment.h"
#include "read_apk.h"
@@ -203,53 +204,6 @@ static_assert(sizeof(JITCodeEntry64) == 40, "");
static_assert(sizeof(JITCodeEntry64V2) == 48, "");
#endif
-class TempSymFile {
- public:
- static std::unique_ptr<TempSymFile> Create(std::string&& path, bool remove_in_destructor) {
- FILE* fp = fopen(path.data(), "web");
- if (fp == nullptr) {
- PLOG(ERROR) << "failed to create " << path;
- return nullptr;
- }
- if (remove_in_destructor) {
- ScopedTempFiles::RegisterTempFile(path);
- }
- return std::unique_ptr<TempSymFile>(new TempSymFile(std::move(path), fp));
- }
-
- bool WriteEntry(const char* data, size_t size) {
- if (fwrite(data, size, 1, fp_.get()) != 1) {
- PLOG(ERROR) << "failed to write to " << path_;
- return false;
- }
- file_offset_ += size;
- need_flush_ = true;
- return true;
- }
-
- bool Flush() {
- if (need_flush_) {
- if (fflush(fp_.get()) != 0) {
- PLOG(ERROR) << "failed to flush " << path_;
- return false;
- }
- need_flush_ = false;
- }
- return true;
- }
-
- const std::string& GetPath() const { return path_; }
- uint64_t GetOffset() const { return file_offset_; }
-
- private:
- TempSymFile(std::string&& path, FILE* fp) : path_(std::move(path)), fp_(fp, fclose) {}
-
- const std::string path_;
- std::unique_ptr<FILE, decltype(&fclose)> fp_;
- uint64_t file_offset_ = 0;
- bool need_flush_ = false;
-};
-
JITDebugReader::JITDebugReader(const std::string& symfile_prefix, SymFileOption symfile_option,
SyncOption sync_option)
: symfile_prefix_(symfile_prefix), symfile_option_(symfile_option), sync_option_(sync_option) {}
diff --git a/simpleperf/JITDebugReader_impl.h b/simpleperf/JITDebugReader_impl.h
new file mode 100644
index 00000000..27b50b52
--- /dev/null
+++ b/simpleperf/JITDebugReader_impl.h
@@ -0,0 +1,77 @@
+/*
+ * Copyright (C) 2022 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.
+ */
+
+#pragma once
+
+#include <stdio.h>
+
+#include <memory>
+#include <string>
+
+#include <android-base/logging.h>
+
+#include "environment.h"
+
+namespace simpleperf {
+
+class TempSymFile {
+ public:
+ static std::unique_ptr<TempSymFile> Create(std::string&& path, bool remove_in_destructor) {
+ FILE* fp = fopen(path.data(), "web");
+ if (fp == nullptr) {
+ PLOG(ERROR) << "failed to create " << path;
+ return nullptr;
+ }
+ if (remove_in_destructor) {
+ ScopedTempFiles::RegisterTempFile(path);
+ }
+ return std::unique_ptr<TempSymFile>(new TempSymFile(std::move(path), fp));
+ }
+
+ bool WriteEntry(const char* data, size_t size) {
+ if (fwrite(data, size, 1, fp_.get()) != 1) {
+ PLOG(ERROR) << "failed to write to " << path_;
+ return false;
+ }
+ file_offset_ += size;
+ need_flush_ = true;
+ return true;
+ }
+
+ bool Flush() {
+ if (need_flush_) {
+ if (fflush(fp_.get()) != 0) {
+ PLOG(ERROR) << "failed to flush " << path_;
+ return false;
+ }
+ need_flush_ = false;
+ }
+ return true;
+ }
+
+ const std::string& GetPath() const { return path_; }
+ uint64_t GetOffset() const { return file_offset_; }
+
+ private:
+ TempSymFile(std::string&& path, FILE* fp) : path_(std::move(path)), fp_(fp, fclose) {}
+
+ const std::string path_;
+ std::unique_ptr<FILE, decltype(&fclose)> fp_;
+ uint64_t file_offset_ = 0;
+ bool need_flush_ = false;
+};
+
+} // namespace simpleperf