wmcpuwatch 0.1
Window Maker dockapp to display the cpu load of all CPUs
|
#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"
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... | |
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
Definition in file wmcpuwatch.c.
#define _GNU_SOURCE |
Use GNU extensions
Definition at line 35 of file wmcpuwatch.c.
#define MAX_CPU (40) |
Maximum number of CPUs: height of the lower frame
Definition at line 51 of file wmcpuwatch.c.
#define MAX_HEIGHT (9) |
Maximum height of one row
Definition at line 52 of file wmcpuwatch.c.
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.
int get_number_of_CPU | ( | FILE * | fpstat | ) |
Returns the number of CPUs.
This function returns the number of logical CPUs in the current system
fpstat | File pointer to open /proc/stat |
Definition at line 394 of file wmcpuwatch.c.
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
fpstat | File pointer to open /proc/stat |
ds | "Array" for the cpu load of all CPUs |
idle | "Array" for the cpu idle time of all CPUs |
ds2 | Field for the average cpu load |
idle2 | Field for average cpu idle time |
Definition at line 311 of file wmcpuwatch.c.
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
actif | CPU load value |
idle | CPU idle value |
line_len | Actual total length of row |
Definition at line 364 of file wmcpuwatch.c.
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
statdevice | Pointer to main stat_dev struct |
cpucount | Number of CPUs |
dockappname | Name of the dockapp |
Definition at line 253 of file wmcpuwatch.c.
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.
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.
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
fpstat | File pointer to open /proc/stat |
st | Pointer to data structure to update |
istat2 | Field used for average and last cpu load |
idle2 | Field used for average and last cpu idle time |
cpucount | Number of CPUs |
Definition at line 278 of file wmcpuwatch.c.
void usage | ( | char * | name | ) |
/brief Show usage
This function shows all possible command line arguments together with a small disclaimer
name | Program name as it was called |
Definition at line 417 of file wmcpuwatch.c.
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.
argc | Number of arguments |
argv | Arguments |
Definition at line 151 of file wmcpuwatch.c.