Ocean
Process.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) Meta Platforms, Inc. and affiliates.
3  *
4  * This source code is licensed under the MIT license found in the
5  * LICENSE file in the root directory of this source tree.
6  */
7 
8 #ifndef META_OCEAN_SYSTEM_PROCESS_H
9 #define META_OCEAN_SYSTEM_PROCESS_H
10 
11 #include "ocean/system/System.h"
12 
13 #include "ocean/base/Singleton.h"
14 
15 namespace Ocean
16 {
17 
18 namespace System
19 {
20 
21 /**
22  * This class implements basic functions related with the application process.
23  * @ingroup system
24  */
25 class OCEAN_SYSTEM_EXPORT Process : public Singleton<Process>
26 {
27  friend class Singleton<Process>;
28 
29  public:
30 
31  /**
32  * Definition of different process priority values.
33  */
35  {
36  /// The process runs if the system is idle.
38  /// The process has a priority below normal.
40  /// The process has a normal priority.
42  /// The process has a priority above normal.
44  /// The process has a high priority.
46  /// The process has a realtime priority.
47  PRIORITY_REALTIME
48  };
49 
50  public:
51 
52  /**
53  * Returns the processor load since the last call to this function.
54  * @return Current processor load in percent, with range [0.0, 1.0]
55  */
56  float currentProcessorLoad() const;
57 
58  /**
59  * Returns the average processor load of this process since the creation.
60  * @return Average processor load in percent, with range [0.0, 1.0]
61  */
62  float averageProcessorLoad() const;
63 
64  /**
65  * Returns the entire processor time of this process since the creation.
66  * @return Entire processor time in seconds
67  */
68  static double entireProcessorTime();
69 
70  /**
71  * Returns the live time of this process since the creation.
72  * @return Live time in seconds
73  */
74  static double entireProcessLiveTime();
75 
76  /**
77  * Returns the start time of this process since 01.01.1970 00:00:00 in UTC time.
78  * @return Start time in microseconds
79  */
80  static long long processStartTime();
81 
82  /**
83  * Returns the priority of the process.
84  * @return Process priority
85  * @exception NotSupportedException Is thrown if this function is not supported
86  */
88 
89  /**
90  * Sets the priority of the process.
91  * @param priority Process priority to set
92  * @return True, if succeeded
93  */
94  static bool setPriority(const ProcessPriority priority);
95 
96  /**
97  * Returns the process id of the current (calling) process.
98  * @return The process id of the current process
99  */
100  static unsigned int currentProcessId();
101 
102  private:
103 
104  /**
105  * Creates a new process object.
106  * As this class is a singleton get access to this object by the singleton.
107  */
109 
110  private:
111 
112  /// Time of most recent processor load request.
113  mutable int64_t loadTimestamp_ = 0ll;
114 
115  /// Processor user time of most recent processor load request.
116  mutable int64_t loadTime_ = 0ll;
117 
118  /// Number of real CPU cores available in this system.
119  const unsigned int numberCores_ = 0u;
120 };
121 
122 }
123 
124 }
125 
126 #endif // META_OCEAN_SYSTEM_PROCESS_H
This template class is the base class for all singleton objects.
Definition: Singleton.h:71
This class implements basic functions related with the application process.
Definition: Process.h:26
Process()
Creates a new process object.
static ProcessPriority priority()
Returns the priority of the process.
static bool setPriority(const ProcessPriority priority)
Sets the priority of the process.
static double entireProcessorTime()
Returns the entire processor time of this process since the creation.
static double entireProcessLiveTime()
Returns the live time of this process since the creation.
float currentProcessorLoad() const
Returns the processor load since the last call to this function.
static long long processStartTime()
Returns the start time of this process since 01.01.1970 00:00:00 in UTC time.
float averageProcessorLoad() const
Returns the average processor load of this process since the creation.
ProcessPriority
Definition of different process priority values.
Definition: Process.h:35
@ PRIORITY_NORMAL
The process has a normal priority.
Definition: Process.h:41
@ PRIORITY_BELOW_NORMAL
The process has a priority below normal.
Definition: Process.h:39
@ PRIORITY_IDLE
The process runs if the system is idle.
Definition: Process.h:37
@ PRIORITY_HIGH
The process has a high priority.
Definition: Process.h:45
@ PRIORITY_ABOVE_NORMAL
The process has a priority above normal.
Definition: Process.h:43
static unsigned int currentProcessId()
Returns the process id of the current (calling) process.
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15