diff --git a/src/core.cc b/src/core.cc index 0b4717af..41b6c094 100644 --- a/src/core.cc +++ b/src/core.cc @@ -849,6 +849,9 @@ struct text_object *construct_text_object(char *s, const char *arg, long * nothing else than just that, using an ugly switch(). */ if (strncmp(s, "top", 3) == EQUAL) { if (parse_top_args(s, arg, obj)) { +#ifdef __linux__ + determine_longstat_file(); +#endif add_update_callback(&update_top); } else { free(obj); diff --git a/src/linux.cc b/src/linux.cc index 34774e4c..d25dff82 100644 --- a/src/linux.cc +++ b/src/linux.cc @@ -661,6 +661,23 @@ void determine_longstat(char *buf) } } +void determine_longstat_file(void) { +#define MAX_PROCSTAT_LINELEN 255 + FILE *stat_fp; + static int rep = 0; + char buf[MAX_PROCSTAT_LINELEN + 1]; + + if ( not (stat_fp = open_file("/proc/stat", &rep))) return; + while ( not feof(stat_fp)) { + if (fgets(buf, MAX_PROCSTAT_LINELEN, stat_fp) == NULL) break; + if (strncmp(buf, "cpu", 3) == 0) { + determine_longstat(buf); + break; + } + } + fclose(stat_fp); +} + void get_cpu_count(void) { FILE *stat_fp; diff --git a/src/linux.h b/src/linux.h index 982647ac..fb87d171 100644 --- a/src/linux.h +++ b/src/linux.h @@ -55,4 +55,5 @@ int update_stat(void); void print_distribution(struct text_object *, char *, int); +void determine_longstat_file(void); #endif /* _LINUX_H */