wmcpuwatch  0.1
Window Maker dockapp to display the cpu load of all CPUs
Data Structures | Macros | Functions
wmcpuwatch.c File Reference
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/wait.h>
#include <libdockapp/wmgeneral.h>
#include <libdockapp/misc.h>
#include "ulllib.h"
#include "wmcpuwatch-master.xpm"
#include "wmcpuwatch-mask.xbm"
#include "config.h"
Include dependency graph for wmcpuwatch.c:

Go to the source code of this file.

Data Structures

struct  stat_dev
 Struct to keep CPU load data. More...
 

Macros

#define _GNU_SOURCE
 
#define MAX_CPU   (40)
 
#define MAX_HEIGHT   (9)
 

Functions

void usage (char *)
 
void print_version (void)
 Definition of current version. More...
 
void wmcpuwatch (int argc, char **argv)
 Actual function for the dockapp. More...
 
void clear_widgets (void)
 Clear both widgets. More...
 
void initialize_stat_device (stat_dev *statdevice, int cpucount, const char *dockappname)
 Initialize stat_device struct. More...
 
int get_number_of_CPU (FILE *fpstat)
 Returns the number of CPUs. More...
 
void get_statistics (FILE *fpstat, ullong *ds, ullong *idle, ullong *ds2, ullong *idle2)
 Parses /proc/stat and gets required values. More...
 
void update_stat_cpu (FILE *fpstat, stat_dev *st, ullong *istat2, ullong *idle2, int cpucount)
 Update CPU stats. More...
 
unsigned long get_width (long actif, long idle, long line_len)
 Get widht of active part. More...
 
int main (int argc, char *argv[])
 Main function. More...
 

Detailed Description

This is the main (and only source) file for the wmcpuwatch dockapp.

The code is based on wmmon, but lots of code has been removed, only the CPU code was left.

See the ChangeLog file for changes

Author
wmmon authors
Andreas Tscharner andy@.nosp@m.vis..nosp@m.ethz..nosp@m.ch
Date
2017-09-03

Definition in file wmcpuwatch.c.

Macro Definition Documentation

◆ _GNU_SOURCE

#define _GNU_SOURCE

Use GNU extensions

Definition at line 35 of file wmcpuwatch.c.

◆ MAX_CPU

#define MAX_CPU   (40)

Maximum number of CPUs: height of the lower frame

Definition at line 51 of file wmcpuwatch.c.

◆ MAX_HEIGHT

#define MAX_HEIGHT   (9)

Maximum height of one row

Definition at line 52 of file wmcpuwatch.c.

Function Documentation

◆ clear_widgets()

void clear_widgets ( void  )

Clear both widgets.

This function clears the upper right (smaller) widget for the average load over all CPUs and the lower (big) widget for the load of all CPUs

Definition at line 230 of file wmcpuwatch.c.

◆ get_number_of_CPU()

int get_number_of_CPU ( FILE *  fpstat)

Returns the number of CPUs.

This function returns the number of logical CPUs in the current system

Parameters
fpstatFile pointer to open /proc/stat
Returns
Number of logical CPUs

Definition at line 394 of file wmcpuwatch.c.

◆ get_statistics()

void get_statistics ( FILE *  fpstat,
ullong *  ds,
ullong *  idle,
ullong *  ds2,
ullong *  idle2 
)

Parses /proc/stat and gets required values.

This function parses /proc/stat and saves the required values to the given variables

Parameters
fpstatFile pointer to open /proc/stat
ds"Array" for the cpu load of all CPUs
idle"Array" for the cpu idle time of all CPUs
ds2Field for the average cpu load
idle2Field for average cpu idle time

Definition at line 311 of file wmcpuwatch.c.

◆ get_width()

unsigned long get_width ( long  actif,
long  idle,
long  line_len 
)

Get widht of active part.

This functions returns the width of the active part of the row

Parameters
actifCPU load value
idleCPU idle value
line_lenActual total length of row
Returns
Length in pixels of active part

Definition at line 364 of file wmcpuwatch.c.

◆ initialize_stat_device()

void initialize_stat_device ( stat_dev statdevice,
int  cpucount,
const char *  dockappname 
)

Initialize stat_device struct.

This function initializes and allocates memory for the main structure for the device stats

Parameters
statdevicePointer to main stat_dev struct
cpucountNumber of CPUs
dockappnameName of the dockapp

Definition at line 253 of file wmcpuwatch.c.

◆ main()

int main ( int  argc,
char *  argv[] 
)

Main function.

The main function parses the command line parameters and starts the actual dockapp

Definition at line 108 of file wmcpuwatch.c.

◆ print_version()

void print_version ( void  )

Definition of current version.

Shows the current version of the dockapp.

Definition of the current program version

Definition at line 441 of file wmcpuwatch.c.

◆ update_stat_cpu()

void update_stat_cpu ( FILE *  fpstat,
stat_dev st,
ullong *  istat2,
ullong *  idle2,
int  cpucount 
)

Update CPU stats.

This function is used to update the given data

Parameters
fpstatFile pointer to open /proc/stat
stPointer to data structure to update
istat2Field used for average and last cpu load
idle2Field used for average and last cpu idle time
cpucountNumber of CPUs

Definition at line 278 of file wmcpuwatch.c.

◆ usage()

void usage ( char *  name)

/brief Show usage

This function shows all possible command line arguments together with a small disclaimer

Parameters
nameProgram name as it was called

Definition at line 417 of file wmcpuwatch.c.

◆ wmcpuwatch()

void wmcpuwatch ( int  argc,
char **  argv 
)

Actual function for the dockapp.

This is the actual function for the dockapp. It initializes all the data and contains the main loop.

Parameters
argcNumber of arguments
argvArguments

Definition at line 151 of file wmcpuwatch.c.