static PyObject* gtop_proc_args(PyObject *self, PyObject *args) { glibtop_proc_args buf; unsigned pid; int argc; char **argv; PyObject *t; if(!PyArg_ParseTuple(args, "I", &pid)) return NULL; argv = glibtop_get_proc_argv(&buf, pid, -1); argc = g_strv_length(argv); INIT_LIST_WITH(t, PyS_S, argv, argc); g_strfreev(argv); return t; }
/*WinIconUse get_win_icon_use (gchar * cmd,gchar *res_name, gchar * class_name,const gchar *title) { IconUse *iter; for (iter = icon_regexes; iter->use != USE_DEFAULT; iter++) { gboolean match = TRUE; #ifdef DEBUG g_debug ("%s: iter->cmd = %s, cmd = %s",__func__,iter->cmd,cmd); #endif if (iter->cmd) { match = cmd && g_regex_match_simple(iter->cmd, cmd,0,0); if (!match) continue; } #ifdef DEBUG g_debug ("%s: iter->res_name = %s, res_name = %s",__func__,iter->res_name,res_name); #endif if (iter->res_name) { match = res_name && g_regex_match_simple(iter->res_name, res_name,0,0); if (!match) continue; } #ifdef DEBUG g_debug ("%s: iter->class_name = %s, class_name = %s",__func__,iter->class_name,class_name); #endif if (iter->class_name) { match = class_name && g_regex_match_simple(iter->class_name, class_name,0,0); if (!match) continue; } #ifdef DEBUG g_debug ("%s: iter->title = %s, title = %s",__func__,iter->title,title); #endif if (iter->title) { match = title && g_regex_match_simple(iter->title, title,0,0); if (!match) continue; } #ifdef DEBUG g_debug ("%s: setting to %d for %s",__func__,iter->use,title); #endif return iter->use; } return USE_DEFAULT; } */ gchar * get_full_cmd_from_pid (gint pid) { gchar * full_cmd = NULL; gchar **cmd_argv; glibtop_proc_args buf; gchar * temp; cmd_argv = glibtop_get_proc_argv (&buf,pid,1024); if (cmd_argv) { gchar ** iter; for (iter = cmd_argv;*iter;iter++) { temp = full_cmd; full_cmd = g_strdup_printf("%s%s%s",full_cmd?full_cmd:"",full_cmd?" ":"",*iter); g_free (temp); } } g_strfreev (cmd_argv); return full_cmd; }
int main (int argc, char *argv []) { glibtop_union data; unsigned c; struct rusage total_start, total_end; struct rusage rusage_start, rusage_end; struct timeval elapsed_utime, elapsed_stime; pid_t pid; pid = getpid (); setlocale (LC_ALL, ""); bindtextdomain (GETTEXT_PACKAGE, GTOPLOCALEDIR); textdomain (GETTEXT_PACKAGE); glibtop_init_r (&glibtop_global_server, 0, 0); display_self_times(); printf ("%-12s (%-10s): %7s - %9s - %9s\n", "Feature", "Flags", "Count", "utime", "stime"); printf ("-------------------------------------------" "---------------\n"); getrusage (RUSAGE_SELF, &total_start); getrusage (RUSAGE_SELF, &rusage_start); for (c = 0; c < PROFILE_COUNT; c++) glibtop_get_cpu (&data.cpu); getrusage (RUSAGE_SELF, &rusage_end); libgtop_timersub (&rusage_end.ru_utime, &rusage_start.ru_utime, &elapsed_utime); libgtop_timersub (&rusage_end.ru_stime, &rusage_start.ru_stime, &elapsed_stime); printf ("CPU (0x%08lx): %7lu - %9.2Lf - %9.2Lf\n", (unsigned long) data.cpu.flags, PROFILE_COUNT, (long double) ELAPSED_UTIME / PROFILE_COUNT, (long double) ELAPSED_STIME / PROFILE_COUNT); getrusage (RUSAGE_SELF, &rusage_start); for (c = 0; c < PROFILE_COUNT_EXPENSIVE; c++) glibtop_get_mem (&data.mem); getrusage (RUSAGE_SELF, &rusage_end); libgtop_timersub (&rusage_end.ru_utime, &rusage_start.ru_utime, &elapsed_utime); libgtop_timersub (&rusage_end.ru_stime, &rusage_start.ru_stime, &elapsed_stime); printf ("Memory (0x%08lx): %7lu - %9.2Lf - %9.2Lf\n", (unsigned long) data.mem.flags, PROFILE_COUNT_EXPENSIVE, (long double) ELAPSED_UTIME / PROFILE_COUNT_EXPENSIVE, (long double) ELAPSED_STIME / PROFILE_COUNT_EXPENSIVE); getrusage (RUSAGE_SELF, &rusage_start); for (c = 0; c < PROFILE_COUNT_EXPENSIVE; c++) glibtop_get_swap (&data.swap); getrusage (RUSAGE_SELF, &rusage_end); libgtop_timersub (&rusage_end.ru_utime, &rusage_start.ru_utime, &elapsed_utime); libgtop_timersub (&rusage_end.ru_stime, &rusage_start.ru_stime, &elapsed_stime); printf ("Swap (0x%08lx): %7lu - %9.2Lf - %9.2Lf\n", (unsigned long) data.swap.flags, PROFILE_COUNT_EXPENSIVE, (long double) ELAPSED_UTIME / PROFILE_COUNT_EXPENSIVE, (long double) ELAPSED_STIME / PROFILE_COUNT_EXPENSIVE); getrusage (RUSAGE_SELF, &rusage_start); for (c = 0; c < PROFILE_COUNT; c++) glibtop_get_uptime (&data.uptime); getrusage (RUSAGE_SELF, &rusage_end); libgtop_timersub (&rusage_end.ru_utime, &rusage_start.ru_utime, &elapsed_utime); libgtop_timersub (&rusage_end.ru_stime, &rusage_start.ru_stime, &elapsed_stime); printf ("Uptime (0x%08lx): %7lu - %9.2Lf - %9.2Lf\n", (unsigned long) data.uptime.flags, PROFILE_COUNT, (long double) ELAPSED_UTIME / PROFILE_COUNT, (long double) ELAPSED_STIME / PROFILE_COUNT); getrusage (RUSAGE_SELF, &rusage_start); for (c = 0; c < PROFILE_COUNT; c++) glibtop_get_loadavg (&data.loadavg); getrusage (RUSAGE_SELF, &rusage_end); libgtop_timersub (&rusage_end.ru_utime, &rusage_start.ru_utime, &elapsed_utime); libgtop_timersub (&rusage_end.ru_stime, &rusage_start.ru_stime, &elapsed_stime); printf ("Loadavg (0x%08lx): %7lu - %9.2Lf - %9.2Lf\n", (unsigned long) data.loadavg.flags, PROFILE_COUNT, (long double) ELAPSED_UTIME / PROFILE_COUNT, (long double) ELAPSED_STIME / PROFILE_COUNT); getrusage (RUSAGE_SELF, &rusage_start); for (c = 0; c < PROFILE_COUNT_EXPENSIVE; c++) { pid_t* ptr = glibtop_get_proclist (&data.proclist, 0, 0); g_free (ptr); } getrusage (RUSAGE_SELF, &rusage_end); libgtop_timersub (&rusage_end.ru_utime, &rusage_start.ru_utime, &elapsed_utime); libgtop_timersub (&rusage_end.ru_stime, &rusage_start.ru_stime, &elapsed_stime); printf ("Proclist (0x%08lx): %7lu - %9.2Lf - %9.2Lf\n", (unsigned long) data.proclist.flags, PROFILE_COUNT_EXPENSIVE, (long double) ELAPSED_UTIME / PROFILE_COUNT_EXPENSIVE, (long double) ELAPSED_STIME / PROFILE_COUNT_EXPENSIVE); getrusage (RUSAGE_SELF, &rusage_start); for (c = 0; c < PROFILE_COUNT_EXPENSIVE; c++) { char** ptr = glibtop_get_netlist (&data.netlist); g_strfreev (ptr); } getrusage (RUSAGE_SELF, &rusage_end); libgtop_timersub (&rusage_end.ru_utime, &rusage_start.ru_utime, &elapsed_utime); libgtop_timersub (&rusage_end.ru_stime, &rusage_start.ru_stime, &elapsed_stime); printf ("Netlist (0x%08lx): %7lu - %9.2Lf - %9.2Lf\n", (unsigned long) data.proclist.flags, PROFILE_COUNT_EXPENSIVE, (long double) ELAPSED_UTIME / PROFILE_COUNT_EXPENSIVE, (long double) ELAPSED_STIME / PROFILE_COUNT_EXPENSIVE); getrusage (RUSAGE_SELF, &rusage_start); for (c = 0; c < PROFILE_COUNT; c++) glibtop_get_proc_state (&data.proc_state, pid); getrusage (RUSAGE_SELF, &rusage_end); libgtop_timersub (&rusage_end.ru_utime, &rusage_start.ru_utime, &elapsed_utime); libgtop_timersub (&rusage_end.ru_stime, &rusage_start.ru_stime, &elapsed_stime); printf ("Proc_State (0x%08lx): %7lu - %9.2Lf - %9.2Lf\n", (unsigned long) data.proc_state.flags, PROFILE_COUNT, (long double) ELAPSED_UTIME / PROFILE_COUNT, (long double) ELAPSED_STIME / PROFILE_COUNT); getrusage (RUSAGE_SELF, &rusage_start); for (c = 0; c < PROFILE_COUNT; c++) glibtop_get_proc_uid (&data.proc_uid, pid); getrusage (RUSAGE_SELF, &rusage_end); libgtop_timersub (&rusage_end.ru_utime, &rusage_start.ru_utime, &elapsed_utime); libgtop_timersub (&rusage_end.ru_stime, &rusage_start.ru_stime, &elapsed_stime); printf ("Proc_Uid (0x%08lx): %7lu - %9.2Lf - %9.2Lf\n", (unsigned long) data.proc_uid.flags, PROFILE_COUNT, (long double) ELAPSED_UTIME / PROFILE_COUNT, (long double) ELAPSED_STIME / PROFILE_COUNT); getrusage (RUSAGE_SELF, &rusage_start); for (c = 0; c < PROFILE_COUNT; c++) glibtop_get_proc_mem (&data.proc_mem, pid); getrusage (RUSAGE_SELF, &rusage_end); libgtop_timersub (&rusage_end.ru_utime, &rusage_start.ru_utime, &elapsed_utime); libgtop_timersub (&rusage_end.ru_stime, &rusage_start.ru_stime, &elapsed_stime); printf ("Proc_Mem (0x%08lx): %7lu - %9.2Lf - %9.2Lf\n", (unsigned long) data.proc_mem.flags, PROFILE_COUNT, (long double) ELAPSED_UTIME / PROFILE_COUNT, (long double) ELAPSED_STIME / PROFILE_COUNT); getrusage (RUSAGE_SELF, &rusage_start); for (c = 0; c < PROFILE_COUNT_EXPENSIVE; c++) { glibtop_map_entry* entries; entries = glibtop_get_proc_map (&data.proc_map, pid); g_free (entries); } getrusage (RUSAGE_SELF, &rusage_end); libgtop_timersub (&rusage_end.ru_utime, &rusage_start.ru_utime, &elapsed_utime); libgtop_timersub (&rusage_end.ru_stime, &rusage_start.ru_stime, &elapsed_stime); printf ("Proc_Map (0x%08lx): %7lu - %9.2Lf - %9.2Lf\n", (unsigned long) data.proc_map.flags, PROFILE_COUNT_EXPENSIVE, (long double) ELAPSED_UTIME / PROFILE_COUNT_EXPENSIVE, (long double) ELAPSED_STIME / PROFILE_COUNT_EXPENSIVE); getrusage (RUSAGE_SELF, &rusage_start); for (c = 0; c < PROFILE_COUNT; c++) glibtop_get_proc_segment (&data.proc_segment, pid); getrusage (RUSAGE_SELF, &rusage_end); libgtop_timersub (&rusage_end.ru_utime, &rusage_start.ru_utime, &elapsed_utime); libgtop_timersub (&rusage_end.ru_stime, &rusage_start.ru_stime, &elapsed_stime); printf ("Proc_Segment (0x%08lx): %7lu - %9.2Lf - %9.2Lf\n", (unsigned long) data.proc_segment.flags, PROFILE_COUNT, (long double) ELAPSED_UTIME / PROFILE_COUNT, (long double) ELAPSED_STIME / PROFILE_COUNT); getrusage (RUSAGE_SELF, &rusage_start); for (c = 0; c < PROFILE_COUNT; c++) { char** argv; argv = glibtop_get_proc_argv (&data.proc_args, pid, 0); g_strfreev(argv); } getrusage (RUSAGE_SELF, &rusage_end); libgtop_timersub (&rusage_end.ru_utime, &rusage_start.ru_utime, &elapsed_utime); libgtop_timersub (&rusage_end.ru_stime, &rusage_start.ru_stime, &elapsed_stime); printf ("Proc_Args (0x%08lx): %7lu - %9.2Lf - %9.2Lf\n", (unsigned long) data.proc_args.flags, PROFILE_COUNT, (long double) ELAPSED_UTIME / PROFILE_COUNT, (long double) ELAPSED_STIME / PROFILE_COUNT); getrusage (RUSAGE_SELF, &rusage_start); for (c = 0; c < PROFILE_COUNT; c++) glibtop_get_proc_time (&data.proc_time, pid); getrusage (RUSAGE_SELF, &rusage_end); libgtop_timersub (&rusage_end.ru_utime, &rusage_start.ru_utime, &elapsed_utime); libgtop_timersub (&rusage_end.ru_stime, &rusage_start.ru_stime, &elapsed_stime); printf ("Proc_Time (0x%08lx): %7lu - %9.2Lf - %9.2Lf\n", (unsigned long) data.proc_time.flags, PROFILE_COUNT, (long double) ELAPSED_UTIME / PROFILE_COUNT, (long double) ELAPSED_STIME / PROFILE_COUNT); getrusage (RUSAGE_SELF, &rusage_start); for (c = 0; c < PROFILE_COUNT; c++) glibtop_get_proc_signal (&data.proc_signal, pid); getrusage (RUSAGE_SELF, &rusage_end); libgtop_timersub (&rusage_end.ru_utime, &rusage_start.ru_utime, &elapsed_utime); libgtop_timersub (&rusage_end.ru_stime, &rusage_start.ru_stime, &elapsed_stime); printf ("Proc_Signal (0x%08lx): %7lu - %9.2Lf - %9.2Lf\n", (unsigned long) data.proc_signal.flags, PROFILE_COUNT, (long double) ELAPSED_UTIME / PROFILE_COUNT, (long double) ELAPSED_STIME / PROFILE_COUNT); getrusage (RUSAGE_SELF, &rusage_start); for (c = 0; c < PROFILE_COUNT; c++) glibtop_get_proc_kernel (&data.proc_kernel, pid); getrusage (RUSAGE_SELF, &rusage_end); libgtop_timersub (&rusage_end.ru_utime, &rusage_start.ru_utime, &elapsed_utime); libgtop_timersub (&rusage_end.ru_stime, &rusage_start.ru_stime, &elapsed_stime); printf ("Proc_Kernel (0x%08lx): %7lu - %9.2Lf - %9.2Lf\n", (unsigned long) data.proc_kernel.flags, PROFILE_COUNT, (long double) ELAPSED_UTIME / PROFILE_COUNT, (long double) ELAPSED_STIME / PROFILE_COUNT); getrusage (RUSAGE_SELF, &total_end); libgtop_timersub (&total_end.ru_utime, &total_start.ru_utime, &elapsed_utime); libgtop_timersub (&total_end.ru_stime, &total_start.ru_stime, &elapsed_stime); printf ("-------------------------------------------" "---------------\n"); printf ("%-36s %9lu - %9lu\n\n", "TOTAL", ELAPSED_UTIME, ELAPSED_STIME); printf ("All timings are in clock ticks " "(1000000 ticks per second).\n\n"); display_self_times(); glibtop_close (); exit (0); }