mirror of
https://github.com/Llewellynvdm/conky.git
synced 2024-11-17 02:25:09 +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:
parent
466dd6f5d4
commit
9ed8bfa28c
@ -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
|
||||
|
78
conky.c
78
conky.c
@ -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,48 @@ static void construct_text_object(const char *s, const char *arg)
|
||||
}
|
||||
else {
|
||||
obj->data.top.num = n-1;
|
||||
top_cpu = 1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
ERR("invalid args given for top");
|
||||
return;
|
||||
}
|
||||
END
|
||||
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 {
|
||||
@ -1792,16 +1835,32 @@ 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
|
||||
=
|
||||
|
6
conky.h
6
conky.h
@ -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;
|
||||
|
||||
|
2
linux.c
2
linux.c
@ -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);
|
||||
}
|
||||
|
47
top.c
47
top.c
@ -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 **);
|
||||
|
||||
|
||||
/******************************************/
|
||||
@ -365,16 +364,17 @@ inline static void calc_cpu_each(int total)
|
||||
*/
|
||||
|
||||
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 */
|
||||
|
||||
@ -392,21 +392,26 @@ inline void process_find_top(struct process **best)
|
||||
* 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<300 && pr->counted) {
|
||||
if(i<sorttmp_size && pr->counted) {
|
||||
sorttmp[i] = pr;
|
||||
i++;
|
||||
}
|
||||
else if (i>299) {
|
||||
/*ERR("too many processes, you will get innaccurate results from top");*/
|
||||
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;
|
||||
if(top_sort_cpu) {
|
||||
for(i=0;i<max-1;i++)
|
||||
{
|
||||
while (sorttmp[i+1]->amount > sorttmp[i]->amount)
|
||||
@ -436,11 +441,29 @@ inline void process_find_top(struct process **best)
|
||||
}
|
||||
for(i=0;i<10;i++)
|
||||
{
|
||||
best[i] = sorttmp[i];
|
||||
cpu[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];
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user