RStudio Launcher Plugin SDK  1.1.3
A software development kit for creating plugins that work the the RStudio Launcher.
LocalResourceStream.hpp
1 /*
2  * LocalResourceStream.hpp
3  *
4  * Copyright (C) 2020 by RStudio, PBC
5  *
6  * Unless you have received this program directly from RStudio pursuant to the terms of a commercial license agreement
7  * with RStudio, then this program is licensed to you under the following terms:
8  *
9  * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
10  * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
11  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
12  * permit persons to whom the Software is furnished to do so, subject to the following conditions:
13  *
14  * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
15  * Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
18  * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
19  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21  *
22  */
23 
24 #ifndef LAUNCHER_PLUGINS_LOCAL_RESOURCE_STREAM_HPP
25 #define LAUNCHER_PLUGINS_LOCAL_RESOURCE_STREAM_HPP
26 
27 #include <api/stream/AbstractTimedResourceStream.hpp>
28 
29 namespace rstudio {
30 namespace launcher_plugins {
31 namespace local {
32 
34 {
35 public:
44  system::TimeDuration in_frequency,
45  const api::ConstJobPtr& in_job,
46  comms::AbstractLauncherCommunicatorPtr in_launcherCommunicator);
47 
48 private:
57  Error getCpuPercent(double& out_cpuPercent);
58 
66  Error getCpuSeconds(double& out_cpuTime);
67 
76  Error getMem(double& out_physMem, double& out_virtMem);
77 
84  Error onInitialize() override;
85 
95  Error pollResourceUtilData(api::ResourceUtilData& out_data) override;
96 
97  // The PID of the process of the job.
98  pid_t m_pid;
99 
100  // The last observed number of system ticks. Used to calculate CPU Percent.
101  clock_t m_lastSysTicks;
102 
103  // The last observed number process ticks. Used to calculate CPU Percent.
104  clock_t m_lastProcTicks;
105 
106  // The number of clock ticks per second. Used to calculate CPU Time.
107  const double m_clockTicksPerSecond;
108 
109  // The number of bytes per page of memory. Used to calculate Physical and Virtual memory MB.
110  const double m_bytesPerPage;
111 };
112 
113 } // namespace local
114 } // namespace launcher_plugins
115 } // namespace rstudio
116 
117 #endif
rstudio::launcher_plugins::local::LocalResourceStream
Definition: LocalResourceStream.hpp:33
rstudio::launcher_plugins::local::LocalResourceStream::LocalResourceStream
LocalResourceStream(system::TimeDuration in_frequency, const api::ConstJobPtr &in_job, comms::AbstractLauncherCommunicatorPtr in_launcherCommunicator)
Constructor.
rstudio::launcher_plugins::api::ResourceUtilData
Represents the current resource utilization of a job.
Definition: ResponseTypes.hpp:111
rstudio::launcher_plugins::Error
Class which represents an error.
Definition: Error.hpp:174
rstudio::launcher_plugins::system::TimeDuration
Represents an duration of time (e.g. 5 hours, 43 minutes, and 21 seconds) as opposed to a point in ti...
Definition: DateTime.hpp:48
rstudio::launcher_plugins::api::AbstractTimedResourceStream
Definition: AbstractTimedResourceStream.hpp:38