TSDuck v3.38-3699
MPEG Transport Stream Toolkit
Loading...
Searching...
No Matches
ts::SystemMonitor Class Reference

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

#include <tsSystemMonitor.h>

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

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.
 

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

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 & Destructor Documentation

◆ SystemMonitor()

ts::SystemMonitor::SystemMonitor ( Report report,
const UString config = UString() 
)

Constructor.

Parameters
[in]reportWhere to report log data.
[in]configName of the monitoring configuration file, if different from the default.

◆ ~SystemMonitor()

virtual ts::SystemMonitor::~SystemMonitor ( )
overridevirtual

Destructor.

The monitor thread is stopped.

Member Function Documentation

◆ stop()

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.

◆ 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.

◆ getTypeName()

UString ts::Thread::getTypeName ( ) const
inherited

Get an implementation-specific name of the object class.

Returns
An implementation-specific name of the object class. The result may be not portable. The returned value may be empty before start().

◆ 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()
{
waitForTermination();
}
...
};
Base class for threads.
Definition tsThread.h:39

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.

◆ setTypeName()

void ts::Thread::setTypeName ( const UString name = UString())
protectedinherited

Set the type name.

Parameters
[in]nameThe type name to set. If empty, the subclass type name is used.

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