summaryrefslogtreecommitdiff
path: root/src/compiler/main.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/compiler/main.cc')
-rw-r--r--src/compiler/main.cc54
1 files changed, 52 insertions, 2 deletions
diff --git a/src/compiler/main.cc b/src/compiler/main.cc
index 4b47232..3036936 100644
--- a/src/compiler/main.cc
+++ b/src/compiler/main.cc
@@ -29,6 +29,37 @@
namespace iorap::compiler {
+// Log everything to stderr.
+// Log errors and higher to logd.
+class StderrAndLogdErrorLogger {
+ public:
+ explicit StderrAndLogdErrorLogger(android::base::LogId default_log_id = android::base::MAIN)
+#ifdef __ANDROID__
+ : logd_(default_log_id)
+#endif
+ {
+ }
+
+ void operator()(::android::base::LogId id,
+ ::android::base::LogSeverity sev,
+ const char* tag,
+ const char* file,
+ unsigned int line,
+ const char* message) {
+#ifdef __ANDROID__
+ if (static_cast<int>(sev) >= static_cast<int>(::android::base::ERROR)) {
+ logd_(id, sev, tag, file, line, message);
+ }
+#endif
+ StderrLogger(id, sev, tag, file, line, message);
+ }
+
+ private:
+#ifdef __ANDROID__
+ ::android::base::LogdLogger logd_;
+#endif
+};
+
void Usage(char** argv) {
std::cerr << "Usage: " << argv[0] << " [--output-proto=output.pb] input1.pb [input2.pb ...]" << std::endl;
std::cerr << "" << std::endl;
@@ -45,6 +76,7 @@ void Usage(char** argv) {
std::cerr << " --inode-textcache $,-it $ Resolve inode->filename from textcache (disables diskscan)." << std::endl;
std::cerr << " --verbose,-v Set verbosity (default off)." << std::endl;
std::cerr << " --wait,-w Wait for key stroke before continuing (default off)." << std::endl;
+ std::cerr << " --pid,-p Set the pid for the compiled trace" << std::endl;
std::cerr << " --timestamp_limit_ns,-tl Set the limit timestamp in nanoseconds for the compiled trace. "
"The order and size of the timestamp should match that of "
"the input trace files. If not specified at all, All of"
@@ -54,7 +86,7 @@ void Usage(char** argv) {
int Main(int argc, char** argv) {
android::base::InitLogging(argv);
- android::base::SetLogger(android::base::StderrLogger);
+ android::base::SetLogger(StderrAndLogdErrorLogger{});
bool wait_for_keystroke = false;
bool enable_verbose = false;
@@ -65,6 +97,7 @@ int Main(int argc, char** argv) {
std::optional<std::string> arg_inode_textcache;
std::vector<uint64_t> timestamp_limit_ns;
+ std::vector<int32_t> pids;
if (argc == 1) {
// Need at least 1 input file to do anything.
@@ -108,6 +141,18 @@ int Main(int argc, char** argv) {
enable_verbose = true;
} else if (argstr == "--wait" || argstr == "-w") {
wait_for_keystroke = true;
+ } else if (argstr == "--pid" || argstr == "-p") {
+ if (!has_arg_next) {
+ std::cerr << "Missing --pid <value>" << std::endl;
+ return 1;
+ }
+ int32_t pid;
+ if (!::android::base::ParseInt<int32_t>(arg_next, &pid)) {
+ std::cerr << "Invalid --pid "<< arg_next << std::endl;
+ return 1;
+ }
+ pids.push_back(pid);
+ ++arg;
} else if (argstr == "--timestamp_limit_ns" || argstr == "-tl") {
if (!has_arg_next) {
std::cerr << "Missing --timestamp_limit_ns <value>" << std::endl;
@@ -132,6 +177,11 @@ int Main(int argc, char** argv) {
return 1;
}
+ if (!pids.empty() && pids.size() != arg_input_filenames.size()) {
+ std::cerr << "The size of pids doesn't match the size of input files."
+ << std::endl;
+ return 1;
+ }
if (enable_verbose) {
android::base::SetMinimumLogSeverity(android::base::VERBOSE);
@@ -183,7 +233,7 @@ int Main(int argc, char** argv) {
int return_code = 0;
std::vector<CompilationInput> perfetto_traces =
- MakeCompilationInputs(arg_input_filenames, timestamp_limit_ns);
+ MakeCompilationInputs(arg_input_filenames, timestamp_limit_ns, pids);
return_code =
!PerformCompilation(std::move(perfetto_traces),
std::move(arg_output_proto),