1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2024-11-16 18:15:17 +00:00

dum de dum

git-svn-id: https://conky.svn.sourceforge.net/svnroot/conky/trunk/conky@12 7f574dfc-610e-0410-a909-a81674777703
This commit is contained in:
Brenden Matthews 2005-07-25 00:22:16 +00:00
parent 466dd6f5d4
commit 9ed8bfa28c
7 changed files with 191 additions and 110 deletions

View File

@ -4,6 +4,8 @@
* Fixed the problem with total_run_times
* Fixed alignment of bars and lines and stuff
* Reduced conky's memory usage (yay!)
* Removed top_sort_cpu, added top_mem which sorts by mem usage instead
of cpu
2005-07-17
* Fixed a pile of bugs in configure script

80
conky.c
View File

@ -404,6 +404,7 @@ enum text_object_type {
OBJ_if_mounted,
OBJ_if_running,
OBJ_top,
OBJ_top_mem,
OBJ_tail,
OBJ_kernel,
OBJ_loadavg,
@ -799,6 +800,7 @@ static void construct_text_object(const char *s, const char *arg)
}
else {
obj->data.top.num = n-1;
top_cpu = 1;
}
}
else {
@ -806,7 +808,48 @@ static void construct_text_object(const char *s, const char *arg)
return;
}
END
OBJ(addr, INFO_NET)
OBJ(top_mem, INFO_TOP)
char buf[64];
int n;
if(!arg) {
ERR("top_mem needs arguments");
obj->type = OBJ_text;
obj->data.s = strdup("${top_mem}");
return;
}
if(sscanf(arg, "%63s %i", buf, &n) == 2) {
if(strcmp(buf, "name") == 0) {
obj->data.top.type = TOP_NAME;
}
else if(strcmp(buf, "cpu") == 0) {
obj->data.top.type = TOP_CPU;
}
else if(strcmp(buf, "pid") == 0) {
obj->data.top.type = TOP_PID;
}
else if(strcmp(buf, "mem") == 0) {
obj->data.top.type = TOP_MEM;
}
else
{
ERR("invalid arg for top");
return;
}
if(n < 1 || n > 10) {
CRIT_ERR("invalid arg for top");
return;
}
else {
obj->data.top.num = n-1;
top_mem = 1;
}
}
else {
ERR("invalid args given for top");
return;
}
END
OBJ(addr, INFO_NET)
obj->data.net = get_net_stat(arg);
END
OBJ(linkstatus, INFO_WIFI)
@ -1792,18 +1835,34 @@ static void generate_text()
if (obj->data.top.type == TOP_NAME && obj->data.top.num >= 0 && obj->data.top.num < 10){
// if we limit the buffer and add a bunch of space after, it stops the thing from
// moving other shit around, which is really fucking annoying
snprintf(p, 17, "%s ", cur->tops[obj->data.top.num]->name);
snprintf(p, 17, "%s ", cur->cpu[obj->data.top.num]->name);
}
else if (obj->data.top.type == TOP_CPU && obj->data.top.num >= 0 && obj->data.top.num < 10) {
snprintf(p, 7, "%3.2f ", cur->tops[obj->data.top.num]->amount);
snprintf(p, 7, "%3.2f ", cur->cpu[obj->data.top.num]->amount);
}
else if (obj->data.top.type == TOP_PID && obj->data.top.num >= 0 && obj->data.top.num < 10) {
snprintf(p, 8, "%i ", cur->tops[obj->data.top.num]->pid);
snprintf(p, 8, "%i ", cur->cpu[obj->data.top.num]->pid);
}
else if (obj->data.top.type == TOP_MEM && obj->data.top.num >= 0 && obj->data.top.num < 10) {
snprintf(p, 7, "%3.2f ", cur->tops[obj->data.top.num]->totalmem);
snprintf(p, 7, "%3.2f ", cur->cpu[obj->data.top.num]->totalmem);
}
}
OBJ(top_mem) {
if (obj->data.top.type == TOP_NAME && obj->data.top.num >= 0 && obj->data.top.num < 10){
// if we limit the buffer and add a bunch of space after, it stops the thing from
// moving other shit around, which is really fucking annoying
snprintf(p, 17, "%s ", cur->memu[obj->data.top.num]->name);
}
else if (obj->data.top.type == TOP_CPU && obj->data.top.num >= 0 && obj->data.top.num < 10) {
snprintf(p, 7, "%3.2f ", cur->memu[obj->data.top.num]->amount);
}
else if (obj->data.top.type == TOP_PID && obj->data.top.num >= 0 && obj->data.top.num < 10) {
snprintf(p, 8, "%i ", cur->memu[obj->data.top.num]->pid);
}
else if (obj->data.top.type == TOP_MEM && obj->data.top.num >= 0 && obj->data.top.num < 10) {
snprintf(p, 7, "%3.2f ", cur->memu[obj->data.top.num]->totalmem);
}
}
@ -2448,7 +2507,7 @@ static void update_text()
static void main_loop()
{
Region region = XCreateRegion();
info.looped = -1;
info.looped = 0;
while (total_run_times == 0 || info.looped < total_run_times-1) {
info.looped++;
XFlush(display);
@ -2819,13 +2878,14 @@ static void set_default_configurations(void)
info.cpu_avg_samples = 2;
info.net_avg_samples = 2;
info.memmax = 0;
top_cpu = 0;
top_mem = 0;
#ifdef MPD
strcpy(info.mpd.host, "localhost");
info.mpd.port = 6600;
info.mpd.status = "Checking status...";
#endif
out_to_console = 0;
top_sort_cpu = 1;
use_spacer = 0;
default_fg_color = WhitePixel(display, screen);
default_bg_color = BlackPixel(display, screen);
@ -3085,12 +3145,6 @@ else if (strcasecmp(name, a) == 0 || strcasecmp(name, a) == 0)
string_to_bool
(value);
}
CONF("top_sort_cpu") {
top_sort_cpu
=
string_to_bool
(value);
}
CONF("use_spacer") {
use_spacer
=

View File

@ -145,7 +145,8 @@ struct information {
struct mpd_s mpd;
mpd_Connection *conn;
#endif
struct process *tops[10];
struct process *cpu[10];
struct process *memu[10];
unsigned long looped;
};
@ -191,7 +192,8 @@ extern int use_xdbe;
int out_to_console;
int top_sort_cpu;
int top_cpu;
int top_mem;
int use_spacer;

View File

@ -1028,5 +1028,5 @@ void get_battery_stuff(char *buf, unsigned int n, const char *bat)
void update_top()
{
show_nice_processes = 1;
process_find_top(info.tops);
process_find_top(info.cpu, info.memu);
}

View File

@ -129,7 +129,7 @@ void *fetch_ftp( ) {
}
else {
ftp_ok = 0;
}
}
} while (ftp_ok == 0 && tries < 3);
status = 1;
@ -140,7 +140,7 @@ static pthread_t thread1;
void update_metar() {
int iret1;
if (!status) {
status = 2;
status = 2;
iret1 = pthread_create( &thread1, NULL, fetch_ftp, NULL);
}
else if (status == 2) { /* thread is still running. what else can we do? */

205
top.c
View File

@ -17,16 +17,16 @@ static struct process *find_process(pid_t pid)
}
/*
* Create a new process object and insert it into the process list
*/
* Create a new process object and insert it into the process list
*/
static struct process *new_process(int p)
{
struct process *process;
process = malloc(sizeof(struct process));
/*
* Do stitching necessary for doubly linked list
*/
* Do stitching necessary for doubly linked list
*/
process->name = 0;
process->previous = 0;
process->next = first_process;
@ -40,7 +40,7 @@ static struct process *new_process(int p)
process->previous_kernel_time = INT_MAX;
process->counted = 1;
/* process_find_name(process);*/
/* process_find_name(process);*/
return process;
}
@ -57,7 +57,6 @@ static void delete_process(struct process *);
/*inline void draw_processes(void);*/
static int calc_cpu_total(void);
static void calc_cpu_each(int);
void process_find_top(struct process **);
/******************************************/
@ -65,9 +64,9 @@ void process_find_top(struct process **);
/******************************************/
/*
* These are the guts that extract information out of /proc.
* Anyone hoping to port wmtop should look here first.
*/
* These are the guts that extract information out of /proc.
* Anyone hoping to port wmtop should look here first.
*/
static int process_parse_stat(struct process *process)
{
struct information *cur;
@ -195,15 +194,15 @@ static int update_process_table()
++g_time;
/*
* Get list of processes from /proc directory
*/
* Get list of processes from /proc directory
*/
while ((entry = readdir(dir))) {
pid_t pid;
if (!entry) {
/*
* Problem reading list of processes
*/
* Problem reading list of processes
*/
closedir(dir);
return 1;
}
@ -229,9 +228,9 @@ static int update_process_table()
/******************************************/
/*
* This function seems to hog all of the CPU time. I can't figure out why - it
* doesn't do much.
*/
* This function seems to hog all of the CPU time. I can't figure out why - it
* doesn't do much.
*/
static int calculate_cpu(struct process *process)
{
int rc;
@ -245,11 +244,11 @@ static int calculate_cpu(struct process *process)
return 1;*/
/*
* Check name against the exclusion list
*/
* Check name against the exclusion list
*/
if (process->counted && exclusion_expression
&& !regexec(exclusion_expression, process->name, 0, 0, 0))
process->counted = 0;
&& !regexec(exclusion_expression, process->name, 0, 0, 0))
process->counted = 0;
return 0;
}
@ -271,8 +270,8 @@ static void process_cleanup()
p = p->next;
/*
* Delete processes that have died
*/
* Delete processes that have died
*/
if (current->time_stamp != g_time)
delete_process(current);
}
@ -288,14 +287,14 @@ static void delete_process(struct process *p)
assert(p->id == 0x0badfeed);
/*
* Ensure that deleted processes aren't reused.
*/
* Ensure that deleted processes aren't reused.
*/
p->id = 0x007babe;
#endif /* defined(PARANOID) */
/*
* Maintain doubly linked list.
*/
* Maintain doubly linked list.
*/
if (p->next)
p->next->previous = p->previous;
if (p->previous)
@ -346,12 +345,12 @@ inline static void calc_cpu_each(int total)
struct process *p = first_process;
while (p) {
/*p->amount = total ?
(100.0 * (float) (p->user_time + p->kernel_time) /
total) : 0;*/
p->amount = (100.0 * (p->user_time + p->kernel_time) / total);
(100.0 * (float) (p->user_time + p->kernel_time) /
total) : 0;*/
p->amount = (100.0 * (p->user_time + p->kernel_time) / total);
/* if (p->amount > 100)
p->amount = 0;*/
p->amount = 0;*/
p = p->next;
}
}
@ -361,20 +360,21 @@ inline static void calc_cpu_each(int total)
/******************************************/
/*
* Result is stored in decreasing order in best[0-9].
*/
* Result is stored in decreasing order in best[0-9].
*/
static struct process **sorttmp;
static size_t sorttmp_size = 10;
inline void process_find_top(struct process **best)
inline void process_find_top(struct process **cpu, struct process **mem)
{
struct process *pr;
if (sorttmp == NULL) {
sorttmp = malloc(sizeof(struct process)*10);
sorttmp = malloc(sizeof(struct process)*sorttmp_size);
assert(sorttmp != NULL);
}
int total;
int i, max;
unsigned int i, max;
total = calc_cpu_total(); /* calculate the total of the processor */
@ -383,64 +383,87 @@ inline void process_find_top(struct process **best)
process_cleanup(); /* cleanup list from exited processes */
/*
* this is really ugly,
* not to mention probably not too efficient.
* the main problem is that there could be any number of processes,
* however we have to use a fixed size for the "best" array.
* right now i can't think of a better way to do this,
* although i'm sure there is one.
* Perhaps just using a linked list would be more effecient?
* I'm too fucking lazy to do that right now.
*/
pr = first_process;
i = 0;
while(pr) {
if(i<300 && pr->counted) {
sorttmp[i] = pr;
i++;
}
else if (i>299) {
/*ERR("too many processes, you will get innaccurate results from top");*/
break;
}
pr = pr->next;
}
max = i;
if(top_sort_cpu) {
for(i=0;i<max-1;i++)
{
while (sorttmp[i+1]->amount > sorttmp[i]->amount)
{
pr = sorttmp[i];
sorttmp[i] = sorttmp[i+1];
sorttmp[i+1] = pr;
if (i>0)
i--;
else
break;
}
}
for(i=max;i>1;i--);
{
while (sorttmp[i]->amount > sorttmp[i-1]->amount)
{
pr = sorttmp[i];
sorttmp[i] = sorttmp[i-1];
sorttmp[i-1] = pr;
if (i<max)
* this is really ugly,
* not to mention probably not too efficient.
* the main problem is that there could be any number of processes,
* however we have to use a fixed size for the "best" array.
* right now i can't think of a better way to do this,
* although i'm sure there is one.
* Perhaps just using a linked list would be more effecient?
* I'm too fucking lazy to do that right now.
*/
if(top_cpu) {
pr = first_process;
i = 0;
while(pr) {
if(i<sorttmp_size && pr->counted) {
sorttmp[i] = pr;
i++;
else
break;
}
else if (i == sorttmp_size && pr->counted) {
sorttmp_size++;
sorttmp = realloc(sorttmp, sizeof(struct process)*sorttmp_size);
sorttmp[i] = pr;
i++;
}
pr = pr->next;
}
if (i+1 < sorttmp_size) {
sorttmp = realloc(sorttmp, sizeof(struct process)*sorttmp_size);
}
max = i;
for(i=0;i<max-1;i++)
{
while (sorttmp[i+1]->amount > sorttmp[i]->amount)
{
pr = sorttmp[i];
sorttmp[i] = sorttmp[i+1];
sorttmp[i+1] = pr;
if (i>0)
i--;
else
break;
}
}
for(i=max;i>1;i--);
{
while (sorttmp[i]->amount > sorttmp[i-1]->amount)
{
pr = sorttmp[i];
sorttmp[i] = sorttmp[i-1];
sorttmp[i-1] = pr;
if (i<max)
i++;
else
break;
}
}
for(i=0;i<10;i++)
{
cpu[i] = sorttmp[i];
}
}
for(i=0;i<10;i++)
{
best[i] = sorttmp[i];
}
}
else {
if (top_mem) {
pr = first_process;
i = 0;
while(pr) {
if(i<sorttmp_size && pr->counted) {
sorttmp[i] = pr;
i++;
}
else if (i == sorttmp_size && pr->counted) {
sorttmp_size++;
sorttmp = realloc(sorttmp, sizeof(struct process)*sorttmp_size);
sorttmp[i] = pr;
i++;
}
pr = pr->next;
}
if (i+1 < sorttmp_size) {
sorttmp = realloc(sorttmp, sizeof(struct process)*sorttmp_size);
} max = i;
for(i=0;i<max-1;i++)
{
while (sorttmp[i+1]->totalmem > sorttmp[i]->totalmem)
@ -470,7 +493,7 @@ inline void process_find_top(struct process **best)
}
for(i=0;i<10;i++)
{
best[i] = sorttmp[i];
mem[i] = sorttmp[i];
}
}

2
top.h
View File

@ -81,4 +81,4 @@
/*
* Pointer to head of process list
*/
void process_find_top(struct process **);
void process_find_top(struct process **, struct process **);