mirror of
https://github.com/Llewellynvdm/conky.git
synced 2024-12-28 13:00:45 +00:00
Usable state reached (use top.cc + minor changes)
* process* management left to top.cc * compile with -Wall -Werror (lots of wasted time for stupid errors) * unify find_process() and new_process(), as used always together Signed-off-by: Pavel Labath <pavelo@centrum.sk>
This commit is contained in:
parent
98196d0e6b
commit
9268165d71
@ -113,7 +113,7 @@ int update_uname(void)
|
|||||||
strcpy(info.uname_v, strsep(&start, " "));
|
strcpy(info.uname_v, strsep(&start, " "));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (errno == ENOMEM) printf("desc_n %d\n", desc_n);
|
if (errno == ENOMEM) printf("desc_n %lu\n", desc_n);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -1209,7 +1209,7 @@ struct text_object *construct_text_object(char *s, const char *arg,
|
|||||||
extract_object_args_to_sub(obj, arg);
|
extract_object_args_to_sub(obj, arg);
|
||||||
obj->callbacks.print = &print_pid_write;
|
obj->callbacks.print = &print_pid_write;
|
||||||
#ifdef __DragonFly__
|
#ifdef __DragonFly__
|
||||||
END OBJ(processes, &update_tmp_top)
|
END OBJ(processes, &update_top)
|
||||||
#else
|
#else
|
||||||
END OBJ(processes, &update_total_processes)
|
END OBJ(processes, &update_total_processes)
|
||||||
#endif
|
#endif
|
||||||
@ -1226,7 +1226,7 @@ struct text_object *construct_text_object(char *s, const char *arg,
|
|||||||
obj->callbacks.print = &print_running_threads;
|
obj->callbacks.print = &print_running_threads;
|
||||||
#else
|
#else
|
||||||
#if defined(__DragonFly__)
|
#if defined(__DragonFly__)
|
||||||
END OBJ(running_processes, &update_tmp_top)
|
END OBJ(running_processes, &update_top)
|
||||||
obj->callbacks.print = &print_running_processes;
|
obj->callbacks.print = &print_running_processes;
|
||||||
#else
|
#else
|
||||||
END OBJ(running_processes, &update_running_processes)
|
END OBJ(running_processes, &update_running_processes)
|
||||||
|
11
src/linux.cc
11
src/linux.cc
@ -2812,15 +2812,8 @@ static void update_process_table(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (sscanf(entry->d_name, "%d", &pid) > 0) {
|
if (sscanf(entry->d_name, "%d", &pid) > 0) {
|
||||||
struct process *p;
|
/* compute each process cpu usage */
|
||||||
|
calculate_stats(get_process(pid));
|
||||||
p = find_process(pid);
|
|
||||||
if (!p) {
|
|
||||||
p = new_process(pid);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* compute each process cpu usage */
|
|
||||||
calculate_stats(p);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
64
src/top.cc
64
src/top.cc
@ -75,7 +75,6 @@ static void unhash_process(struct process *p)
|
|||||||
|
|
||||||
/* get the bucket head */
|
/* get the bucket head */
|
||||||
phe = &proc_hash_table[p->pid & (HTABSIZE - 1)];
|
phe = &proc_hash_table[p->pid & (HTABSIZE - 1)];
|
||||||
|
|
||||||
/* find the entry pointing to p and drop it */
|
/* find the entry pointing to p and drop it */
|
||||||
while (phe->next) {
|
while (phe->next) {
|
||||||
if (phe->next->proc == p) {
|
if (phe->next->proc == p) {
|
||||||
@ -138,7 +137,7 @@ struct process *get_process_by_name(const char *name)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct process *find_process(pid_t pid)
|
static struct process *find_process(pid_t pid)
|
||||||
{
|
{
|
||||||
struct proc_hash_entry *phe;
|
struct proc_hash_entry *phe;
|
||||||
|
|
||||||
@ -148,43 +147,56 @@ struct process *find_process(pid_t pid)
|
|||||||
return phe->next->proc;
|
return phe->next->proc;
|
||||||
phe = phe->next;
|
phe = phe->next;
|
||||||
}
|
}
|
||||||
return 0;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Create a new process object and insert it into the process list */
|
static struct process *new_process(pid_t pid)
|
||||||
struct process *new_process(int p)
|
|
||||||
{
|
{
|
||||||
struct process *process;
|
struct process *p = (struct process *) malloc(sizeof(struct process));
|
||||||
process = (struct process *) malloc(sizeof(struct process));
|
|
||||||
|
|
||||||
// clean up memory first
|
|
||||||
memset(process, 0, sizeof(struct process));
|
|
||||||
|
|
||||||
/* Do stitching necessary for doubly linked list */
|
/* Do stitching necessary for doubly linked list */
|
||||||
process->name = 0;
|
p->previous = NULL;
|
||||||
process->previous = 0;
|
p->next = first_process;
|
||||||
process->next = first_process;
|
if (p->next) {
|
||||||
if (process->next) {
|
p->next->previous = p;
|
||||||
process->next->previous = process;
|
|
||||||
}
|
}
|
||||||
first_process = process;
|
first_process = p;
|
||||||
|
|
||||||
process->pid = p;
|
p->pid = pid;
|
||||||
process->time_stamp = 0;
|
p->name = 0;
|
||||||
process->previous_user_time = ULONG_MAX;
|
p->amount = 0;
|
||||||
process->previous_kernel_time = ULONG_MAX;
|
p->user_time = 0;
|
||||||
|
p->total = 0;
|
||||||
|
p->kernel_time = 0;
|
||||||
|
p->previous_user_time = ULONG_MAX;
|
||||||
|
p->previous_kernel_time = ULONG_MAX;
|
||||||
|
p->total_cpu_time = 0;
|
||||||
|
p->vsize = 0;
|
||||||
|
p->rss = 0;
|
||||||
#ifdef BUILD_IOSTATS
|
#ifdef BUILD_IOSTATS
|
||||||
process->previous_read_bytes = ULLONG_MAX;
|
p->read_bytes = 0;
|
||||||
process->previous_write_bytes = ULLONG_MAX;
|
p->previous_read_bytes = ULLONG_MAX;
|
||||||
|
p->write_bytes = 0;
|
||||||
|
p->previous_write_bytes = ULLONG_MAX;
|
||||||
|
p->io_perc = 0;
|
||||||
#endif /* BUILD_IOSTATS */
|
#endif /* BUILD_IOSTATS */
|
||||||
process->counted = 1;
|
p->time_stamp = 0;
|
||||||
|
p->counted = 1;
|
||||||
|
p->changed = 0;
|
||||||
|
|
||||||
/* process_find_name(process); */
|
/* process_find_name(p); */
|
||||||
|
|
||||||
/* add the process to the hash table */
|
/* add the process to the hash table */
|
||||||
hash_process(process);
|
hash_process(p);
|
||||||
|
|
||||||
return process;
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Get / create a new process object and insert it into the process list */
|
||||||
|
struct process *get_process(pid_t pid)
|
||||||
|
{
|
||||||
|
struct process *p = find_process(pid);
|
||||||
|
return p ? p : new_process(pid);
|
||||||
}
|
}
|
||||||
|
|
||||||
/******************************************
|
/******************************************
|
||||||
|
@ -128,7 +128,6 @@ void get_top_info(void);
|
|||||||
extern struct process *first_process;
|
extern struct process *first_process;
|
||||||
extern unsigned long g_time;
|
extern unsigned long g_time;
|
||||||
|
|
||||||
struct process *find_process(pid_t pid);
|
struct process *get_process(pid_t pid);
|
||||||
struct process *new_process(int p);
|
|
||||||
|
|
||||||
#endif /* _top_h_ */
|
#endif /* _top_h_ */
|
||||||
|
Loading…
Reference in New Issue
Block a user