Remoto - VFS: cpuUsage Class Reference
Remoto - VFS

A VFS_application plugin for reporting CPU and RAM usage over time. More...

#include <cpuUsage.h>

Inheritance diagram for cpuUsage:
VFS_application VFS_node

Public Member Functions

Q_INVOKABLE cpuUsage ()
 The cpuUsage constructor. More...
 
virtual ~cpuUsage ()
 
bool isContainer ()
 This is always false. More...
 
- Public Member Functions inherited from VFS_application
Q_INVOKABLE VFS_application (QString settingsRoot="")
 Construct a VFS_application object. More...
 
virtual ~VFS_application ()
 
virtual VFS_nodefind (VFS_request *r)
 Check if a resource (path) is available for this application. More...
 
- Public Member Functions inherited from VFS_node
Q_INVOKABLE VFS_node ()
 The VFS_node constructor will add its instance to the VFS_node::__allNodes global node registry, observing thread safety rules. More...
 
virtual ~VFS_node ()
 VFS_node destructor. More...
 
virtual VFS_nodeappend (QString name, VFS_node *node, bool containerCheck=true, QString user="server")
 Append a VFS_node as a child of this node. More...
 
QString className ()
 Return the class name of a node. More...
 
virtual VFS_requestcreateRequest (VFS_request::requestType type, QString path, QString user="unknown", QJsonDocument data=QJsonDocument(), QJsonObject metadata=QJsonObject(), bool dontDelete=false)
 Create a new VFS_request with this object as _origin. More...
 
VFS_nodefind (QString path)
 Find a node by string path. More...
 
VFS_nodefindChildWithName (QString name)
 Check if a child with a given name exists. More...
 
virtual VFS_nodemount ()
 Mount this node. More...
 
virtual QString reportDetails ()
 Additional details for a generated report. More...
 
QString uniqueChildName (QString name)
 Generate a unique child name. More...
 
virtual VFS_nodeunmount ()
 Unmount this node. More...
 
virtual bool validChildName (QString name)
 Check if a node name is valid. More...
 

Static Public Member Functions

static QString code (QString nodename, QString libname, QString &error)
 Fetch code from this node. More...
 
- Static Public Member Functions inherited from VFS_node
static bool __isNode (VFS_node *)
 Check to see if a node is in the global registry. More...
 
static QString code (QString nodename, QString libname, QString &error)
 Fetch code or any other resource from a node. More...
 

Protected Member Functions

virtual QByteArray icon ()
 Return the icon. More...
 
void timerEvent (QTimerEvent *event)
 Gather the CPU and RAM samples. More...
 
- Protected Member Functions inherited from VFS_application
virtual void ls (VFS_request *r)
 List the contents of this node. More...
 
- Protected Member Functions inherited from VFS_node
virtual void aclDefaults (VFS_request *r)
 Return default values and features associated wth this node. More...
 
void addACLDefault (QJsonObject &acl, bool value, QString description="")
 Add a default value to the acl object. More...
 
void addACLFeature (QJsonObject &acl, QString feature, bool value, QString description="")
 Add a feature to the acl object. More...
 
void addACLFeatureGroup (QJsonObject &acl, QString feature, QString group, bool value)
 Add a feature group to the acl object. More...
 
void addACLFeatureUser (QJsonObject &acl, QString feature, QString user, bool value)
 Add a feature user to the acl object. More...
 
void addACLGroup (QJsonObject &acl, QString group, bool value)
 Add a group to the acl object. More...
 
void addACLUser (QJsonObject &acl, QString user, bool value)
 Add a user to the acl object. More...
 
virtual void issueRequest (VFS_node *target, VFS_request *t)
 Issue a VFS_request to its target. More...
 
virtual void issueRequest (VFS_request *t)
 A convenience function. More...
 
virtual void issueResponse (VFS_request *t)
 Once a request has been completed, issue a response. More...
 
virtual void releaseLock (VFS_request *r)
 Release a lock on this node. More...
 
virtual void report (VFS_request *r)
 Report debugging information about the current state of this node. More...
 
virtual void requestLock (VFS_request *r)
 Request a lock on this node. More...
 
virtual void rm (VFS_request *r)
 Remove a child entry from a node, or the node itself. More...
 
virtual void submit (VFS_request *r)
 Submit a diff to a node. More...
 
virtual void subscribe (VFS_request *r)
 Add an entry to this node's _subscription list. More...
 
virtual void unsubscribe (VFS_request *r)
 Remove an entry from this node's _subscription list. More...
 
virtual void unsubscribePath (QString path)
 Unsubscribe all references to a subpath. More...
 
virtual void write (VFS_request *r)
 Write data to this node. More...
 

Private Slots

virtual void initialize ()
 Start the sample timer. More...
 

Private Member Functions

void getCPUSample (quint64 t)
 Get a CPU sample. More...
 
void getRAMSample (quint64 t)
 Get a RAM sample. More...
 
void getREQSample (quint64 t)
 Take a sample of the current VFS_request::_refcount. More...
 
virtual void metadata (VFS_request *r)
 Fetch the metadata of this node. More...
 
virtual void read (VFS_request *r)
 Return the data contents of this node, or if it's a container call ls() More...
 
QString runCommand (QString which)
 Execute a shell command to gather sample data. More...
 

Private Attributes

QJsonObject _cpu_diff
 The CPU diff. More...
 
QList< QPair< quint64, double > > _cpuSamples
 The CPU samples recorded. More...
 
QString _kernel
 The kernel string reported by Qt. More...
 
int _processors
 The number of processors available on this machine. More...
 
QJsonObject _ram_diff
 The RAM diff. More...
 
QList< QPair< quint64, double > > _ramSamples
 The RAM samples recorded. More...
 
QJsonObject _req_diff
 The VFS_request sample diff. More...
 
QList< QPair< quint64, quint16 > > _reqSamples
 The VFS_request count sample recorded. More...
 
float _scale
 The amount to scale processor values. More...
 

Additional Inherited Members

- Public Slots inherited from VFS_node
virtual void applyDiff (VFS_request *r)
 Apply a diff received via subscription. More...
 
virtual void executeRequest (VFS_request *t)
 Based on the VFS_request::requestType, execute the function associated with an operation. More...
 
void notifySubscribers (VFS_node *origin, VFS_request *t)
 Propagate a diff to subscribers. More...
 
virtual void receiveResponse (VFS_request *t)
 Once a VFS_request has been completed, a response will be issued back to its _origin. More...
 
void remove (bool andDelete)
 Remove a child node. More...
 
virtual void remove (VFS_node *node=nullptr, QString *name=nullptr, QString user="server")
 Remove a child node from this node. More...
 
virtual void subtreeRequest (VFS_request *t)
 find() the target of a VFS_request, and execute the request More...
 
virtual void unsubscribeAll (VFS_node *n)
 Remove all references to a subscriber from this node. More...
 
- Signals inherited from VFS_node
void diff (VFS_node *origin, VFS_request *t)
 Emit a diff, which will trigger notifySubscribers() for a mounted node. More...
 
void finished (bool andDelete=false)
 Emitted if a thread fails to create its node, or a node is rm()'d, or any other reason a node has completed its lifecycle. It is deleted if andDelete==true. More...
 
void mounted ()
 Emitted when a node is mount()ed. More...
 
void unmounted (VFS_node *self)
 Emitted when a node is unmount()ed. More...
 
- Protected Slots inherited from VFS_application
virtual void initialize ()
 The default implementation does nothing. More...
 
- Protected Attributes inherited from VFS_application
QString _settingsRoot
 The base path for future settings. More...
 
- Protected Attributes inherited from VFS_node
VFS_children _children
 This node's children. More...
 
QMutex _lock
 A recursive mutex that is local to this node. More...
 
VFS_subscriptionType _subscribers
 This node's subscribers. These subscribers will receive diff notifications. More...
 

Detailed Description

A VFS_application plugin for reporting CPU and RAM usage over time.

For linux, the sar and bc commands are required to be installed.

Definition at line 12 of file cpuUsage.h.

Constructor & Destructor Documentation

◆ cpuUsage()

cpuUsage::cpuUsage ( )
explicit

The cpuUsage constructor.

This will detect the kernel and the processor count.

Definition at line 25 of file cpuUsage.cpp.

◆ ~cpuUsage()

cpuUsage::~cpuUsage ( )
virtual

Definition at line 55 of file cpuUsage.cpp.

Member Function Documentation

◆ code()

QString cpuUsage::code ( QString  nodename,
QString  libname,
QString &  error 
)
static

Fetch code from this node.

Parameters
nodenameThe nodename or namespace for the request
libnameThe library requested
errorA reference to an error string, for writing errors back to the caller
Returns
The raw source code or resource requested.

Definition at line 141 of file cpuUsage.cpp.

◆ getCPUSample()

void cpuUsage::getCPUSample ( quint64  t)
private

Get a CPU sample.

Parameters
tThe time stamp

This method calls the runCommand() method to gather its data.

Definition at line 192 of file cpuUsage.cpp.

◆ getRAMSample()

void cpuUsage::getRAMSample ( quint64  t)
private

Get a RAM sample.

Parameters
tThe time stamp

This method calls the runCommand() method to gather its data.

Definition at line 211 of file cpuUsage.cpp.

◆ getREQSample()

void cpuUsage::getREQSample ( quint64  t)
private

Take a sample of the current VFS_request::_refcount.

Parameters
tThe time stamp
Todo:
Debug VFS_request and why it doesn't always return to 0 instances, which implies a memory leak

Definition at line 232 of file cpuUsage.cpp.

◆ icon()

QByteArray cpuUsage::icon ( )
protectedvirtual

Return the icon.

Returns
The icon

Reimplemented from VFS_application.

Definition at line 83 of file cpuUsage.cpp.

◆ initialize

void cpuUsage::initialize ( )
privatevirtualslot

Start the sample timer.

Definition at line 63 of file cpuUsage.cpp.

◆ isContainer()

bool cpuUsage::isContainer ( )
virtual

This is always false.

Returns
false

Reimplemented from VFS_node.

Definition at line 73 of file cpuUsage.cpp.

◆ metadata()

void cpuUsage::metadata ( VFS_request r)
privatevirtual

Fetch the metadata of this node.

Parameters
rThe VFS_request object

The base implementation will call icon() to populate the r->_metadata["icon"] field.

Generally, the metadata will want to contain "icon" and "type" fields, but could contain anything. It is recommended that classes call their parent implementation before modifying the metadata:

void myFancyNode::metadata(VFS_request *r)
{
r->_metadata["type"] = "fancy";
//now we have "icon" and "type" entries.
}
virtual void metadata(VFS_request *r)
Fetch the metadata of this node.
Definition: VFS_node.cpp:797
The base class for all requests between nodes.
Definition: VFS_node.h:54
QJsonObject _metadata
the request payload
Definition: VFS_node.h:101
See also
Requests

Reimplemented from VFS_node.

Definition at line 89 of file cpuUsage.cpp.

◆ read()

void cpuUsage::read ( VFS_request r)
privatevirtual

Return the data contents of this node, or if it's a container call ls()

Parameters
rThe VFS_request object

The base class implementation will return no data and _success will be false, except for the case of isContainer()==true, where ls() will be performed.

Data should be written to VFS_request::_data, and can be any JSON content.

Note that if a pane is subscribing to a node, the VFS_client will close panes that receive null as content. Even if you plan to do nothing with the read value of a node, you should provide some non-null data to prevent the pane from closing, or failing to open.

See also
Requests

Reimplemented from VFS_node.

Definition at line 108 of file cpuUsage.cpp.

◆ runCommand()

QString cpuUsage::runCommand ( QString  which)
private

Execute a shell command to gather sample data.

Parameters
whichWhich command is being requested
Returns
The results of the executed shell command.

This uses the _kernel and which values to determine which command to execute.

Definition at line 261 of file cpuUsage.cpp.

◆ timerEvent()

void cpuUsage::timerEvent ( QTimerEvent *  event)
protected

Gather the CPU and RAM samples.

Parameters
eventThe QTimerEvent provided by the timer

Definition at line 157 of file cpuUsage.cpp.

Member Data Documentation

◆ _cpu_diff

QJsonObject cpuUsage::_cpu_diff
private

The CPU diff.

Definition at line 50 of file cpuUsage.h.

◆ _cpuSamples

QList< QPair<quint64,double> > cpuUsage::_cpuSamples
private

The CPU samples recorded.

Definition at line 46 of file cpuUsage.h.

◆ _kernel

QString cpuUsage::_kernel
private

The kernel string reported by Qt.

Definition at line 42 of file cpuUsage.h.

◆ _processors

int cpuUsage::_processors
private

The number of processors available on this machine.

Definition at line 43 of file cpuUsage.h.

◆ _ram_diff

QJsonObject cpuUsage::_ram_diff
private

The RAM diff.

Definition at line 51 of file cpuUsage.h.

◆ _ramSamples

QList< QPair<quint64,double> > cpuUsage::_ramSamples
private

The RAM samples recorded.

Definition at line 47 of file cpuUsage.h.

◆ _req_diff

QJsonObject cpuUsage::_req_diff
private

The VFS_request sample diff.

Definition at line 52 of file cpuUsage.h.

◆ _reqSamples

QList< QPair<quint64,quint16> > cpuUsage::_reqSamples
private

The VFS_request count sample recorded.

Definition at line 48 of file cpuUsage.h.

◆ _scale

float cpuUsage::_scale
private

The amount to scale processor values.

Definition at line 44 of file cpuUsage.h.


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