wmcpuwatch: wmcpuwatch.c File Reference

| 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

Copyright
  GNU General Public License, v3

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

  fpstat | File 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

  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.

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

  actif | CPU load value
  idle | CPU idle value
  line_len | Actual 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

  statdevice | Pointer to main stat_dev struct
  cpucount | Number of CPUs
  dockappname | Name 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

  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.

## ◆ usage()

void usage | ( | char * | name | ) |

/brief Show usage

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

Parameters

  name | Program 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

  argc | Number of arguments
  argv | Arguments

Definition at line 151 of file wmcpuwatch.c.