Apache Mesos
perf.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 __PERF_HPP__
18 #define __PERF_HPP__
19 
20 #include <unistd.h>
21 
22 #include <set>
23 #include <string>
24 
25 #include <process/future.hpp>
26 
27 #include <stout/duration.hpp>
28 #include <stout/hashmap.hpp>
29 #include <stout/version.hpp>
30 
31 // For PerfStatistics protobuf.
32 #include "mesos/mesos.hpp"
33 
34 namespace perf {
35 
36 // Sample the perf events for process(es) in the perf_event cgroups
37 // for duration. The returned hashmap is keyed by cgroup.
38 // NOTE: cgroups should be relative to the perf_event subsystem mount,
39 // e.g., mesos/test for /sys/fs/cgroup/perf_event/mesos/test.
41  const std::set<std::string>& events,
42  const std::set<std::string>& cgroups,
43  const Duration& duration);
44 
45 
46 // Validate a set of events are accepted by `perf stat`.
47 bool valid(const std::set<std::string>& events);
48 
49 
50 // Returns whether perf is supported on this host. Returns false if
51 // the kernel is too old (requires >= 2.6.39).
52 bool supported();
53 
54 
55 // Returns the detected perf version. Exposed for testing.
57 
58 
59 // Parse a perf(1) version string. Exposed for testing.
60 Try<Version> parseVersion(const std::string& output);
61 
62 
63 // Note: The parse function is exposed to allow testing of the
64 // multiple supported perf stat output formats.
66  const std::string& output);
67 
68 } // namespace perf {
69 
70 #endif // __PERF_HPP__
Definition: check.hpp:33
Definition: perf.hpp:34
Definition: cgroups.hpp:39
Definition: duration.hpp:32
bool valid(const std::set< std::string > &events)
bool supported()
process::Future< Version > version()
Definition: version.hpp:32
process::Future< hashmap< std::string, mesos::PerfStatistics > > sample(const std::set< std::string > &events, const std::set< std::string > &cgroups, const Duration &duration)
Try< hashmap< std::string, mesos::PerfStatistics > > parse(const std::string &output)
Returns the OCI v1 descriptor, image index, image manifest and image configuration from the given str...
Definition: parse.hpp:36
Try< Version > parseVersion(const std::string &output)
Definition: future.hpp:58