Apache Mesos
profiler.hpp
Go to the documentation of this file.
1 // Licensed under the Apache License, Version 2.0 (the "License");
2 // you may not use this file except in compliance with the License.
3 // You may obtain a copy of the License at
4 //
5 // http://www.apache.org/licenses/LICENSE-2.0
6 //
7 // Unless required by applicable law or agreed to in writing, software
8 // distributed under the License is distributed on an "AS IS" BASIS,
9 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 // See the License for the specific language governing permissions and
11 // limitations under the License
12 
13 #ifndef __PROCESS_PROFILER_HPP__
14 #define __PROCESS_PROFILER_HPP__
15 
16 #include <string>
17 
18 #include <process/future.hpp>
19 #include <process/http.hpp>
20 #include <process/process.hpp>
21 
22 namespace process {
23 
24 class Profiler : public Process<Profiler>
25 {
26 public:
27  Profiler(const Option<std::string>& _authenticationRealm)
28  : ProcessBase("profiler"),
29  authenticationRealm(_authenticationRealm) {}
30 
31  ~Profiler() override {}
32 
33 protected:
34  void initialize() override
35  {
36  route("/start",
37  authenticationRealm,
38  START_HELP(),
39  &Profiler::start);
40 
41  route("/stop",
42  authenticationRealm,
43  STOP_HELP(),
44  &Profiler::stop);
45  }
46 
47 private:
48  static const std::string START_HELP();
49  static const std::string STOP_HELP();
50 
51  // HTTP endpoints.
52 
53  // Starts the profiler. There are no request parameters.
55  const http::Request& request,
57 
58  // Stops the profiler. There are no request parameters.
59  // This returns the profile output, it will also remain present
60  // in the working directory.
62  const http::Request& request,
64 
65  // The authentication realm that the profiler's HTTP endpoints will be
66  // installed into.
67  Option<std::string> authenticationRealm;
68 };
69 
70 } // namespace process {
71 
72 #endif // __PROCESS_PROCESS_HPP__
void initialize() override
Invoked when a process gets spawned.
Definition: profiler.hpp:34
Profiler(const Option< std::string > &_authenticationRealm)
Definition: profiler.hpp:27
Future< Response > request(const Request &request, bool streamedResponse=false)
Asynchronously sends an HTTP request to the process and returns the HTTP response once the entire res...
Definition: profiler.hpp:24
Definition: process.hpp:72
void route(const std::string &name, const Option< std::string > &help, const HttpRequestHandler &handler, const RouteOptions &options=RouteOptions())
Sets up a handler for HTTP requests with the specified name.
Definition: http.hpp:533
Definition: executor.hpp:48
Definition: process.hpp:505
~Profiler() override
Definition: profiler.hpp:31