summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorandroid-build-team Robot <android-build-team-robot@google.com>2020-04-10 02:08:03 +0000
committerandroid-build-team Robot <android-build-team-robot@google.com>2020-04-10 02:08:03 +0000
commit91351d805cad743b28037e8950df76f9bb8a29fb (patch)
tree340e5a391a21d453e693c81f342b24d980050a8e
parent0fa558443f965f9f659782319e229055a9c4a8a1 (diff)
parent23af78b48066723b75e4727c6f4c2b3ee1f9eacb (diff)
downloadiorap-91351d805cad743b28037e8950df76f9bb8a29fb.tar.gz
Snap for 6383144 from 23af78b48066723b75e4727c6f4c2b3ee1f9eacb to rvc-release
Change-Id: Id1869fec82227705a73761e68152ea0c01212440
-rw-r--r--src/binder/iiorap_impl.cc70
-rw-r--r--src/common/printer.h62
-rw-r--r--src/maintenance/controller.cc15
-rw-r--r--src/maintenance/controller.h4
-rw-r--r--src/manager/event_manager.cc129
-rw-r--r--src/manager/event_manager.h12
6 files changed, 261 insertions, 31 deletions
diff --git a/src/binder/iiorap_impl.cc b/src/binder/iiorap_impl.cc
index 088631d..514d1be 100644
--- a/src/binder/iiorap_impl.cc
+++ b/src/binder/iiorap_impl.cc
@@ -26,6 +26,10 @@
#include <include/binder/request_id.h>
#include <utils/Printer.h>
+#include <codecvt>
+#include <locale>
+#include <utility>
+
/*
* Definitions for the IIorap binder native service implementation.
* See also IIorap.aidl.
@@ -77,7 +81,14 @@ static std::atomic<bool> s_service_params_ready_{false};
static ServiceParams s_service_params_;
static std::atomic<ServiceParams*> s_service_params_atomic_;
+// Convert an android::String16 (UTF-16) to a UTF-8 std::string.
+static std::string String16ToStdString(const ::android::String16& s16) {
+ std::u16string u16{s16.string()};
+ std::wstring_convert<std::codecvt_utf8_utf16<char16_t>,char16_t> convert;
+ std::string res = convert.to_bytes(u16);
+ return res;
+}
} // namespace anonymous
@@ -175,8 +186,61 @@ class IIorapImpl::Impl {
return service_params_.event_manager_->OnJobScheduledEvent(request_id, event);
}
- void Dump(/*borrow*/::android::Printer& printer) {
- return service_params_.event_manager_->Dump(/*borrow*/printer);
+ void Dump(/*borrow*/::android::Printer& printer,
+ const ::android::Vector<::android::String16>& args) {
+
+ if (args.size() == 0) {
+ service_params_.event_manager_->Dump(/*borrow*/printer);
+ return;
+ }
+
+ ::android::String16 arg_prev;
+ for (const ::android::String16& arg : args) {
+ bool unknown = false;
+ if (arg == ::android::String16("--refresh-properties")) {
+ service_params_.event_manager_->RefreshSystemProperties(/*borrow*/printer);
+ printer.printLine("System properties refreshed.");
+ } else if (arg == ::android::String16("--compile-package")) {
+ // Intentionally left blank.
+ } else if (arg_prev == ::android::String16("--compile-package")) {
+ std::string package_name = String16ToStdString(arg);
+
+ if (!service_params_.event_manager_->CompilePackage(/*borrow*/printer, package_name)) {
+ printer.printFormatLine("Failed to compile package %s.", package_name.c_str());
+ } else {
+ printer.printFormatLine("Package %s compiled.", package_name.c_str());
+ }
+ } else if (arg == ::android::String16("--purge-package")) {
+ // Intentionally left blank.
+ } else if (arg_prev == ::android::String16("--purge-package")) {
+ std::string package_name = String16ToStdString(arg);
+
+ if (!service_params_.event_manager_->PurgePackage(/*borrow*/printer, package_name)) {
+ printer.printFormatLine("Failed to purge package %s.", package_name.c_str());
+ } else {
+ printer.printFormatLine("Package %s purged.", package_name.c_str());
+ }
+ } else {
+ unknown = true;
+ }
+
+ if (unknown && arg != ::android::String16("--help")) {
+ printer.printLine("Invalid arguments.");
+ printer.printLine("");
+ }
+
+ if (unknown || arg == ::android::String16("--help")) {
+ printer.printLine("Iorapd dumpsys commands:");
+ printer.printLine(" (0 args): Print state information for debugging iorapd.");
+ printer.printLine(" --help: Display this help menu");
+ printer.printLine(" --compile-package <name>: Compile single package on device");
+ printer.printLine(" --purge-package <name>: Delete database entries/files for package");
+ printer.printLine(" --refresh-properties: Refresh system properties");
+ return;
+ }
+
+ arg_prev = arg;
+ }
}
void HandleFakeBehavior(const RequestId& request_id) {
@@ -297,7 +361,7 @@ bool IIorapImpl::Start(std::shared_ptr<manager::EventManager> event_manager) {
::android::FdPrinter printer{fd};
- impl_->Dump(printer);
+ impl_->Dump(printer, args);
return ::android::NO_ERROR;
}
diff --git a/src/common/printer.h b/src/common/printer.h
new file mode 100644
index 0000000..272e459
--- /dev/null
+++ b/src/common/printer.h
@@ -0,0 +1,62 @@
+/*
+ * Copyright (C) 2020 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 IORAP_UTILS_PRINTER_H_
+#define IORAP_UTILS_PRINTER_H_
+
+#include <utils/Printer.h>
+
+#include <string.h>
+
+namespace iorap::common {
+
+class StderrLogPrinter : public ::android::Printer {
+public:
+ // Create a printer using the specified logcat and log priority
+ // - Unless ignoreBlankLines is false, print blank lines to logcat
+ // (Note that the default ALOG behavior is to ignore blank lines)
+ StderrLogPrinter(const char* logtag,
+ android_LogPriority priority = ANDROID_LOG_DEBUG,
+ const char* prefix = nullptr,
+ bool ignore_blank_lines = false)
+ : log_printer_{logtag, priority, prefix, ignore_blank_lines} {
+ logtag_ = logtag;
+ prefix_ = prefix;
+ ignore_blank_lines_ = ignore_blank_lines;
+ }
+
+ // Print the specified line to logcat. No \n at the end is necessary.
+ virtual void printLine(const char* string) override {
+ if (ignore_blank_lines_ && strlen(string) == 0) {
+ return;
+ }
+ std::cerr << logtag_ << ": ";
+ if (prefix_ != nullptr) {
+ std::cerr << prefix_;
+ }
+ std::cerr << string << std::endl;
+ log_printer_.printLine(string);
+ }
+ private:
+ ::android::LogPrinter log_printer_;
+ const char* logtag_;
+ const char* prefix_;
+ bool ignore_blank_lines_;
+};
+
+} // namespace iorap::common
+
+#endif // IORAP_UTILS_PRINTER_H_
diff --git a/src/maintenance/controller.cc b/src/maintenance/controller.cc
index cea7a55..073b938 100644
--- a/src/maintenance/controller.cc
+++ b/src/maintenance/controller.cc
@@ -409,6 +409,21 @@ bool CompileAppsOnDevice(const db::DbHandle& db, const ControllerParameters& par
return ret;
}
+// Compiled the perfetto traces for a single package in a device.
+bool CompileSingleAppOnDevice(const db::DbHandle& db,
+ const ControllerParameters& params,
+ const std::string& package_name) {
+ std::vector<db::PackageModel> packages = db::PackageModel::SelectByName(db, package_name.c_str());
+ bool ret = true;
+ for (db::PackageModel package : packages) {
+ if (!CompilePackage(db, package.name, package.version, params)) {
+ ret = false;
+ }
+ }
+
+ return ret;
+}
+
bool Compile(const std::string& db_path, const ControllerParameters& params) {
iorap::db::SchemaModel db_schema = db::SchemaModel::GetOrCreate(db_path);
db::DbHandle db{db_schema.db()};
diff --git a/src/maintenance/controller.h b/src/maintenance/controller.h
index dcf95a9..dbe6df9 100644
--- a/src/maintenance/controller.h
+++ b/src/maintenance/controller.h
@@ -102,6 +102,10 @@ bool Compile(const std::string& db_path,
// Visible for testing.
bool CompileAppsOnDevice(const db::DbHandle& db, const ControllerParameters& params);
+bool CompileSingleAppOnDevice(const db::DbHandle& db,
+ const ControllerParameters& params,
+ const std::string& package_name);
+
void Dump(const db::DbHandle& db, ::android::Printer& printer);
} // iorap::maintenance
diff --git a/src/manager/event_manager.cc b/src/manager/event_manager.cc
index 1f0ea13..80cfb35 100644
--- a/src/manager/event_manager.cc
+++ b/src/manager/event_manager.cc
@@ -17,6 +17,7 @@
#include "binder/package_version_map.h"
#include "common/debug.h"
#include "common/expected.h"
+#include "common/printer.h"
#include "common/rx_async.h"
#include "common/trace.h"
#include "db/app_component_name.h"
@@ -34,13 +35,14 @@
#include <android-base/properties.h>
#include <rxcpp/rx.hpp>
#include <server_configurable_flags/get_flags.h>
+#include <utils/misc.h>
+#include <utils/Trace.h>
#include <atomic>
#include <filesystem>
#include <functional>
#include <type_traits>
#include <unordered_map>
-#include <utils/Trace.h>
using rxcpp::observe_on_one_worker;
@@ -59,6 +61,10 @@ using perfetto::PerfettoTraceProto;
using db::AppComponentName;
+static std::atomic<bool> s_tracing_allowed{false};
+static std::atomic<bool> s_readahead_allowed{false};
+static std::atomic<uint64_t> s_min_traces{3};
+
struct PackageBlacklister {
// "x.y.z;foo.bar.baz" colon-separated list of substrings
PackageBlacklister(std::string blacklist_string) {
@@ -189,6 +195,8 @@ struct AppLaunchEventState {
DCHECK_GE(event.sequence_id, 0);
sequence_id_ = static_cast<size_t>(event.sequence_id);
+ allowed_readahead_ = s_readahead_allowed;
+ allowed_tracing_ = s_tracing_allowed;
switch (event.type) {
case Type::kIntentStarted: {
@@ -551,7 +559,6 @@ struct AppLaunchEventState {
void AbortTrace() {
LOG(VERBOSE) << "AppLaunchEventState - AbortTrace";
- DCHECK(allowed_tracing_);
// if the tracing is not running, do nothing.
if (!IsTracing()){
@@ -575,7 +582,6 @@ struct AppLaunchEventState {
void MarkPendingTrace() {
LOG(VERBOSE) << "AppLaunchEventState - MarkPendingTrace";
- DCHECK(allowed_tracing_);
DCHECK(is_tracing_);
DCHECK(rx_lifetime_.has_value());
@@ -916,33 +922,13 @@ class EventManager::Impl {
// Try to create version map
RetryCreateVersionMap();
- // TODO: read all properties from one config class.
- // PH properties do not work if they contain ".". "_" was instead used here.
- const char* ph_namespace = "runtime_native_boot";
- tracing_allowed_ = server_configurable_flags::GetServerConfigurableFlag(
- ph_namespace,
- "iorap_perfetto_enable",
- ::android::base::GetProperty("iorapd.perfetto.enable", /*default*/"true")) == "true";
- readahead_allowed_ = server_configurable_flags::GetServerConfigurableFlag(
- ph_namespace,
- "iorap_readahead_enable",
- ::android::base::GetProperty("iorapd.readahead.enable", /*default*/"true")) == "true";
-
- package_blacklister_ = PackageBlacklister{
- /* Colon-separated string list of blacklisted packages, e.g.
- * "foo.bar.baz;com.fake.name" would blacklist {"foo.bar.baz", "com.fake.name"} packages.
- *
- * Blacklisted packages are ignored by iorapd.
- */
- server_configurable_flags::GetServerConfigurableFlag(
- ph_namespace,
- "iorap_blacklisted_packages",
- ::android::base::GetProperty("iorapd.blacklist_packages",
- /*default*/""))
- };
+ iorap::common::StderrLogPrinter printer{"iorapd"};
+ RefreshSystemProperties(printer);
rx_lifetime_ = InitializeRxGraph();
rx_lifetime_jobs_ = InitializeRxGraphForJobScheduledEvents();
+
+ android::add_sysprop_change_callback(&Impl::OnSyspropChanged, /*priority*/-10000);
}
void RetryCreateVersionMap() {
@@ -1107,6 +1093,7 @@ class EventManager::Impl {
min_traces,
std::make_shared<maintenance::Exec>()};
+ LOG(DEBUG) << "StartMaintenance: min_traces=" << min_traces;
maintenance::CompileAppsOnDevice(db, params);
}
}
@@ -1133,7 +1120,7 @@ class EventManager::Impl {
/*inode_textcache=*/std::nullopt,
/*verbose=*/false,
/*recompile=*/false,
- /*min_traces=*/3);
+ s_min_traces);
// TODO: probably this shouldn't be emitted until most of the usual DCHECKs
// (for example, validate a job isn't already started, the request is not reused, etc).
@@ -1198,6 +1185,80 @@ class EventManager::Impl {
}
}
+ static void OnSyspropChanged() {
+ LOG(DEBUG) << "OnSyspropChanged";
+ }
+
+ void RefreshSystemProperties(::android::Printer& printer) {
+ // TODO: read all properties from one config class.
+ // PH properties do not work if they contain ".". "_" was instead used here.
+ const char* ph_namespace = "runtime_native_boot";
+ tracing_allowed_ = server_configurable_flags::GetServerConfigurableFlag(
+ ph_namespace,
+ "iorap_perfetto_enable",
+ ::android::base::GetProperty("iorapd.perfetto.enable", /*default*/"true")) == "true";
+ s_tracing_allowed = tracing_allowed_;
+ printer.printFormatLine("iorapd.perfetto.enable = %s", tracing_allowed_ ? "true" : "false");
+
+ readahead_allowed_ = server_configurable_flags::GetServerConfigurableFlag(
+ ph_namespace,
+ "iorap_readahead_enable",
+ ::android::base::GetProperty("iorapd.readahead.enable", /*default*/"true")) == "true";
+ s_readahead_allowed = readahead_allowed_;
+ printer.printFormatLine("iorapd.readahead.enable = %s", s_readahead_allowed ? "true" : "false");
+
+ s_min_traces =
+ ::android::base::GetUintProperty<uint64_t>("iorapd.maintenance.min_traces", /*default*/3);
+ uint64_t min_traces = s_min_traces;
+ printer.printFormatLine("iorapd.maintenance.min_traces = %" PRIu64, min_traces);
+
+ package_blacklister_ = PackageBlacklister{
+ /* Colon-separated string list of blacklisted packages, e.g.
+ * "foo.bar.baz;com.fake.name" would blacklist {"foo.bar.baz", "com.fake.name"} packages.
+ *
+ * Blacklisted packages are ignored by iorapd.
+ */
+ server_configurable_flags::GetServerConfigurableFlag(
+ ph_namespace,
+ "iorap_blacklisted_packages",
+ ::android::base::GetProperty("iorapd.blacklist_packages",
+ /*default*/""))
+ };
+
+ LOG(DEBUG) << "RefreshSystemProperties";
+ }
+
+ bool PurgePackage(::android::Printer& printer, const std::string& package_name) {
+ (void)printer;
+
+ db::DbHandle db{db::SchemaModel::GetSingleton()};
+ db::CleanUpFilesForPackage(db, package_name);
+ LOG(DEBUG) << "PurgePackage: " << package_name;
+
+ return true;
+ }
+
+ bool CompilePackage(::android::Printer& printer, const std::string& package_name) {
+ (void)printer;
+
+ ScopedFormatTrace atrace_compile_app(ATRACE_TAG_PACKAGE_MANAGER,
+ "Compile one app on device");
+
+ maintenance::ControllerParameters params{
+ /*output_text*/false,
+ /*inode_textcache*/std::nullopt,
+ WOULD_LOG(VERBOSE),
+ /*recompile*/false,
+ s_min_traces,
+ std::make_shared<maintenance::Exec>()};
+
+ db::DbHandle db{db::SchemaModel::GetSingleton()};
+ bool res = maintenance::CompileSingleAppOnDevice(db, std::move(params), package_name);
+ LOG(DEBUG) << "CompilePackage: " << package_name;
+
+ return res;
+ }
+
bool readahead_allowed_{true};
perfetto::RxProducerFactory& perfetto_factory_;
@@ -1286,4 +1347,16 @@ void EventManager::Dump(/*borrow*/::android::Printer& printer) {
return impl_->Dump(printer);
}
+void EventManager::RefreshSystemProperties(::android::Printer& printer) {
+ return impl_->RefreshSystemProperties(printer);
+}
+
+bool EventManager::PurgePackage(::android::Printer& printer, const std::string& package_name) {
+ return impl_->PurgePackage(printer, package_name);
+}
+
+bool EventManager::CompilePackage(::android::Printer& printer, const std::string& package_name) {
+ return impl_->CompilePackage(printer, package_name);
+}
+
} // namespace iorap::manager
diff --git a/src/manager/event_manager.h b/src/manager/event_manager.h
index 2a40191..1a533bc 100644
--- a/src/manager/event_manager.h
+++ b/src/manager/event_manager.h
@@ -89,6 +89,18 @@ class EventManager {
// Print to adb shell dumpsys (for bugreport info).
void Dump(/*borrow*/::android::Printer& printer);
+ // A dumpsys --refresh-properties command signaling that we should
+ // refresh our system properties.
+ void RefreshSystemProperties(::android::Printer& printer);
+
+ // A dumpsys --purge-package <name> command signaling
+ // that all db rows and files associated with a package should be deleted.
+ bool PurgePackage(::android::Printer& printer, const std::string& package_name);
+
+ // A dumpsys --compile-package <name> command signaling
+ // that a package should be recompiled.
+ bool CompilePackage(::android::Printer& printer, const std::string& package_name);
+
class Impl;
private:
std::unique_ptr<Impl> impl_;