Made `PerfEventSubsystemProcess` can be created without `--perf_events`. If the agent flag `--perf_events` is not specified, the `perf_event` subsystem (i.e., `PerfEventSubsystemProcess`) can still be created, but it will not do sampling at all. The reason that we want to do this is, in some cases, even it is not required to sample any events, we still want each container to have its own `perf_event` cgroup instead under the root cgroup.
Review: https://reviews.apache.org/r/67574/ Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/11f1a7c5 Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/11f1a7c5 Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/11f1a7c5 Branch: refs/heads/master Commit: 11f1a7c509f82076b1bce1a24ccfdf370686aec0 Parents: bb670f1 Author: Qian Zhang <[email protected]> Authored: Mon Jun 18 23:23:42 2018 -0700 Committer: Gilbert Song <[email protected]> Committed: Mon Jun 18 23:36:50 2018 -0700 ---------------------------------------------------------------------- .../isolators/cgroups/subsystems/perf_event.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/11f1a7c5/src/slave/containerizer/mesos/isolators/cgroups/subsystems/perf_event.cpp ---------------------------------------------------------------------- diff --git a/src/slave/containerizer/mesos/isolators/cgroups/subsystems/perf_event.cpp b/src/slave/containerizer/mesos/isolators/cgroups/subsystems/perf_event.cpp index 06eca0c..180afc9 100644 --- a/src/slave/containerizer/mesos/isolators/cgroups/subsystems/perf_event.cpp +++ b/src/slave/containerizer/mesos/isolators/cgroups/subsystems/perf_event.cpp @@ -44,6 +44,13 @@ Try<Owned<SubsystemProcess>> PerfEventSubsystemProcess::create( const Flags& flags, const string& hierarchy) { + // If the agent flag `--perf_events` is not specified, we will not do sampling + // at all, so this subsystem is just like a no-op in this case. + if (flags.perf_events.isNone()) { + return Owned<SubsystemProcess>( + new PerfEventSubsystemProcess(flags, hierarchy, set<string>{})); + } + if (!perf::supported()) { return Error("Perf is not supported"); } @@ -54,10 +61,6 @@ Try<Owned<SubsystemProcess>> PerfEventSubsystemProcess::create( "interval (" + stringify(flags.perf_interval) + ") is not supported."); } - if (!flags.perf_events.isSome()) { - return Error("No perf events specified"); - } - set<string> events; foreach (const string& event, strings::tokenize(flags.perf_events.get(), ",")) { @@ -90,7 +93,9 @@ PerfEventSubsystemProcess::PerfEventSubsystemProcess( void PerfEventSubsystemProcess::initialize() { // Start sampling. - sample(); + if (!events.empty()) { + sample(); + } }
