📄 data.h
字号:
#define NUMBER_PROCESSES 5#include <unistd.h>#include <glib.h>#include <glibtop.h>#include <glibtop/cpu.h>#include <glibtop/netload.h>#include <glibtop/mem.h>#include <glibtop/mountlist.h>#include <glibtop/fsusage.h>#include "processes.h"/** * We save one copy of glibtop_cpu to calculate the difference of jiffies * between two invocations. */typedef struct _cpustorage cpustorage;struct _cpustorage{ glibtop_cpu *olddata;};/** * We save one copy of glibtop_netload per network-device to calculate the * amount of data which passed through the device between the two invocations. * * This is a linked list since we want to hold the data for multiple network * devices */typedef struct _netloadstorage netstorage;struct _netloadstorage{ glibtop_netload *olddata; netstorage *next; // pointer to next network-device};/** * This structure holds all the data about cpu usage in percent. * * First knot is the summ of all cpus and every next knot represents * one cpu. First knot only on single-cpu-systems. */typedef struct _cpuusage cpuusage;struct _cpuusage{ float total, user, nice, sys, idle, frequency; cpuusage *next; // pointer to next cpu};/** * Structure to hold the usage of network-devices. * * Same order as in netstorage. */typedef struct _netload netload;struct _netload{ char device[40]; int bytes_in, bytes_out, packets_in, packets_out, errors_in, errors_out, collisions; netload *next;};/** * list of filesystems and their data */typedef struct _csm_fsinfo csm_fsinfo;struct _csm_fsinfo{ char devname[GLIBTOP_MOUNTENTRY_LEN + 1]; char mountdir[GLIBTOP_MOUNTENTRY_LEN + 1]; char type[GLIBTOP_MOUNTENTRY_LEN + 1]; glibtop_fsusage *fsusage; int touched; csm_fsinfo *next, *prev;};/** * This is the applications main data-storage */typedef struct _database database;struct _database{ // cpu specific things (beware, this is a linked list with one cpu each) cpuusage *Lcpu; cpustorage *Scpu; // memory usage glibtop_mem *memoryusage; // netload (beware, this is a linked list with one device each) netload *Lnetload; netstorage *Snetload; // this is a linked list of processes process *Lprocess; // top n processes process *Tprocess[NUMBER_PROCESSES]; // list of mounted filesystems csm_fsinfo *fsinfo;};/** * Methods which update the data storage */void calc_cpu (database * data);void calc_net (database * data);void calc_mem (database * data);void calc_disk (database * data);void calc_top_processes (database * data);/** * Utitity methods */void init_csm ();// create main data storage (already filled with content)database *init_database ();void free_database (database * data);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -