Commit 60093de0 authored by Petr Štětka's avatar Petr Štětka
Browse files

Bug fixes

parent b7f4b6dd
......@@ -50,6 +50,11 @@ namespace Usage
label.set_text("<span font_desc=\"11.0\"><b>" + block_name + " " + processor_core.to_string() + "</b></span>");
label.use_markup = true;
}
else
{
label.set_text("<span font_desc=\"11.0\"><b>" + block_name + "</b></span>");
label.use_markup = true;
}
graph.update(application_percentages, other_percentages);
application_row.update(application_percentages);
......
......@@ -64,8 +64,13 @@ namespace Usage
{
app_cpu_load = (int) data.x_cpu_load;
app_memory_usage = (int) data.mem_usage;
processor_graph_block.update((int) data.last_processor, app_cpu_load, (int) monitor.x_cpu_load[data.last_processor]);
}
processor_graph_block.update((int) data.last_processor, app_cpu_load, (int) monitor.x_cpu_load[data.last_processor]);
else
{
processor_graph_block.update(-1, app_cpu_load, (int) monitor.cpu_load);
}
memory_graph_block.update(-1, app_memory_usage, (int) monitor.mem_usage);
return true;
}
......
......@@ -5,8 +5,8 @@ namespace Usage
public class ProcessListBoxNew : Gtk.ListBox
{
ListStore model;
HashSet<string> rows;
string cmdline_opened_process;
ProcessRowNew? opened_row = null;
public ProcessListBoxNew()
{
......@@ -14,14 +14,22 @@ namespace Usage
set_header_func (update_header);
row_activated.connect( (row) => {
var process_row = (ProcessRowNew) row;
process_row.activate();
if(cmdline_opened_process == null)
cmdline_opened_process = process_row.process.cmdline;
if(opened_row != null)
opened_row.activate();
if(opened_row != process_row)
{
process_row.activate();
if(process_row.process.sub_processes != null)
opened_row = process_row;
else
opened_row = null;
}
else
cmdline_opened_process = null;
opened_row = null;
});
rows = new HashSet<string>();
model = new ListStore(typeof(Process));
bind_model(model, on_row_created);
......@@ -37,29 +45,10 @@ namespace Usage
public bool update()
{
foreach(unowned Process process in (GLib.Application.get_default() as Application).monitor.get_processes_cmdline())
{
if((process.cmdline in rows) == false)
{
if(process.cpu_load >= 1) //TODO To backend!
{
rows.add(process.cmdline);
model.append(process);
}
}
}
model.remove_all();
model.sort(sort);
for(uint i = 0; i < model.get_n_items(); i++)
{
Process row = (Process) model.get_item(i);
if(row.alive == false || row.cpu_load < 1)
{
rows.remove(row.cmdline);
model.remove(i);
}
}
foreach(unowned Process process in (GLib.Application.get_default() as Application).monitor.get_processes_cmdline())
model.insert_sorted(process, sort);
return true;
}
......@@ -68,10 +57,19 @@ namespace Usage
{
Process process = (Process) item;
bool opened = false;
if(process.cmdline == cmdline_opened_process)
opened = true;
if(opened_row != null)
{
if(process.cmdline == opened_row.process.cmdline)
{
opened = true;
}
}
var row = new ProcessRowNew(process, opened);
if(opened)
opened_row = row;
return row;
}
......
......@@ -38,9 +38,6 @@ namespace Usage
row_box.pack_end(load_label, false, true, 10);
box.pack_start(row_box, false, true, 0);
notify["max-usage"].connect (() => {
set_styles();
});
update();
if(process.sub_processes != null)
......@@ -128,20 +125,19 @@ namespace Usage
{
string values = "";
foreach(Process sub_process in process.sub_processes.get_values())
{
if(sub_process.cpu_load >= 1)
values += " " + ((int) sub_process.cpu_load).to_string() + " %";
}
values += " " + ((int) sub_process.cpu_load).to_string() + " %";
load_label.set_label(values);
}
else
load_label.set_label(((int) process.cpu_load).to_string() + " %");
if(process.cpu_load >= 90)
max_usage = true;
else
max_usage = false;
if(process.cpu_load >= 90)
max_usage = true;
else
max_usage = false;
set_styles();
}
private void hide_details()
......@@ -158,7 +154,6 @@ namespace Usage
revealer.set_reveal_child(true);
load_label.visible = false;
get_style_context().add_class("opened");
}
public void activate()
......@@ -175,7 +170,7 @@ namespace Usage
else
{
var dialog = new ProcessDialog(process.pid, display_name);
dialog.show_all ();
dialog.show_all();
}
}
......
......@@ -36,16 +36,7 @@ namespace Usage
{
foreach(unowned Process process in parent_process.sub_processes.get_values())
{
if(process.cpu_load >= 1)
model.append(process);
}
model.sort(sort);
for(uint i = 0; i < model.get_n_items(); i++)
{
Process row = (Process) model.get_item(i);
if(row.alive == false || row.cpu_load < 1)
model.remove(i);
model.insert_sorted(process, sort);
}
}
}
......
......@@ -32,6 +32,7 @@ namespace Usage
HashTable<string, Process> process_table_cmdline;
HashTable<pid_t?, Process> process_table_pid;
HashTable<pid_t?, Process> process_table_pid_condition;
private int process_mode = GTop.KERN_PROC_UID;
......@@ -70,8 +71,8 @@ namespace Usage
x_cpu_last_used = new uint64[get_num_processors()];
x_cpu_last_total = new uint64[get_num_processors()];
process_table_cmdline = new HashTable<string, Process>(str_hash, str_equal);
process_table_cmdline = new HashTable<string, Process>(str_hash, str_equal);
process_table_pid = new HashTable<pid_t?, Process>(int_hash, int_equal);
process_table_pid_condition = new HashTable<pid_t?, Process>(int_hash, int_equal);
var settings = (GLib.Application.get_default() as Application).settings;
......@@ -163,6 +164,11 @@ namespace Usage
GTop.get_swap (out swap);
swap_usage = (double) swap.used / swap.total;
foreach(unowned Process process in process_table_pid.get_values())
{
process.alive = false;
}
foreach(unowned Process process in process_table_cmdline.get_values())
{
if(process.sub_processes == null)
......@@ -208,7 +214,7 @@ namespace Usage
{
unowned Process process = process_table_pid[pids[i]];
process.last_processor = proc_state.last_processor;
process.cpu_load = (((double) (proc_time.rtime - process.cpu_last_used)) / (cpu_data.total - cpu_last_total)) * 100 *4; //TODO remove * 4 only me for test
process.cpu_load = (((double) (proc_time.rtime - process.cpu_last_used)) / (cpu_data.total - cpu_last_total)) * 100 * get_num_processors();//FIX ME remove * get_num_processors()
process.x_cpu_load = (((double) ((proc_time.xcpu_utime[process.last_processor] + proc_time.xcpu_stime[process.last_processor]) - process.x_cpu_last_used)) / (cpu_data.xcpu_total[process.last_processor] - x_cpu_last_total[process.last_processor])) * 100;
//FIX ME: It is always 0, libGTop bug propably
//GLib.stdout.printf("X_cpu: " + process.last_processor.to_string() + " " + (proc_time.xcpu_utime[process.last_processor] + proc_time.xcpu_stime[process.last_processor]).to_string() + "\n");
......@@ -220,67 +226,72 @@ namespace Usage
GTop.get_proc_mem (out proc_mem, process.pid);
process.mem_usage = ((double) (proc_mem.resident - proc_mem.share) / mem.total) * 100;
}
}
process_table_pid_condition.remove_all();
foreach(unowned Process process in process_table_pid.get_values())
{
if (process.alive == false)
process_table_pid.remove (process.pid);
else
{
if(process.cpu_load >= 1)
process_table_pid_condition.insert(process.pid, process);
}
}
if(proc_cmd_full in process_table_cmdline) //subprocess or update process
foreach(unowned Process process_it in process_table_pid_condition.get_values())
{
if(process_it.cmdline in process_table_cmdline) //subprocess or update process
{
if(process_table_cmdline[proc_cmd_full].sub_processes != null) //subprocess
if(process_table_cmdline[process_it.cmdline].sub_processes != null) //subprocess
{
if(pids[i] in process_table_cmdline[proc_cmd_full].sub_processes) //update subprocess
if(process_it.pid in process_table_cmdline[process_it.cmdline].sub_processes) //update subprocess
{
unowned Process process = process_table_cmdline[proc_cmd_full].sub_processes[pids[i]];
process.last_processor = proc_state.last_processor;
process.cpu_load = (((double) (proc_time.rtime - process.cpu_last_used)) / (cpu_data.total - cpu_last_total)) * 100 * get_num_processors(); //TODO After fix bug bellow remove: * get_num_processors()
process.x_cpu_load = (((double) ((proc_time.xcpu_utime[process.last_processor] + proc_time.xcpu_stime[process.last_processor]) - process.x_cpu_last_used)) / (cpu_data.xcpu_total[process.last_processor] - x_cpu_last_total[process.last_processor])) * 100;
//FIX ME: It is always 0, libGTop bug propably
//GLib.stdout.printf("X_cpu: " + process.last_processor.to_string() + " " + (proc_time.xcpu_utime[process.last_processor] + proc_time.xcpu_stime[process.last_processor]).to_string() + "\n");
process.alive = true;
process.cpu_last_used = proc_time.rtime;
process.x_cpu_last_used = (proc_time.xcpu_utime[process.last_processor] + proc_time.xcpu_stime[process.last_processor]);
GTop.ProcMem proc_mem;
GTop.get_proc_mem (out proc_mem, process.pid);
process.mem_usage = ((double) (proc_mem.resident - proc_mem.share) / mem.total) * 100;
unowned Process process = process_table_cmdline[process_it.cmdline].sub_processes[process_it.pid];
process.last_processor = process_it.last_processor;
process.cpu_load = process_it.cpu_load;
process.x_cpu_load = process_it.x_cpu_load;
process.alive = process_it.alive;
process.cpu_last_used = process_it.cpu_last_used;
process.x_cpu_last_used = process_it.x_cpu_last_used;
process.mem_usage = process_it.mem_usage;
}
else //add subrow
{
var process = new Process();
process.pid = pids[i];
process.alive = true;
process.cmdline = proc_cmd_full;
process.last_processor = proc_state.last_processor;
process.cpu_load = 0;
process.x_cpu_load = 0;
process.cpu_last_used = proc_time.rtime;
process.x_cpu_last_used = (proc_time.xcpu_utime[process.last_processor] + proc_time.xcpu_stime[process.last_processor]);
process.mem_usage = 0;
process_table_cmdline[proc_cmd_full].sub_processes.insert(pids[i], (owned) process);
process.pid = process_it.pid;
process.alive = process_it.alive;
process.cmdline = process_it.cmdline;
process.last_processor = process_it.last_processor;
process.cpu_load = process_it.cpu_load;
process.x_cpu_load = process_it.x_cpu_load ;
process.cpu_last_used = process_it.cpu_last_used;
process.x_cpu_last_used = process_it.x_cpu_last_used;
process.mem_usage = process_it.mem_usage;
process_table_cmdline[process_it.cmdline].sub_processes.insert(process_it.pid, (owned) process);
}
}
else //update process or transform to group and add subrow
{
if(pids[i] == process_table_cmdline[proc_cmd_full].pid) //update process
if(process_it.pid == process_table_cmdline[process_it.cmdline].pid) //update process
{
unowned Process process = process_table_cmdline[proc_cmd_full];
process.last_processor = proc_state.last_processor;
process.cpu_load = (((double) (proc_time.rtime - process.cpu_last_used)) / (cpu_data.total - cpu_last_total)) * 100 * get_num_processors(); //TODO After fix bug bellow remove: * get_num_processors()
process.x_cpu_load = (((double) ((proc_time.xcpu_utime[process.last_processor] + proc_time.xcpu_stime[process.last_processor]) - process.x_cpu_last_used)) / (cpu_data.xcpu_total[process.last_processor] - x_cpu_last_total[process.last_processor])) * 100;
//FIX ME: It is always 0, libGTop bug propably
//GLib.stdout.printf("X_cpu: " + process.last_processor.to_string() + " " + (proc_time.xcpu_utime[process.last_processor] + proc_time.xcpu_stime[process.last_processor]).to_string() + "\n");
process.alive = true;
process.cpu_last_used = proc_time.rtime;
process.x_cpu_last_used = (proc_time.xcpu_utime[process.last_processor] + proc_time.xcpu_stime[process.last_processor]);
GTop.ProcMem proc_mem;
GTop.get_proc_mem (out proc_mem, process.pid);
process.mem_usage = ((double) (proc_mem.resident - proc_mem.share) / mem.total) * 100;
unowned Process process = process_table_cmdline[process_it.cmdline];
process.last_processor = process_it.last_processor;
process.cpu_load = process_it.cpu_load;
process.x_cpu_load = process_it.x_cpu_load ;
process.alive = process_it.alive;
process.cpu_last_used = process_it.cpu_last_used;
process.x_cpu_last_used = process_it.x_cpu_last_used;
process.mem_usage = process_it.mem_usage;
}
else //add transform to group and add subrow
{
process_table_cmdline[proc_cmd_full].sub_processes = new HashTable<pid_t?, Process>(int_hash, int_equal);
unowned Process process = process_table_cmdline[proc_cmd_full];
process_table_cmdline[process_it.cmdline].sub_processes = new HashTable<pid_t?, Process>(int_hash, int_equal);
unowned Process process = process_table_cmdline[process_it.cmdline];
var sub_process_one = new Process();
sub_process_one.pid = process.pid;
sub_process_one.pid = process_it.pid;
sub_process_one.alive = process.alive;
sub_process_one.cmdline = process.cmdline;
sub_process_one.last_processor = process.last_processor;
......@@ -289,44 +300,38 @@ namespace Usage
sub_process_one.cpu_last_used = process.cpu_last_used;
sub_process_one.x_cpu_last_used = process.x_cpu_last_used;
sub_process_one.mem_usage = process.mem_usage;
process_table_cmdline[proc_cmd_full].sub_processes.insert(sub_process_one.pid, (owned) sub_process_one);
process_table_cmdline[process_it.cmdline].sub_processes.insert(sub_process_one.pid, (owned) sub_process_one);
var sub_process = new Process();
sub_process.pid = pids[i];
sub_process.alive = true;
sub_process.cmdline = proc_cmd_full;
sub_process.last_processor = proc_state.last_processor;
sub_process.cpu_load = 0;
sub_process.x_cpu_load = 0;
sub_process.cpu_last_used = proc_time.rtime;
sub_process.x_cpu_last_used = (proc_time.xcpu_utime[sub_process.last_processor] + proc_time.xcpu_stime[sub_process.last_processor]);
sub_process.mem_usage = 0;
process_table_cmdline[proc_cmd_full].sub_processes.insert(pids[i], (owned) sub_process);
sub_process.pid = process_it.pid;
sub_process.alive = process_it.alive;
sub_process.cmdline = process_it.cmdline;
sub_process.last_processor = process_it.last_processor;
sub_process.cpu_load = process_it.cpu_load;
sub_process.x_cpu_load = process_it.x_cpu_load;
sub_process.cpu_last_used = process_it.cpu_last_used;
sub_process.x_cpu_last_used = process_it.x_cpu_last_used;
sub_process.mem_usage = process_it.mem_usage;
process_table_cmdline[process_it.cmdline].sub_processes.insert(process_it.pid, (owned) sub_process);
}
}
}
else //add process
{
var process = new Process();
process.pid = pids[i];
process.alive = true;
process.cmdline = proc_cmd_full;
process.last_processor = proc_state.last_processor;
process.cpu_load = 0;
process.x_cpu_load = 0;
process.cpu_last_used = proc_time.rtime;
process.x_cpu_last_used = (proc_time.xcpu_utime[process.last_processor] + proc_time.xcpu_stime[process.last_processor]);
process.mem_usage = 0;
process.pid = process_it.pid;
process.alive = process_it.alive;
process.cmdline = process_it.cmdline;
process.last_processor = process_it.last_processor;
process.cpu_load = process_it.cpu_load;
process.x_cpu_load = process_it.x_cpu_load;
process.cpu_last_used = process_it.cpu_last_used;
process.x_cpu_last_used = process_it.x_cpu_last_used;
process.mem_usage = process_it.mem_usage;
process_table_cmdline.insert(process.cmdline, (owned) process);
}
}
foreach(unowned Process process in process_table_pid.get_values())
{
if (process.alive == false)
process_table_pid.remove (process.pid);
}
foreach(unowned Process process in process_table_cmdline.get_values())
{
if(process.sub_processes == null)
......
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