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

drop enum text_object_type and all references to it's members

After some minor rewrite of the top parser (which was in fact the only
real user of the obj->type field left since introduction of text object
callbacks), there is no need for the obj->type field anymore.
This commit is contained in:
Phil Sutter 2009-12-12 15:47:00 +01:00
parent 5c86a80614
commit 8045e7f714
6 changed files with 160 additions and 625 deletions

View File

@ -139,7 +139,7 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
/* helper defines for internal use only */ /* helper defines for internal use only */
#define __OBJ_HEAD(a, n) if (!strcmp(s, #a)) { \ #define __OBJ_HEAD(a, n) if (!strcmp(s, #a)) { \
obj->type = OBJ_##a; add_update_callback(n); add_update_callback(n);
#define __OBJ_IF obj_be_ifblock_if(ifblock_opaque, obj) #define __OBJ_IF obj_be_ifblock_if(ifblock_opaque, obj)
#define __OBJ_ARG(...) if (!arg) { CRIT_ERR(obj, free_at_crash, __VA_ARGS__); } #define __OBJ_ARG(...) if (!arg) { CRIT_ERR(obj, free_at_crash, __VA_ARGS__); }
@ -152,7 +152,6 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
#ifdef X11 #ifdef X11
if (s[0] == '#') { if (s[0] == '#') {
obj->type = OBJ_color;
obj->data.l = get_x11_color(s); obj->data.l = get_x11_color(s);
obj->callbacks.print = &new_fg; obj->callbacks.print = &new_fg;
} else } else
@ -683,8 +682,6 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
if (!parse_top_args(s, arg, obj)) { if (!parse_top_args(s, arg, obj)) {
return NULL; return NULL;
} }
obj->callbacks.print = &print_top;
obj->callbacks.free = &free_top;
} else } else
#ifdef __linux__ #ifdef __linux__
OBJ(addr, &update_net_stats) OBJ(addr, &update_net_stats)

View File

@ -73,7 +73,6 @@ void parse_scroll_arg(struct text_object *obj, const char *arg, void *free_at_cr
#ifdef X11 #ifdef X11
/* add a color object right after scroll to reset any color changes */ /* add a color object right after scroll to reset any color changes */
obj->next->type = OBJ_color;
obj->next->data.l = sd->resetcolor; obj->next->data.l = sd->resetcolor;
obj->next->callbacks.print = &new_fg; obj->next->callbacks.print = &new_fg;
#endif /* X11 */ #endif /* X11 */

View File

@ -196,7 +196,6 @@ int ifblock_stack_empty(void **opaque)
void obj_be_plain_text(struct text_object *obj, const char *text) void obj_be_plain_text(struct text_object *obj, const char *text)
{ {
obj->type = OBJ_text;
obj->data.s = strdup(text); obj->data.s = strdup(text);
obj->verbatim_output = 1; obj->verbatim_output = 1;

View File

@ -37,444 +37,6 @@
extern "C" { extern "C" {
#endif #endif
enum text_object_type {
OBJ_read_tcp,
OBJ_addr,
#if defined(__linux__)
OBJ_addrs,
#endif /* __linux__ */
#ifndef __OpenBSD__
OBJ_acpiacadapter,
OBJ_acpifan,
OBJ_acpitemp,
OBJ_battery,
OBJ_battery_time,
OBJ_battery_percent,
OBJ_battery_bar,
OBJ_battery_short,
#endif /* !__OpenBSD__ */
OBJ_buffers,
OBJ_cached,
OBJ_color,
OBJ_color0,
OBJ_color1,
OBJ_color2,
OBJ_color3,
OBJ_color4,
OBJ_color5,
OBJ_color6,
OBJ_color7,
OBJ_color8,
OBJ_color9,
OBJ_conky_version,
OBJ_conky_build_date,
OBJ_conky_build_arch,
OBJ_font,
OBJ_cpu,
OBJ_cpubar,
OBJ_cpugauge,
#ifdef X11
OBJ_cpugraph,
OBJ_loadgraph,
#endif /* X11 */
OBJ_diskio,
OBJ_diskio_read,
OBJ_diskio_write,
#ifdef X11
OBJ_diskiograph,
OBJ_diskiograph_read,
OBJ_diskiograph_write,
#endif /* X11 */
OBJ_downspeed,
OBJ_downspeedf,
#ifdef X11
OBJ_downspeedgraph,
#endif /* X11 */
OBJ_else,
OBJ_endif,
OBJ_eval,
OBJ_image,
OBJ_exec,
OBJ_execi,
OBJ_texeci,
OBJ_execbar,
OBJ_execibar,
OBJ_execgauge,
OBJ_execigauge,
#ifdef X11
OBJ_execgraph,
OBJ_execigraph,
#endif /* X11 */
OBJ_execp,
OBJ_execpi,
OBJ_freq,
OBJ_freq_g,
OBJ_fs_bar,
OBJ_fs_bar_free,
OBJ_fs_free,
OBJ_fs_free_perc,
OBJ_fs_size,
OBJ_fs_type,
OBJ_fs_used,
OBJ_fs_used_perc,
OBJ_goto,
OBJ_tab,
OBJ_hr,
OBJ_offset,
OBJ_voffset,
OBJ_alignr,
OBJ_alignc,
OBJ_i2c,
OBJ_platform,
OBJ_hwmon,
#if defined(__linux__)
OBJ_disk_protect,
OBJ_i8k_version,
OBJ_i8k_bios,
OBJ_i8k_serial,
OBJ_i8k_cpu_temp,
OBJ_i8k_left_fan_status,
OBJ_i8k_right_fan_status,
OBJ_i8k_left_fan_rpm,
OBJ_i8k_right_fan_rpm,
OBJ_i8k_ac_status,
OBJ_i8k_buttons_status,
#if defined(IBM)
OBJ_ibm_fan,
OBJ_ibm_temps,
OBJ_ibm_volume,
OBJ_ibm_brightness,
OBJ_smapi,
#ifdef X11
OBJ_smapi_bat_bar,
#endif /* X11 */
OBJ_smapi_bat_perc,
OBJ_smapi_bat_temp,
OBJ_smapi_bat_power,
OBJ_if_smapi_bat_installed,
#endif /* IBM */
/* information from sony_laptop kernel module
* /sys/devices/platform/sony-laptop */
OBJ_sony_fanspeed,
OBJ_if_gw,
OBJ_ioscheduler,
OBJ_gw_iface,
OBJ_gw_ip,
OBJ_laptop_mode,
OBJ_pb_battery,
OBJ_voltage_mv,
OBJ_voltage_v,
OBJ_wireless_essid,
OBJ_wireless_mode,
OBJ_wireless_bitrate,
OBJ_wireless_ap,
OBJ_wireless_link_qual,
OBJ_wireless_link_qual_max,
OBJ_wireless_link_qual_perc,
OBJ_wireless_link_bar,
#endif /* __linux__ */
#if defined(__FreeBSD__) || defined(__linux__)
OBJ_if_up,
#endif
OBJ_if_empty,
OBJ_if_match,
OBJ_if_existing,
OBJ_if_mounted,
OBJ_if_running,
OBJ_if_updatenr,
OBJ_top,
OBJ_top_mem,
OBJ_top_time,
#ifdef IOSTATS
OBJ_top_io,
#endif
OBJ_tail,
OBJ_head,
OBJ_lines,
OBJ_words,
OBJ_kernel,
OBJ_loadavg,
OBJ_machine,
OBJ_mails,
OBJ_new_mails,
OBJ_seen_mails,
OBJ_unseen_mails,
OBJ_flagged_mails,
OBJ_unflagged_mails,
OBJ_format_time,
OBJ_forwarded_mails,
OBJ_unforwarded_mails,
OBJ_replied_mails,
OBJ_unreplied_mails,
OBJ_draft_mails,
OBJ_trashed_mails,
OBJ_mboxscan,
OBJ_mem,
OBJ_memeasyfree,
OBJ_memfree,
OBJ_memgauge,
#ifdef X11
OBJ_memgraph,
#endif /* X11 */
OBJ_membar,
OBJ_memmax,
OBJ_memperc,
OBJ_mixer,
OBJ_mixerl,
OBJ_mixerr,
OBJ_mixerbar,
OBJ_mixerlbar,
OBJ_mixerrbar,
OBJ_if_mixer_mute,
#ifdef X11
OBJ_monitor,
OBJ_monitor_number,
OBJ_desktop,
OBJ_desktop_number,
OBJ_desktop_name,
#endif /* X11 */
OBJ_nameserver,
OBJ_nodename,
OBJ_nvidia,
OBJ_pre_exec,
OBJ_cmdline_to_pid,
OBJ_pid_chroot,
OBJ_pid_cmdline,
OBJ_pid_cwd,
OBJ_pid_environ,
OBJ_pid_environ_list,
OBJ_pid_exe,
OBJ_pid_nice,
OBJ_pid_openfiles,
OBJ_pid_parent,
OBJ_pid_priority,
OBJ_pid_state,
OBJ_pid_state_short,
OBJ_pid_stderr,
OBJ_pid_stdin,
OBJ_pid_stdout,
OBJ_pid_threads,
OBJ_pid_thread_list,
OBJ_pid_time_kernelmode,
OBJ_pid_time_usermode,
OBJ_pid_time,
OBJ_pid_uid,
OBJ_pid_euid,
OBJ_pid_suid,
OBJ_pid_fsuid,
OBJ_pid_gid,
OBJ_pid_egid,
OBJ_pid_sgid,
OBJ_pid_fsgid,
OBJ_pid_read,
OBJ_pid_vmpeak,
OBJ_pid_vmsize,
OBJ_pid_vmlck,
OBJ_pid_vmhwm,
OBJ_pid_vmrss,
OBJ_pid_vmdata,
OBJ_pid_vmstk,
OBJ_pid_vmexe,
OBJ_pid_vmlib,
OBJ_pid_vmpte,
OBJ_pid_write,
OBJ_gid_name,
OBJ_uid_name,
OBJ_processes,
OBJ_running_processes,
OBJ_shadecolor,
OBJ_outlinecolor,
OBJ_stippled_hr,
OBJ_swap,
OBJ_swapfree,
OBJ_swapbar,
OBJ_swapmax,
OBJ_swapperc,
OBJ_sysname,
OBJ_text,
OBJ_threads,
OBJ_running_threads,
OBJ_time,
OBJ_utime,
OBJ_tztime,
OBJ_totaldown,
OBJ_totalup,
OBJ_updates,
OBJ_upspeed,
OBJ_upspeedf,
#ifdef X11
OBJ_upspeedgraph,
#endif /* X11 */
OBJ_uptime,
OBJ_uptime_short,
OBJ_user_names,
OBJ_user_terms,
OBJ_user_times,
OBJ_user_time,
OBJ_user_number,
OBJ_imap_messages,
OBJ_imap_unseen,
OBJ_pop3_unseen,
OBJ_pop3_used,
#if (defined(__FreeBSD__) || defined(__FreeBSD_kernel__) \
|| defined(__OpenBSD__)) && (defined(i386) || defined(__i386__))
OBJ_apm_adapter,
OBJ_apm_battery_time,
OBJ_apm_battery_life,
#endif /* __FreeBSD__ __OpenBSD__ */
#ifdef __OpenBSD__
OBJ_obsd_sensors_temp,
OBJ_obsd_sensors_fan,
OBJ_obsd_sensors_volt,
OBJ_obsd_vendor,
OBJ_obsd_product,
#endif /* __OpenBSD__ */
#ifdef MPD
OBJ_mpd_title,
OBJ_mpd_artist,
OBJ_mpd_album,
OBJ_mpd_random,
OBJ_mpd_repeat,
OBJ_mpd_vol,
OBJ_mpd_bitrate,
OBJ_mpd_status,
OBJ_mpd_bar,
OBJ_mpd_elapsed,
OBJ_mpd_length,
OBJ_mpd_track,
OBJ_mpd_name,
OBJ_mpd_file,
OBJ_mpd_percent,
OBJ_mpd_smart,
OBJ_if_mpd_playing,
#endif /* MPD */
#ifdef MOC
OBJ_moc_state,
OBJ_moc_file,
OBJ_moc_title,
OBJ_moc_artist,
OBJ_moc_song,
OBJ_moc_album,
OBJ_moc_totaltime,
OBJ_moc_timeleft,
OBJ_moc_curtime,
OBJ_moc_bitrate,
OBJ_moc_rate,
#endif /* MOC */
#ifdef XMMS2
OBJ_xmms2_artist,
OBJ_xmms2_album,
OBJ_xmms2_title,
OBJ_xmms2_genre,
OBJ_xmms2_comment,
OBJ_xmms2_url,
OBJ_xmms2_date,
OBJ_xmms2_tracknr,
OBJ_xmms2_bitrate,
OBJ_xmms2_id,
OBJ_xmms2_duration,
OBJ_xmms2_elapsed,
OBJ_xmms2_size,
OBJ_xmms2_percent,
OBJ_xmms2_status,
#ifdef X11
OBJ_xmms2_bar,
#endif /* X11 */
OBJ_xmms2_smart,
OBJ_xmms2_playlist,
OBJ_xmms2_timesplayed,
OBJ_if_xmms2_connected,
#endif /* XMMS2 */
#ifdef AUDACIOUS
OBJ_audacious_status,
OBJ_audacious_title,
OBJ_audacious_length,
OBJ_audacious_length_seconds,
OBJ_audacious_position,
OBJ_audacious_position_seconds,
OBJ_audacious_bitrate,
OBJ_audacious_frequency,
OBJ_audacious_channels,
OBJ_audacious_filename,
OBJ_audacious_playlist_length,
OBJ_audacious_playlist_position,
OBJ_audacious_main_volume,
#ifdef X11
OBJ_audacious_bar,
#endif /* X11 */
#endif /* AUDACIOUS */
#ifdef BMPX
OBJ_bmpx_title,
OBJ_bmpx_artist,
OBJ_bmpx_album,
OBJ_bmpx_track,
OBJ_bmpx_uri,
OBJ_bmpx_bitrate,
#endif /* BMPX */
#ifdef EVE
OBJ_eve,
#endif /* EVE */
#ifdef HAVE_CURL
OBJ_curl,
#endif /* HAVE_CURL */
#ifdef RSS
OBJ_rss,
#endif /* RSS */
#ifdef WEATHER
OBJ_weather,
#endif /* WEATHER */
#ifdef XOAP
OBJ_weather_forecast,
#endif /* XOAP */
#ifdef HAVE_LUA
OBJ_lua,
OBJ_lua_parse,
OBJ_lua_bar,
OBJ_lua_gauge,
#ifdef X11
OBJ_lua_graph,
#endif /* X11 */
#endif /* HAVE_LUA */
#ifdef TCP_PORT_MONITOR
OBJ_tcp_portmon,
#endif /* TCP_PORT_MONITOR */
#ifdef HAVE_ICONV
OBJ_iconv_start,
OBJ_iconv_stop,
#endif /* HAVE_ICONV */
#ifdef HDDTEMP
OBJ_hddtemp,
#endif /* HDDTEMP */
OBJ_include,
OBJ_blink,
OBJ_to_bytes,
OBJ_scroll,
OBJ_combine,
OBJ_entropy_avail,
OBJ_entropy_perc,
OBJ_entropy_poolsize,
OBJ_entropy_bar,
#ifdef APCUPSD
OBJ_apcupsd,
OBJ_apcupsd_name,
OBJ_apcupsd_model,
OBJ_apcupsd_upsmode,
OBJ_apcupsd_cable,
OBJ_apcupsd_status,
OBJ_apcupsd_linev,
OBJ_apcupsd_load,
OBJ_apcupsd_loadbar,
OBJ_apcupsd_loadgauge,
#ifdef X11
OBJ_apcupsd_loadgraph,
#endif /* X11 */
OBJ_apcupsd_charge,
OBJ_apcupsd_timeleft,
OBJ_apcupsd_temp,
OBJ_apcupsd_lastxfer,
#endif /* APCUPSD */
};
/* text object callbacks */ /* text object callbacks */
struct obj_cb { struct obj_cb {
/* text object: print obj's output to p */ /* text object: print obj's output to p */
@ -531,7 +93,6 @@ struct text_object {
char verbatim_output; char verbatim_output;
void *special_data; void *special_data;
int type;
long line; long line;
struct obj_cb callbacks; struct obj_cb callbacks;
}; };

321
src/top.c
View File

@ -801,101 +801,6 @@ void process_find_top(struct process **cpu, struct process **mem,
#endif /* IOSTATS */ #endif /* IOSTATS */
} }
struct top_data {
int num;
int type;
int was_parsed;
char *s;
};
int parse_top_args(const char *s, const char *arg, struct text_object *obj)
{
struct top_data *td;
char buf[64];
int n;
if (!arg) {
NORM_ERR("top needs arguments");
return 0;
}
if (obj->data.opaque) {
return 1;
}
if (s[3] == 0) {
obj->type = OBJ_top;
top_cpu = 1;
} else if (strcmp(&s[3], "_mem") == EQUAL) {
obj->type = OBJ_top_mem;
top_mem = 1;
} else if (strcmp(&s[3], "_time") == EQUAL) {
obj->type = OBJ_top_time;
top_time = 1;
#ifdef IOSTATS
} else if (strcmp(&s[3], "_io") == EQUAL) {
obj->type = OBJ_top_io;
top_io = 1;
#endif /* IOSTATS */
} else {
#ifdef IOSTATS
NORM_ERR("Must be top, top_mem, top_time or top_io");
#else /* IOSTATS */
NORM_ERR("Must be top, top_mem or top_time");
#endif /* IOSTATS */
return 0;
}
obj->data.opaque = td = malloc(sizeof(struct top_data));
memset(td, 0, sizeof(struct top_data));
td->s = strndup(arg, text_buffer_size);
if (sscanf(arg, "%63s %i", buf, &n) == 2) {
if (strcmp(buf, "name") == EQUAL) {
td->type = TOP_NAME;
} else if (strcmp(buf, "cpu") == EQUAL) {
td->type = TOP_CPU;
} else if (strcmp(buf, "pid") == EQUAL) {
td->type = TOP_PID;
} else if (strcmp(buf, "mem") == EQUAL) {
td->type = TOP_MEM;
} else if (strcmp(buf, "time") == EQUAL) {
td->type = TOP_TIME;
} else if (strcmp(buf, "mem_res") == EQUAL) {
td->type = TOP_MEM_RES;
} else if (strcmp(buf, "mem_vsize") == EQUAL) {
td->type = TOP_MEM_VSIZE;
#ifdef IOSTATS
} else if (strcmp(buf, "io_read") == EQUAL) {
td->type = TOP_READ_BYTES;
} else if (strcmp(buf, "io_write") == EQUAL) {
td->type = TOP_WRITE_BYTES;
} else if (strcmp(buf, "io_perc") == EQUAL) {
td->type = TOP_IO_PERC;
#endif /* IOSTATS */
} else {
NORM_ERR("invalid type arg for top");
#ifdef IOSTATS
NORM_ERR("must be one of: name, cpu, pid, mem, time, mem_res, mem_vsize, "
"io_read, io_write, io_perc");
#else /* IOSTATS */
NORM_ERR("must be one of: name, cpu, pid, mem, time, mem_res, mem_vsize");
#endif /* IOSTATS */
return 0;
}
if (n < 1 || n > 10) {
NORM_ERR("invalid num arg for top. Must be between 1 and 10.");
return 0;
} else {
td->num = n - 1;
}
} else {
NORM_ERR("invalid argument count for top");
return 0;
}
return 1;
}
static char *format_time(unsigned long timeval, const int width) static char *format_time(unsigned long timeval, const int width)
{ {
char buf[10]; char buf[10];
@ -936,6 +841,13 @@ static char *format_time(unsigned long timeval, const int width)
return strndup("<inf>", text_buffer_size); return strndup("<inf>", text_buffer_size);
} }
struct top_data {
struct process **list;
int num;
int was_parsed;
char *s;
};
static unsigned int top_name_width = 15; static unsigned int top_name_width = 15;
/* return zero on success, non-zero otherwise */ /* return zero on success, non-zero otherwise */
@ -946,97 +858,74 @@ int set_top_name_width(const char *s)
return !(sscanf(s, "%u", &top_name_width) == 1); return !(sscanf(s, "%u", &top_name_width) == 1);
} }
void print_top(struct text_object *obj, char *p, int p_max_size) static void print_top_name(struct text_object *obj, char *p, int p_max_size)
{ {
struct information *cur = &info;
struct top_data *td = obj->data.opaque; struct top_data *td = obj->data.opaque;
struct process **needed = 0;
int width; int width;
if (!td) if (!td || !td->list || !td->list[td->num])
return; return;
switch (obj->type) { width = MIN(p_max_size, (int)top_name_width + 1);
case OBJ_top: snprintf(p, width + 1, "%-*s", width, td->list[td->num]->name);
needed = cur->cpu;
break;
case OBJ_top_mem:
needed = cur->memu;
break;
case OBJ_top_time:
needed = cur->time;
break;
#ifdef IOSTATS
case OBJ_top_io:
needed = cur->io;
break;
#endif /* IOSTATS */
default:
return;
} }
static void print_top_mem(struct text_object *obj, char *p, int p_max_size)
{
struct top_data *td = obj->data.opaque;
int width;
if (needed[td->num]) { if (!td || !td->list || !td->list[td->num])
return;
width = MIN(p_max_size, 7);
snprintf(p, width, "%6.2f", (float) ((float)td->list[td->num]->rss / info.memmax) / 10);
}
static void print_top_time(struct text_object *obj, char *p, int p_max_size)
{
struct top_data *td = obj->data.opaque;
int width;
char *timeval; char *timeval;
switch (td->type) { if (!td || !td->list || !td->list[td->num])
case TOP_NAME: return;
width = MIN(p_max_size, (int)top_name_width + 1);
snprintf(p, width + 1, "%-*s", width,
needed[td->num]->name);
break;
case TOP_CPU:
width = MIN(p_max_size, 7);
snprintf(p, width, "%6.2f",
needed[td->num]->amount);
break;
case TOP_PID:
width = MIN(p_max_size, 6);
snprintf(p, width, "%5i",
needed[td->num]->pid);
break;
case TOP_MEM:
/* Calculate a percentage of residential mem from total mem available.
* Since rss is bytes and memmax kilobytes, dividing by 10 suffices here. */
width = MIN(p_max_size, 7);
snprintf(p, width, "%6.2f",
(float) ((float)needed[td->num]->rss / cur->memmax) / 10);
break;
case TOP_TIME:
width = MIN(p_max_size, 10); width = MIN(p_max_size, 10);
timeval = format_time( timeval = format_time(td->list[td->num]->total_cpu_time, 9);
needed[td->num]->total_cpu_time, 9);
snprintf(p, width, "%9s", timeval); snprintf(p, width, "%9s", timeval);
free(timeval); free(timeval);
break;
case TOP_MEM_RES:
human_readable(needed[td->num]->rss,
p, p_max_size);
break;
case TOP_MEM_VSIZE:
human_readable(needed[td->num]->vsize,
p, p_max_size);
break;
#ifdef IOSTATS
case TOP_READ_BYTES:
human_readable(needed[td->num]->read_bytes / update_interval,
p, p_max_size);
break;
case TOP_WRITE_BYTES:
human_readable(needed[td->num]->write_bytes / update_interval,
p, p_max_size);
break;
case TOP_IO_PERC:
width = MIN(p_max_size, 7);
snprintf(p, width, "%6.2f",
needed[td->num]->io_perc);
break;
#endif
}
}
} }
void free_top(struct text_object *obj) #define PRINT_TOP_GENERATOR(name, width, fmt, field) \
static void print_top_##name(struct text_object *obj, char *p, int p_max_size) \
{ \
struct top_data *td = obj->data.opaque; \
if (!td || !td->list || !td->list[td->num]) \
return; \
snprintf(p, MIN(p_max_size, width), fmt, td->list[td->num]->field); \
}
#define PRINT_TOP_HR_GENERATOR(name, field, denom) \
static void print_top_##name(struct text_object *obj, char *p, int p_max_size) \
{ \
struct top_data *td = obj->data.opaque; \
if (!td || !td->list || !td->list[td->num]) \
return; \
human_readable(td->list[td->num]->field / denom, p, p_max_size); \
}
PRINT_TOP_GENERATOR(cpu, 7, "%6.2f", amount)
PRINT_TOP_GENERATOR(pid, 6, "%5i", pid)
PRINT_TOP_HR_GENERATOR(mem_res, rss, 1)
PRINT_TOP_HR_GENERATOR(mem_vsize, vsize, 1)
#ifdef IOSTATS
PRINT_TOP_HR_GENERATOR(read_bytes, read_bytes, update_interval)
PRINT_TOP_HR_GENERATOR(write_bytes, write_bytes, update_interval)
PRINT_TOP_GENERATOR(io_perc, 7, "%6.2f", io_perc)
#endif /* IOSTATS */
static void free_top(struct text_object *obj)
{ {
struct top_data *td = obj->data.opaque; struct top_data *td = obj->data.opaque;
@ -1047,3 +936,95 @@ void free_top(struct text_object *obj)
free(obj->data.opaque); free(obj->data.opaque);
obj->data.opaque = NULL; obj->data.opaque = NULL;
} }
int parse_top_args(const char *s, const char *arg, struct text_object *obj)
{
struct top_data *td;
char buf[64];
int n;
if (!arg) {
NORM_ERR("top needs arguments");
return 0;
}
if (obj->data.opaque) {
return 1;
}
obj->data.opaque = td = malloc(sizeof(struct top_data));
memset(td, 0, sizeof(struct top_data));
if (s[3] == 0) {
td->list = info.cpu;
top_cpu = 1;
} else if (strcmp(&s[3], "_mem") == EQUAL) {
td->list = info.memu;
top_mem = 1;
} else if (strcmp(&s[3], "_time") == EQUAL) {
td->list = info.time;
top_time = 1;
#ifdef IOSTATS
} else if (strcmp(&s[3], "_io") == EQUAL) {
td->list = info.io;
top_io = 1;
#endif /* IOSTATS */
} else {
#ifdef IOSTATS
NORM_ERR("Must be top, top_mem, top_time or top_io");
#else /* IOSTATS */
NORM_ERR("Must be top, top_mem or top_time");
#endif /* IOSTATS */
free(obj->data.opaque);
obj->data.opaque = 0;
return 0;
}
td->s = strndup(arg, text_buffer_size);
if (sscanf(arg, "%63s %i", buf, &n) == 2) {
if (strcmp(buf, "name") == EQUAL) {
obj->callbacks.print = &print_top_name;
} else if (strcmp(buf, "cpu") == EQUAL) {
obj->callbacks.print = &print_top_cpu;
} else if (strcmp(buf, "pid") == EQUAL) {
obj->callbacks.print = &print_top_pid;
} else if (strcmp(buf, "mem") == EQUAL) {
obj->callbacks.print = &print_top_mem;
} else if (strcmp(buf, "time") == EQUAL) {
obj->callbacks.print = &print_top_time;
} else if (strcmp(buf, "mem_res") == EQUAL) {
obj->callbacks.print = &print_top_mem_res;
} else if (strcmp(buf, "mem_vsize") == EQUAL) {
obj->callbacks.print = &print_top_mem_vsize;
#ifdef IOSTATS
} else if (strcmp(buf, "io_read") == EQUAL) {
obj->callbacks.print = &print_top_read_bytes;
} else if (strcmp(buf, "io_write") == EQUAL) {
obj->callbacks.print = &print_top_write_bytes;
} else if (strcmp(buf, "io_perc") == EQUAL) {
obj->callbacks.print = &print_top_io_perc;
#endif /* IOSTATS */
} else {
NORM_ERR("invalid type arg for top");
#ifdef IOSTATS
NORM_ERR("must be one of: name, cpu, pid, mem, time, mem_res, mem_vsize, "
"io_read, io_write, io_perc");
#else /* IOSTATS */
NORM_ERR("must be one of: name, cpu, pid, mem, time, mem_res, mem_vsize");
#endif /* IOSTATS */
return 0;
}
if (n < 1 || n > 10) {
NORM_ERR("invalid num arg for top. Must be between 1 and 10.");
return 0;
} else {
td->num = n - 1;
}
} else {
NORM_ERR("invalid argument count for top");
return 0;
}
obj->callbacks.free = &free_top;
return 1;
}

View File

@ -146,8 +146,6 @@ void process_find_top(struct process **, struct process **, struct process **
struct process *get_process_by_name(const char *); struct process *get_process_by_name(const char *);
int parse_top_args(const char *s, const char *arg, struct text_object *obj); int parse_top_args(const char *s, const char *arg, struct text_object *obj);
void print_top(struct text_object *, char *, int);
void free_top(struct text_object *);
/* return zero on success, non-zero otherwise */ /* return zero on success, non-zero otherwise */
int set_top_name_width(const char *); int set_top_name_width(const char *);