TSDuck v3.40-3965
MPEG Transport Stream Toolkit
|
Monitoring thread for system resources used by the application. More...
#include <tsSystemMonitor.h>
Public Member Functions | |
SystemMonitor (Report &report, const UString &config=UString()) | |
Constructor. | |
virtual | ~SystemMonitor () override |
Destructor. | |
void | getAttributes (ThreadAttributes &attributes) |
Get a copy of the attributes of the thread. | |
UString | getTypeName () const |
Get an implementation-specific name of the object class. | |
bool | isCurrentThread () const |
Check if the caller is running in the context of this thread. | |
bool | setAttributes (const ThreadAttributes &attributes) |
Set new attributes to the thread. | |
bool | start () |
Start the thread. | |
void | stop () |
Stop the monitor thread. | |
bool | waitForTermination () |
Wait for thread termination. | |
Static Public Member Functions | |
static void | Yield () |
Yield execution of the current thread. | |
Protected Member Functions | |
void | setTypeName (const UString &name=UString()) |
Set the type name. | |
Monitoring thread for system resources used by the application.
This class starts an internal thread which periodically wakes up and reports the usage of system resources by the current process (virtual memory usage, CPU load). In addition to precise usage values, it also displays an analysis of the virtual memory usage (such as stable or leaking).
The reporting interval is changing over time, very fast at the start of the application, then slower and slower:
This class derives from Thread. The methods start() and waitForTermination() are inherited. The destructor stops the thread and synchronously waits for its termination. The method stop() can be used to stop the thread.
Constructor.
[in] | report | Where to report log data. |
[in] | config | Name of the monitoring configuration file, if different from the default. |
|
overridevirtual |
Destructor.
The monitor thread is stopped.
void ts::SystemMonitor::stop | ( | ) |
Stop the monitor thread.
The monitor thread is requested to stop. This method returns immediately, use waitForTermination() to synchronously wait for its termination.
|
inherited |
Set new attributes to the thread.
New attributes can be set as long as the thread is not started, i.e. as long as start() is not invoked.
[in] | attributes | New attributes to set. |
|
inherited |
Get a copy of the attributes of the thread.
[out] | attributes | Attributes of the thread. |
|
inherited |
Get an implementation-specific name of the object class.
|
inherited |
Start the thread.
The operating system thread is created and started. The code which is executed in the context of this thread is in the method main().
|
inherited |
Wait for thread termination.
The thread which invokes this method is blocked until the execution of this thread object completes.
Only one waiter thread is allowed. If several threads concurrently invoke waitForTermination() on the same Thread object, only the first one will wait. The method waitForTermination() returns an error to all other threads.
This method is automatically invoked in the destructor. Thus, when a Thread object is declared in a control block and the thread has been started, the end of the control block hangs as long as the thread is not terminated. If the thread has not been started, however, the destructor does not wait (otherwise it would hang for ever).
Important: When a subclass of Thread has non-static members, its destructor shall invoke waitForTermination(). Thus, it prevents its members from being destructed until the thread terminates. If the destructor of the subclass does not invoke waitForTermination() and the Thread object goes out of scope before the termination of the thread, the subclass part of the object is destroyed. Any attempt to access non-static members from the main() method in the context of the thread will give unexpected results. Most of the time, this will result in an error similar to "pure virtual method called". To avoid this:
Do not use this method if the thread was created with the delete when terminated flag (ts::ThreadAttributes::setDeleteWhenTerminated).
|
inherited |
Check if the caller is running in the context of this thread.
|
staticinherited |
Yield execution of the current thread.
Execution is passed to another thread, if any is waiting for execution. This should not change the behaviour of correctly-written applications.
Set the type name.
[in] | name | The type name to set. If empty, the subclass type name is used. |