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  virtual ~PerfEventSubsystem() {}
52 
53  virtual std::string name() const
54  {
56  }
57 
59  const ContainerID& containerId,
60  const std::string& cgroup);
61 
63  const ContainerID& containerId,
64  const std::string& cgroup);
65 
67  const ContainerID& containerId,
68  const std::string& cgroup);
69 
71  const ContainerID& containerId,
72  const std::string& cgroup);
73 
74 protected:
75  virtual void initialize();
76 
77 private:
79  const Flags& flags,
80  const std::string& hierarchy,
81  const std::set<std::string>& events);
82 
83  struct Info
84  {
85  Info(const std::string& _cgroup)
86  : cgroup(_cgroup)
87  {
88  // Ensure the initial statistics include the required fields.
89  // Note the duration is set to zero to indicate no sampling has
90  // taken place. This empty sample will be returned from usage()
91  // until the first true sample is obtained.
92  statistics.set_timestamp(process::Clock::now().secs());
93  statistics.set_duration(Seconds(0).secs());
94  }
95 
96  const std::string cgroup;
97  PerfStatistics statistics;
98  };
99 
100  void sample();
101 
102  void _sample(
103  const process::Time& next,
105 
106  // Set of events to sample.
107  std::set<std::string> events;
108 
109  // Stores cgroups associated information for container.
111 };
112 
113 } // namespace slave {
114 } // namespace internal {
115 } // namespace mesos {
116 
117 #endif // __CGROUPS_ISOLATOR_SUBSYSTEMS_PERF_EVENT_HPP__
const std::string CGROUP_SUBSYSTEM_PERF_EVENT_NAME
Definition: constants.hpp:51
Definition: try.hpp:34
static Try< process::Owned< Subsystem > > create(const Flags &flags, const std::string &hierarchy)
virtual std::string name() const
The cgroups subsystem name of this Subsystem object.
Definition: perf_event.hpp:53
virtual process::Future< Nothing > prepare(const ContainerID &containerId, const std::string &cgroup)
Prepare the cgroups subsystem for the associated container.
const Flags flags
Flags used to launch the agent.
Definition: subsystem.hpp:176
Definition: flags.hpp:39
virtual void initialize()
Invoked when a process gets spawned.
virtual ~PerfEventSubsystem()
Definition: perf_event.hpp:51
Definition: hashmap.hpp:38
virtual process::Future< ResourceStatistics > usage(const ContainerID &containerId, const std::string &cgroup)
Gather resource usage statistics of the cgroups subsystem for the associated container.
Definition: duration.hpp:259
Result< std::string > cgroup(pid_t pid)
Represent cgroups perf_event subsystem.
Definition: perf_event.hpp:44
Definition: time.hpp:23
An abstraction for cgroups subsystem.
Definition: subsystem.hpp:42
static Time now()
The current clock time for either the current process that makes this call or the global clock time i...
virtual process::Future< Nothing > recover(const ContainerID &containerId, const std::string &cgroup)
Recover the cgroups subsystem for the associated container.
virtual process::Future< Nothing > cleanup(const ContainerID &containerId, const std::string &cgroup)
Clean up the cgroups subsystem for the associated container.
const std::string hierarchy
The hierarchy path of cgroups subsystem.
Definition: subsystem.hpp:181