OSDN Git Service

build_verity_metadata: Support --signer_args argument. am: 1522691d1d am: c2e9c0f0fc...
[android-x86/system-extras.git] / simpleperf / cmd_stat.cpp
index 5e82ba8..488e731 100644 (file)
@@ -25,8 +25,8 @@
 #include <string>
 #include <vector>
 
-#include <base/logging.h>
-#include <base/strings.h>
+#include <android-base/logging.h>
+#include <android-base/strings.h>
 
 #include "command.h"
 #include "environment.h"
@@ -34,6 +34,7 @@
 #include "event_fd.h"
 #include "event_selection_set.h"
 #include "event_type.h"
+#include "scoped_signal_handler.h"
 #include "utils.h"
 #include "workload.h"
 
@@ -75,8 +76,8 @@ class StatCommand : public Command {
         system_wide_collection_(false),
         child_inherit_(true) {
     signaled = false;
-    signal_handler_register_.reset(
-        new SignalHandlerRegister({SIGCHLD, SIGINT, SIGTERM}, signal_handler));
+    scoped_signal_handler_.reset(
+        new ScopedSignalHandler({SIGCHLD, SIGINT, SIGTERM}, signal_handler));
   }
 
   bool Run(const std::vector<std::string>& args);
@@ -96,10 +97,14 @@ class StatCommand : public Command {
   std::vector<EventTypeAndModifier> measured_event_types_;
   EventSelectionSet event_selection_set_;
 
-  std::unique_ptr<SignalHandlerRegister> signal_handler_register_;
+  std::unique_ptr<ScopedSignalHandler> scoped_signal_handler_;
 };
 
 bool StatCommand::Run(const std::vector<std::string>& args) {
+  if (!CheckPerfEventLimit()) {
+    return false;
+  }
+
   // 1. Parse options, and use default measured event types if not given.
   std::vector<std::string> workload_args;
   if (!ParseOptions(args, &workload_args)) {
@@ -145,11 +150,6 @@ bool StatCommand::Run(const std::vector<std::string>& args) {
 
   // 4. Count events while workload running.
   auto start_time = std::chrono::steady_clock::now();
-  if (!event_selection_set_.GetEnableOnExec()) {
-    if (!event_selection_set_.EnableEvents()) {
-      return false;
-    }
-  }
   if (workload != nullptr && !workload->Start()) {
     return false;
   }
@@ -415,6 +415,6 @@ bool StatCommand::ShowCounters(const std::vector<CountersInfo>& counters, double
   return true;
 }
 
-__attribute__((constructor)) static void RegisterStatCommand() {
+void RegisterStatCommand() {
   RegisterCommand("stat", [] { return std::unique_ptr<Command>(new StatCommand); });
 }