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

Added automatic choose size suffix.

Fixed unit64.
parent 462d6782
No preview for this file type
......@@ -57,7 +57,7 @@ namespace Usage
upload_usage += bytes_out - bytes_out_unasigned;
download_usage += bytes_in - bytes_in_unasigned;
net_usage += bytes_all - bytes_all_unasigned;// TODO clear it every 5sec or? Mabe 30 sec will beter
net_usage += bytes_all - bytes_all_unasigned;
handle_error(netinfo.clear());
}
......
......@@ -118,15 +118,18 @@ namespace Usage
private int sort(GLib.CompareDataFunc.G a, GLib.CompareDataFunc.G b)
{
Process p_a = (Process) a;
Process p_b = (Process) b;
switch(type)
{
default:
case ProcessListBoxType.PROCESSOR:
return (int) ((Process) b).cpu_load - (int) ((Process) a).cpu_load;
return (int) ((uint64) (p_a.cpu_load < p_b.cpu_load) - (uint64) (p_a.cpu_load > p_b.cpu_load));
case ProcessListBoxType.MEMORY:
return (int) ((Process) b).mem_usage - (int) ((Process) a).mem_usage;
return (int) ((uint64) (p_a.mem_usage < p_b.mem_usage) - (uint64) (p_a.mem_usage > p_b.mem_usage));
case ProcessListBoxType.NETWORK:
return (int) ((Process) b).net_all - (int) ((Process) a).net_all;
return (int) ((uint64) (p_a.net_all < p_b.net_all) - (uint64) (p_a.net_all > p_b.net_all));
}
}
}
......
......@@ -136,10 +136,25 @@ namespace Usage
}
public static string format_size_values(uint64 value)
{
if(value >= 1000000000000)
return "%.3f TB".printf((double) value / 1000000000000d);
else if(value >= 1000000000)
return "%.1f GB".printf((double) value / 1000000000d);
else if(value >= 1000000)
return(value / 1000000).to_string() + " MB";
else if(value >= 1000)
return (value / 1000).to_string() + " KB";
else
return value.to_string() + " B";
}
private void update()
{
CompareFunc<int> sort = (a, b) => {
return (int) (a < b) - (int) (a > b);
CompareFunc<uint64?> sort = (a, b) => {
return (int) ((uint64) (a < b) - (uint64) (a > b));
};
switch(type)
......@@ -148,11 +163,11 @@ namespace Usage
if(process.sub_processes != null)
{
string values_string = "";
var values = new GLib.List<int>();
var values = new GLib.List<uint64?>();
foreach(Process sub_process in process.sub_processes.get_values())
values.insert_sorted((int) sub_process.cpu_load, sort);
values.insert_sorted((uint64) sub_process.cpu_load, sort);
foreach(int value in values)
foreach(uint64 value in values)
values_string += " " + value.to_string() + " %";
load_label.set_label(values_string);
......@@ -169,17 +184,17 @@ namespace Usage
if(process.sub_processes != null)
{
string values_string = "";
var values = new GLib.List<int>();
var values = new GLib.List<uint64?>();
foreach(Process sub_process in process.sub_processes.get_values())
values.insert_sorted((int) sub_process.mem_usage, sort);
values.insert_sorted(sub_process.mem_usage, sort);
foreach(int value in values)
values_string += " " + ((int) (value/1000000)).to_string() + " MB";
foreach(uint64 value in values)
values_string += " " + format_size_values(value);
load_label.set_label(values_string);
}
else
load_label.set_label(((int) process.mem_usage/1000000).to_string() + " MB");
load_label.set_label(format_size_values(process.mem_usage));
if(process.mem_usage_percentages >= 90)
max_usage = true;
......@@ -190,18 +205,18 @@ namespace Usage
if(process.sub_processes != null)
{
string values_string = "";
var values = new GLib.List<int>();
var values = new GLib.List<uint64?>();
foreach(Process sub_process in process.sub_processes.get_values())
values.insert_sorted((int) sub_process.net_all, sort);
values.insert_sorted((uint64) sub_process.net_all, sort);
foreach(int value in values)
values_string += " " + value.to_string() + " B";
foreach(uint64 value in values)
values_string += " " + format_size_values(value);
load_label.set_label(values_string);
}
else
{
load_label.set_label(((int) process.net_all).to_string() + " B");
load_label.set_label(format_size_values(process.net_all));
}
break;
}
......
......@@ -65,15 +65,18 @@ namespace Usage
private int sort(GLib.CompareDataFunc.G a, GLib.CompareDataFunc.G b)
{
Process p_a = (Process) a;
Process p_b = (Process) b;
switch(type)
{
default:
case ProcessListBoxType.PROCESSOR:
return (int) ((Process) b).cpu_load - (int) ((Process) a).cpu_load;
return (int) ((uint64) (p_a.cpu_load < p_b.cpu_load) - (uint64) (p_a.cpu_load > p_b.cpu_load));
case ProcessListBoxType.MEMORY:
return (int) ((Process) b).mem_usage - (int) ((Process) a).mem_usage;
return (int) ((uint64) (p_a.mem_usage < p_b.mem_usage) - (uint64) (p_a.mem_usage > p_b.mem_usage));
case ProcessListBoxType.NETWORK:
return (int) ((Process) b).net_all - (int) ((Process) a).net_all;
return (int) ((uint64) (p_a.net_all < p_b.net_all) - (uint64) (p_a.net_all > p_b.net_all));
}
}
}
......
......@@ -43,7 +43,7 @@ namespace Usage
switch(type)
{
case ProcessListBoxType.PROCESSOR:
load_label.set_label(((int) process.cpu_load).to_string() + " %");
load_label.set_label(((uint64) process.cpu_load).to_string() + " %");
if(process.cpu_load >= 90)
max_usage = true;
......@@ -51,7 +51,7 @@ namespace Usage
max_usage = false;
break;
case ProcessListBoxType.MEMORY:
load_label.set_label(((int) process.mem_usage/1000000).to_string() + " MB");
load_label.set_label(ProcessRow.format_size_values(process.mem_usage));
if(process.mem_usage_percentages >= 90)
max_usage = true;
......@@ -59,7 +59,7 @@ namespace Usage
max_usage = false;
break;
case ProcessListBoxType.NETWORK:
load_label.set_label(((int) process.net_all).to_string() + " B");
load_label.set_label(ProcessRow.format_size_values(process.net_all));
break;
}
}
......
......@@ -128,7 +128,7 @@ namespace Usage
GTop.Proclist proclist;
var pids = GTop.get_proclist (out proclist, process_mode, uid);
for(int i = 0; i < proclist.number; i++)
for(uint i = 0; i < proclist.number; i++)
{
if (!(pids[i] in process_table_pid))
{
......@@ -396,20 +396,27 @@ namespace Usage
}
else
{
int max_cpu_load = 0;
int mem_usage = 0;
double cpu_load = 0;
uint64 mem_usage = 0;
uint64 net_all = 0;
uint64 net_download = 0;
uint64 net_upload = 0;
foreach(unowned Process sub_process in process.sub_processes.get_values())
{
if (sub_process.alive == false)
process.sub_processes.remove(sub_process.pid);
if(sub_process.cpu_load > max_cpu_load)
max_cpu_load = (int) sub_process.cpu_load;
mem_usage += (int) sub_process.mem_usage;
cpu_load += sub_process.cpu_load;
mem_usage += sub_process.mem_usage;
net_all += sub_process.net_all;
net_download += sub_process.net_download;
net_upload += sub_process.net_upload;
}
process.cpu_load = max_cpu_load;
process.cpu_load = cpu_load;
process.mem_usage = mem_usage;
process.net_all = net_all;
process.net_download = net_download;
process.net_upload = net_upload;
if(process.sub_processes.size() == 1) //tranform to process
{
......
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