Commit 3640c849 authored by Petr Štětka's avatar Petr Štětka
Browse files

Implemented show full process name.

parent cd01c565
......@@ -23,7 +23,7 @@ namespace Usage
var process_list_box_frame = new Gtk.Frame(null);
process_list_box_frame.margin_top = 30;
process_list_box_frame.margin_bottom = 20;
process_list_box_frame.add(new ProcessBox());
process_list_box_frame.add(new ListBox());
var cpu_box = new Gtk.Box(Gtk.Orientation.VERTICAL, 0);
cpu_box.pack_start(label, false, false, 0);
......
......@@ -23,17 +23,17 @@ namespace Usage
}
}
public class ProcessBox : Gtk.Box
public class ListBox : Gtk.Box
{
private Gee.ArrayList<ProcessRow> rows;
private Gee.ArrayList<Row> rows;
HashTable<uint, ProcessRow> process_rows_table;
HashTable<uint, Row> process_rows_table;
public ProcessBox()
public ListBox()
{
orientation = Gtk.Orientation.VERTICAL;
rows = new Gee.ArrayList<ProcessRow>();
process_rows_table = new HashTable<uint, ProcessRow>(direct_hash, direct_equal);
rows = new Gee.ArrayList<Row>();
process_rows_table = new HashTable<uint, Row>(direct_hash, direct_equal);
Timeout.add((GLib.Application.get_default() as Application).settings.list_update_interval, () =>
{
......@@ -45,7 +45,7 @@ namespace Usage
public void update()
{
foreach(ProcessRow row in rows)
foreach(Row row in rows)
row.alive = false;
foreach(unowned Process process in (GLib.Application.get_default() as Application).monitor.get_processes())
......@@ -54,7 +54,7 @@ namespace Usage
{
if((int) process.cpu_load > 0)
{
ProcessRow row = new ProcessRow(process.pid, (int) process.cpu_load, process.cmdline);
Row row = new Row(process.pid, (int) process.cpu_load, process.cmdline);
rows.add(row);
process_rows_table.insert (process.pid, row);
}
......@@ -63,13 +63,13 @@ namespace Usage
{
if((int) process.cpu_load > 0)
{
unowned ProcessRow row = process_rows_table[process.pid];
unowned Row row = process_rows_table[process.pid];
row.alive = true;
row.set_value((int) process.cpu_load);
}
else
{
unowned ProcessRow row = process_rows_table[process.pid];
unowned Row row = process_rows_table[process.pid];
rows.remove(row);
process_rows_table.remove(process.pid);
}
......@@ -96,7 +96,7 @@ namespace Usage
public void sort()
{
rows.sort((a, b) => {
return(b as ProcessRow).get_value() - ( a as ProcessRow).get_value();
return(b as Row).get_value() - ( a as Row).get_value();
});
}
}
......
namespace Usage
{
public class ProcessRow : Gtk.Box
public class Row : Gtk.Box
{
Gtk.Image icon;
Gtk.Label title_label;
......@@ -22,7 +22,7 @@ namespace Usage
public bool showing_details { get; private set; }
public bool max_usage { get; private set; }
public ProcessRow(/*Gee.ArrayList<uint> pids, Gee.ArrayList<int> values, Gee.ArrayList<int> values*/uint pid, int value, string name)
public Row(/*Gee.ArrayList<uint> pids, Gee.ArrayList<int> values, Gee.ArrayList<int> values*/uint pid, int value, string name)
{
/*this.pids = pids;
this.names = names;
......
......@@ -64,6 +64,44 @@ namespace Usage
}
}
private string get_full_process_cmd (string cmd, string[] args)
{
var secure_arguments = new string[2];
for(int i = 0; i < 2; i++)
{
if(args[i] != null)
{
secure_arguments[i] = args[i];
for (int j = 0; j < args[i].length; j++)
{
if(args[i][j] == ' ')
secure_arguments[i] = args[i].substring(0, j);
}
}
else
secure_arguments[i] = "";
}
for (int i = 0; i < secure_arguments.length; i++)
{
var name = Path.get_basename(secure_arguments[i]);
if (name.has_prefix(cmd))
{
for (int j = 0; j < name.length; j++)
{
if(name[j] == ' ')
name = name.substring(0, j);
}
return name;
}
}
return cmd;
}
public bool update_data()
{
/* CPU */
......@@ -100,15 +138,18 @@ namespace Usage
{
GTop.ProcState proc_state;
GTop.ProcTime proc_time;
GTop.ProcArgs proc_args;
GTop.get_proc_state (out proc_state, pids[i]);
GTop.get_proc_time (out proc_time, pids[i]);
var arguments = GTop.get_proc_argv (out proc_args, pids[i]);
if (!(pids[i] in process_table))
{
var process = new Process();
process.pid = pids[i];
process.alive = true;
process.cmdline = (string) proc_state.cmd;
process.cmdline = get_full_process_cmd ((string) proc_state.cmd, arguments);
process.cpu_load = 0;
process.cpu_last_used = proc_time.rtime;
process.mem_usage = 0;
......
......@@ -121,4 +121,35 @@ namespace GTop {
[CCode(array_length = false, array_null_terminated = false)]
public string[] get_netlist(out Netlist netlist);
[CCode(cname = "glibtop_proc_uid", cheader_filename = "glibtop/procuid.h")]
public struct ProcUid {
uint64 flags;
int32 uid;
int32 euid;
int32 gid;
int32 egid;
int32 suid;
int32 sgid;
int32 fsuid;
int32 fsgid;
int32 pid;
int32 ppid;
int32 pgrp;
int32 session;
int32 tty;
int32 tpgid;
int32 priority;
int32 nice;
int32 ngroups;
int32 groups[64];
}
public void get_proc_uid(out ProcUid proc_uid, uint pid);
[CCode(cname = "glibtop_proc_args", cheader_filename = "glibtop/procargs.h")]
public struct ProcArgs {
uint64 flags;
uint64 size;
}
public string[] get_proc_argv(out ProcArgs proc_args, uint pid);
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment