Apache Mesos
perf_event.hpp
Go to the documentation of this file.
1 // Licensed to the Apache Software Foundation (ASF) under one
2 // or more contributor license agreements. See the NOTICE file
3 // distributed with this work for additional information
4 // regarding copyright ownership. The ASF licenses this file
5 // to you under the Apache License, Version 2.0 (the
6 // "License"); you may not use this file except in compliance
7 // with the License. You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 
17 #ifndef __CGROUPS_ISOLATOR_SUBSYSTEMS_PERF_EVENT_HPP__
18 #define __CGROUPS_ISOLATOR_SUBSYSTEMS_PERF_EVENT_HPP__
19 
20 #include <set>
21 #include <string>
22 
23 #include <mesos/resources.hpp>
24 
25 #include <process/clock.hpp>
26 #include <process/future.hpp>
27 #include <process/owned.hpp>
28 #include <process/time.hpp>
29 
30 #include <stout/hashmap.hpp>
31 
32 #include "slave/flags.hpp"
33 
36 
37 namespace mesos {
38 namespace internal {
39 namespace slave {
40 
45 {
46 public:
48  const Flags& flags,
49  const std::string& hierarchy);
50 
51  ~PerfEventSubsystemProcess() override = default;
52 
53  std::string name() const override
54  {
56  }
57 
59  const ContainerID& containerId,
60  const std::string& cgroup,
61  const mesos::slave::ContainerConfig& containerConfig) override;
62 
64  const ContainerID& containerId,
65  const std::string& cgroup) override;
66 
68  const ContainerID& containerId,
69  const std::string& cgroup) override;
70 
72  const ContainerID& containerId,
73  const std::string& cgroup) override;
74 
75 protected:
76  void initialize() override;
77 
78 private:
80  const Flags& flags,
81  const std::string& hierarchy,
82  const std::set<std::string>& events);
83 
84  struct Info
85  {
86  Info(const std::string& _cgroup)
87  : cgroup(_cgroup)
88  {
89  // Ensure the initial statistics include the required fields.
90  // Note the duration is set to zero to indicate no sampling has
91  // taken place. This empty sample will be returned from usage()
92  // until the first true sample is obtained.
93  statistics.set_timestamp(process::Clock::now().secs());
94  statistics.set_duration(Seconds(0).secs());
95  }
96 
97  const std::string cgroup;
98  PerfStatistics statistics;
99  };
100 
101  void sample();
102 
103  void _sample(
104  const process::Time& next,
106 
107  // Set of events to sample.
108  std::set<std::string> events;
109 
110  // Stores cgroups associated information for container.
112 };
113 
114 } // namespace slave {
115 } // namespace internal {
116 } // namespace mesos {
117 
118 #endif // __CGROUPS_ISOLATOR_SUBSYSTEMS_PERF_EVENT_HPP__
const std::string CGROUP_SUBSYSTEM_PERF_EVENT_NAME
Definition: constants.hpp:51
Definition: check.hpp:33
process::Future< Nothing > cleanup(const ContainerID &containerId, const std::string &cgroup) override
Definition: flags.hpp:39
Definition: hashmap.hpp:38
void initialize() override
Invoked when a process gets spawned.
process::Future< ResourceStatistics > usage(const ContainerID &containerId, const std::string &cgroup) override
Definition: duration.hpp:207
Definition: agent.hpp:25
Represent cgroups perf_event subsystem.
Definition: perf_event.hpp:44
Result< std::string > cgroup(pid_t pid)
static Try< process::Owned< SubsystemProcess > > create(const Flags &flags, const std::string &hierarchy)
Definition: subsystem.hpp:190
Definition: time.hpp:23
Definition: attributes.hpp:24
const std::string hierarchy
The hierarchy path of cgroups subsystem.
Definition: subsystem.hpp:245
static Time now()
The current clock time for either the current process that makes this call or the global clock time i...
std::string name() const override
Definition: perf_event.hpp:53
Definition: parse.hpp:33
process::Future< Nothing > prepare(const ContainerID &containerId, const std::string &cgroup, const mesos::slave::ContainerConfig &containerConfig) override
process::Future< Nothing > recover(const ContainerID &containerId, const std::string &cgroup) override