TSDuck Version 3.15-955 (TSDuck - The MPEG Transport Stream Toolkit)
ts::SystemMonitor Class Reference

Monitoring thread for system resources used by the application. More...

Inheritance diagram for ts::SystemMonitor:
Collaboration diagram for ts::SystemMonitor:

Public Member Functions

 SystemMonitor (Report *report)
 Constructor. More...
 
virtual ~SystemMonitor ()
 Destructor.
 
void getAttributes (ThreadAttributes &attributes)
 Get a copy of the attributes of the thread. More...
 
bool isCurrentThread () const
 Check if the caller is running in the context of this thread. More...
 
bool setAttributes (const ThreadAttributes &attributes)
 Set new attributes to the thread. More...
 
bool start ()
 Start the thread. More...
 
bool waitForTermination ()
 Wait for thread termination. More...
 

Static Public Member Functions

static void Yield ()
 Yield execution of the current thread. More...
 

Detailed Description

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:

  • Up to start + 2 mn, log every 10 seconds
  • Up to start + 10 mn, log every minute
  • Up to start + 20 mn, log every 2 minutes
  • Up to start + 1 hour, log every 5 minutes
  • After start + 1 hour, log every 30 minutes

Constructor & Destructor Documentation

◆ SystemMonitor()

ts::SystemMonitor::SystemMonitor ( Report report)

Constructor.

Parameters
[in]reportWhere to report log data.

Member Function Documentation

◆ setAttributes()

bool ts::Thread::setAttributes ( const ThreadAttributes attributes)
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.

Parameters
[in]attributesNew attributes to set.
Returns
True on success, false on error (if the thread is already started).

◆ getAttributes()

void ts::Thread::getAttributes ( ThreadAttributes attributes)
inherited

Get a copy of the attributes of the thread.

Parameters
[out]attributesAttributes of the thread.

◆ start()

bool ts::Thread::start ( )
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().

Returns
True on success, false on error (operating system error or the thread is already started).

◆ waitForTermination()

bool ts::Thread::waitForTermination ( )
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:

class MyThread: public ts::Thread
{
public:
virtual ~MyThread()
{
}
...
};

Do not use this method if the thread was created with the delete when terminated flag (ts::ThreadAttributes::setDeleteWhenTerminated).

Returns
True on success, false on error. Errors include operating system errors, the thread is not yet started, the caller thread is this thread (waiting for ourself would result in a dead-lock).

◆ isCurrentThread()

bool ts::Thread::isCurrentThread ( ) const
inherited

Check if the caller is running in the context of this thread.

Returns
True if the caller of isCurrentThread() is running in the context of this thread.

◆ Yield()

static void ts::Thread::Yield ( )
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.


The documentation for this class was generated from the following file: