OSDN Git Service

simpleperf: check perf event limit.
[android-x86/system-extras.git] / simpleperf / cmd_stat.cpp
index e25cf5a..488e731 100644 (file)
@@ -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)) {
@@ -410,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); });
 }