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

Backend is more safe for programmers. (fields in Process class not are public).

Separated Utils.
Version 0.3.8
parent 6524c38a
......@@ -13,6 +13,7 @@ New GNOME Usage!
- [x] Add Running/Sleeping/Dead label
- [ ] Support other architectures than x86_64 (netinfo precompiled library)
- [ ] Fix bug with refreshing ProcessListBox 50% (focus, and click when refresh)
- [ ] Search in processes
- [ ] DEB packages
- [ ] Storage view - 0%
- [ ] Power view (Design?)
......@@ -20,13 +21,13 @@ New GNOME Usage!
- [ ] Data view - 0%
##Installation from RPM
[Download RPM](https://github.com/petr-stety-stetka/gnome-usage/raw/master/rpmbuild/RPMS/x86_64/gnome-usage-0.3.7-1.x86_64.rpm)
[Download RPM](https://github.com/petr-stety-stetka/gnome-usage/raw/master/rpmbuild/RPMS/x86_64/gnome-usage-0.3.8-1.x86_64.rpm)
##Run
In terminal run ```gnome-usage``` command or run GNOME Usage application from app launcher.
##Version
Actual version is 0.3.7
Actual version is 0.3.8
##Compilation from sources:
```
......
No preview for this file type
......@@ -5,7 +5,7 @@ project_name: gnome-usage
vala_binary: src/gnome-usage
version: 0.3.6
version: 0.3.8
*vala_vapi: vapis/better.vapi
*vala_vapi: vapis/egg.vapi
*vala_vapi: vapis/glibtop.vapi
......@@ -58,10 +58,13 @@ c_library: gmodule-2.0 m rt gtop-2.0 ${CMAKE_SOURCE_DIR}/external/netinfo/libnet
*vala_source: settings.vala
*vala_source: storage-graph.vala
*vala_source: storage-list-box.vala
*vala_source: storage-list.vala
*vala_source: storage-row.vala
*vala_source: storage-view.vala
*vala_source: sub-process-list-box.vala
*vala_source: sub-process-sub-row.vala
*vala_source: system-monitor.vala
*vala_source: utils.vala
*vala_source: view.vala
*vala_source: window.vala
c_source: ../external/egg/egg-animation.c
......@@ -152,17 +155,16 @@ translate: c src/../external/rg/rg-ring.c
translate: c src/../external/rg/rg-stacked-renderer.c
translate: c src/../external/rg/rg-table.c
*translate: vala src/cookie-graph.vala
*translate: vala src/network-monitor.vala
*translate: vala src/storage-list-box.vala
*translate: vala src/system-monitor.vala
*translate: vala src/memory-graph.vala
*translate: vala src/header-bar.vala
*translate: vala src/process.vala
*translate: vala src/cpu-monitor.vala
*translate: vala src/process-list-box.vala
*translate: vala src/disk-graph.vala
*translate: vala src/storage-list-box.vala
*translate: vala src/sub-process-list-box.vala
*translate: vala src/cpu-monitor.vala
*translate: vala src/process-row.vala
*translate: vala src/process-dialog.vala
*translate: vala src/disk-sub-view.vala
*translate: vala src/sub-process-sub-row.vala
*translate: vala src/graph-stack-switcher.vala
*translate: vala src/network-graph-table.vala
*translate: vala src/graph-box.vala
......@@ -174,18 +176,22 @@ translate: c src/../external/rg/rg-table.c
*translate: vala src/graph-block.vala
*translate: vala src/memory-graph-table.vala
*translate: vala src/color-rectangle.vala
*translate: vala src/process-list-box.vala
*translate: vala src/system-monitor.vala
*translate: vala src/process.vala
*translate: vala src/memory-monitor.vala
*translate: vala src/data-view.vala
*translate: vala src/settings.vala
*translate: vala src/storage-graph.vala
*translate: vala src/view.vala
*translate: vala src/cpu-graph.vala
*translate: vala src/process-row.vala
*translate: vala src/utils.vala
*translate: vala src/window.vala
*translate: vala src/storage-list.vala
*translate: vala src/storage-view.vala
*translate: vala src/storage-row.vala
*translate: vala src/sub-process-list-box.vala
*translate: vala src/network-monitor.vala
*translate: vala src/sub-process-sub-row.vala
*translate: vala src/graph-block-row.vala
*translate: vala src/memory-monitor.vala
*translate: vala src/network-graph.vala
*translate: vala src/gnome-usage.vala
*translate: vala src/application.vala
......
......@@ -32,10 +32,13 @@ src/process.vala
src/settings.vala
src/storage-graph.vala
src/storage-list-box.vala
src/storage-list.vala
src/storage-row.vala
src/storage-view.vala
src/sub-process-list-box.vala
src/sub-process-sub-row.vala
src/system-monitor.vala
src/utils.vala
src/view.vala
src/window.vala
src/../external/egg/egg-animation.c
......
Name: gnome-usage
Version: 0.3.7
Version: 0.3.8
Release: 1
License: GPLv3
Summary: New GNOME Usage!
......
......@@ -7,13 +7,13 @@ set (GETTEXT_PACKAGE "gnome-usage")
set (RELEASE_NAME "gnome-usage")
set (CMAKE_C_FLAGS "")
set (PREFIX ${CMAKE_INSTALL_PREFIX})
set (VERSION "0.3.6")
set (VERSION "0.3.8")
set (TESTSRCDIR "${CMAKE_SOURCE_DIR}")
set (DOLLAR "$")
configure_file (${CMAKE_SOURCE_DIR}/src/Config.vala.cmake ${CMAKE_BINARY_DIR}/src/Config.vala)
add_definitions(-DGETTEXT_PACKAGE=\"${GETTEXT_PACKAGE}\")
set (VERSION "0.3.6")
set (VERSION "0.3.8")
add_definitions (${DEPS_CFLAGS})
link_libraries ( ${DEPS_LIBRARIES} )
link_directories ( ${DEPS_LIBRARY_DIRS} )
......@@ -70,10 +70,13 @@ set (APP_SOURCES ${APP_SOURCES} process.vala)
set (APP_SOURCES ${APP_SOURCES} settings.vala)
set (APP_SOURCES ${APP_SOURCES} storage-graph.vala)
set (APP_SOURCES ${APP_SOURCES} storage-list-box.vala)
set (APP_SOURCES ${APP_SOURCES} storage-list.vala)
set (APP_SOURCES ${APP_SOURCES} storage-row.vala)
set (APP_SOURCES ${APP_SOURCES} storage-view.vala)
set (APP_SOURCES ${APP_SOURCES} sub-process-list-box.vala)
set (APP_SOURCES ${APP_SOURCES} sub-process-sub-row.vala)
set (APP_SOURCES ${APP_SOURCES} system-monitor.vala)
set (APP_SOURCES ${APP_SOURCES} utils.vala)
set (APP_SOURCES ${APP_SOURCES} view.vala)
set (APP_SOURCES ${APP_SOURCES} window.vala)
......
......@@ -50,19 +50,20 @@ namespace Usage
return x_cpu_load;
}
public void get_cpu_info_for_pid(pid_t pid, ref uint process_last_processor, ref double process_cpu_load, ref uint64 process_cpu_last_used, ref uint64 process_x_cpu_last_used)
public void update_process_info(ref Process process)
{
GTop.ProcTime proc_time;
GTop.ProcState proc_state;
GTop.get_proc_time (out proc_time, pid);
GTop.get_proc_state (out proc_state, pid);
GTop.get_proc_time (out proc_time, process.get_pid());
GTop.get_proc_state (out proc_state, process.get_pid());
process_last_processor = proc_state.last_processor;
process_cpu_load = (((double) (proc_time.rtime - process_cpu_last_used)) / cpu_last_total_step) * 100 * get_num_processors();
process_cpu_load = double.min(100, process_cpu_load);
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.set_last_processor(proc_state.last_processor);
double cpu_load = (((double) (proc_time.rtime - process.get_cpu_last_used())) / cpu_last_total_step) * 100 * get_num_processors();
cpu_load = double.min(100, cpu_load);
process.set_cpu_load(cpu_load);
process.set_cpu_last_used(proc_time.rtime);
process.set_x_cpu_last_used(proc_time.xcpu_utime[process.get_last_processor()] + proc_time.xcpu_stime[process.get_last_processor()]);
}
}
}
\ No newline at end of file
......@@ -30,16 +30,16 @@ namespace Usage
return swap_usage;
}
public void get_memory_info_for_pid(pid_t pid, ref uint64 mem_usage, ref double mem_usage_percentages)
public void update_process_info(ref Process process)
{
GTop.Mem mem;
GTop.ProcMem proc_mem;
GTop.get_mem (out mem);
GTop.get_proc_mem (out proc_mem, pid);
GTop.get_proc_mem (out proc_mem, process.get_pid());
mem_usage = (proc_mem.resident - proc_mem.share);
mem_usage_percentages = ((double) (proc_mem.resident - proc_mem.share) / mem.total) * 100;
process.set_mem_usage(proc_mem.resident - proc_mem.share);
process.set_mem_usage_percentages(((double) (proc_mem.resident - proc_mem.share) / mem.total) * 100);
}
}
}
\ No newline at end of file
......@@ -92,18 +92,18 @@ namespace Usage
return net_usage;
}
public void get_network_info_for_pid(pid_t pid, ref uint64 download, ref uint64 upload, ref uint64 all)
public void update_process_info(ref Process process)
{
uint64 bytes_out;
uint64 bytes_in;
uint64 bytes_all;
handle_error(stat.get_bytes_per_attr(pid, InoutEnum.OUTGOING, null, out bytes_out));
handle_error(stat.get_bytes_per_attr(pid, InoutEnum.INCOMING, null, out bytes_in));
handle_error(stat.get_bytes_per_pid(pid, out bytes_all));
handle_error(stat.get_bytes_per_attr(process.get_pid(), InoutEnum.OUTGOING, null, out bytes_out));
handle_error(stat.get_bytes_per_attr(process.get_pid(), InoutEnum.INCOMING, null, out bytes_in));
handle_error(stat.get_bytes_per_pid(process.get_pid(), out bytes_all));
upload += bytes_out;
download += bytes_in;
all += bytes_all;
process.set_net_upload(process.get_net_upload() + bytes_out);
process.set_net_download(process.get_net_download() + bytes_in);
process.set_net_all(process.get_net_all() + bytes_all);
}
private void handle_error(ErrorCode e)
......
......@@ -75,14 +75,14 @@ namespace Usage
if(data != null)
{
app_cpu_load = (int) data.cpu_load;
app_memory_usage = (int) data.mem_usage_percentages;
processor_graph_block.update((int) data.last_processor, app_cpu_load, (int) monitor.x_cpu_load[data.last_processor]-app_cpu_load);
app_cpu_load = (int) data.get_cpu_load();
app_memory_usage = (int) data.get_mem_usage_percentages();
processor_graph_block.update((int) data.get_last_processor(), app_cpu_load, (int) monitor.x_cpu_load[data.get_last_processor()]-app_cpu_load);
double download_one_percentage = monitor.net_download / 100;
if(download_one_percentage != 0)
{
app_download = (int) (data.net_download / download_one_percentage);
app_download = (int) (data.get_net_download() / download_one_percentage);
app_download = int.min(app_download, 100);
other_download = 100 - app_download;
}
......@@ -90,11 +90,11 @@ namespace Usage
double upload_one_percentage = monitor.net_upload / 100;
if(upload_one_percentage != 0)
{
app_upload = (int) (data.net_upload / upload_one_percentage);
app_upload = (int) (data.get_net_upload() / upload_one_percentage);
app_upload = int.min(app_upload, 100);
other_upload = 100 - app_upload;
}
process_status = data.status;
process_status = data.get_status();
}
else
processor_graph_block.update(-1, 0, (int) monitor.cpu_load);
......
......@@ -32,7 +32,7 @@ namespace Usage
if(opened_row != process_row)
{
process_row.activate();
if(process_row.process.sub_processes != null)
if(process_row.process.get_sub_processes() != null)
opened_row = process_row;
else
opened_row = null;
......@@ -45,7 +45,7 @@ namespace Usage
{
if(child != null)
{
focused_row_cmdline = ((ProcessRow) child).process.cmdline;
focused_row_cmdline = ((ProcessRow) child).process.get_cmdline();
//GLib.stdout.printf("focused: " + focused_row_cmdline+ "\n");
}
});
......@@ -99,7 +99,7 @@ namespace Usage
bool opened = false;
if(opened_row != null)
if(process.cmdline == opened_row.process.cmdline)
if(process.get_cmdline() == opened_row.process.get_cmdline())
opened = true;
var row = new ProcessRow(process, type, opened);
......@@ -108,7 +108,7 @@ namespace Usage
if(focused_row_cmdline != null)
{
if(process.cmdline == focused_row_cmdline)
if(process.get_cmdline() == focused_row_cmdline)
{
//row.grab_focus(); TODO not working
//GLib.stdout.printf("grab focus for: " + focused_row_cmdline+ "\n");
......@@ -140,11 +140,11 @@ namespace Usage
{
default:
case ProcessListBoxType.PROCESSOR:
return (int) ((uint64) (p_a.cpu_load < p_b.cpu_load) - (uint64) (p_a.cpu_load > p_b.cpu_load));
return (int) ((uint64) (p_a.get_cpu_load() < p_b.get_cpu_load()) - (uint64) (p_a.get_cpu_load() > p_b.get_cpu_load()));
case ProcessListBoxType.MEMORY:
return (int) ((uint64) (p_a.mem_usage < p_b.mem_usage) - (uint64) (p_a.mem_usage > p_b.mem_usage));
return (int) ((uint64) (p_a.get_mem_usage() < p_b.get_mem_usage()) - (uint64) (p_a.get_mem_usage() > p_b.get_mem_usage()));
case ProcessListBoxType.NETWORK:
return (int) ((uint64) (p_a.net_all < p_b.net_all) - (uint64) (p_a.net_all > p_b.net_all));
return (int) ((uint64) (p_a.get_net_all() < p_b.get_net_all()) - (uint64) (p_a.get_net_all() > p_b.get_net_all()));
}
}
}
......
......@@ -41,7 +41,7 @@ namespace Usage
row_box.pack_end(load_label, false, true, 10);
box.pack_start(row_box, false, true, 0);
if(process.sub_processes != null)
if(process.get_sub_processes() != null)
{
group = true;
sub_process_list_box = new SubProcessListBox(process, type);
......@@ -78,10 +78,10 @@ namespace Usage
}
commandline = Path.get_basename(commandline);
string process_full_cmd = process.cmdline + " " + process.cmdline_parameter;
string process_full_cmd = process.get_cmdline() + " " + process.get_cmdline_parameter();
if(commandline == process_full_cmd)
app_info = info;
else if(commandline.contains("google-" + process.cmdline + "-")) //Fix for Google Chrome naming
else if(commandline.contains("google-" + process.get_cmdline() + "-")) //Fix for Google Chrome naming
app_info = info;
if(app_info == null)
......@@ -97,7 +97,7 @@ namespace Usage
commandline = info.get_commandline();
commandline = Path.get_basename(commandline);
if(commandline == process.cmdline)
if(commandline == process.get_cmdline())
app_info = info;
}
}
......@@ -126,7 +126,7 @@ namespace Usage
}
else
{
display_name = process.cmdline;
display_name = process.get_cmdline();
}
if(icon == null)
......@@ -141,21 +141,6 @@ 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<uint64?> sort = (a, b) => {
......@@ -169,8 +154,8 @@ namespace Usage
{
string values_string = "";
var values = new GLib.List<uint64?>();
foreach(Process sub_process in process.sub_processes.get_values())
values.insert_sorted((uint64) sub_process.cpu_load, sort);
foreach(Process sub_process in process.get_sub_processes().get_values())
values.insert_sorted((uint64) sub_process.get_cpu_load(), sort);
foreach(uint64 value in values)
values_string += " " + value.to_string() + " %";
......@@ -178,9 +163,9 @@ namespace Usage
load_label.set_label(values_string);
}
else
load_label.set_label(((int) process.cpu_load).to_string() + " %");
load_label.set_label(((int) process.get_cpu_load()).to_string() + " %");
if(process.cpu_load >= 90)
if(process.get_cpu_load() >= 90)
max_usage = true;
else
max_usage = false;
......@@ -190,18 +175,18 @@ namespace Usage
{
string values_string = "";
var values = new GLib.List<uint64?>();
foreach(Process sub_process in process.sub_processes.get_values())
values.insert_sorted(sub_process.mem_usage, sort);
foreach(Process sub_process in process.get_sub_processes().get_values())
values.insert_sorted(sub_process.get_mem_usage(), sort);
foreach(uint64 value in values)
values_string += " " + format_size_values(value);
values_string += " " + Utils.format_size_values(value);
load_label.set_label(values_string);
}
else
load_label.set_label(format_size_values(process.mem_usage));
load_label.set_label(Utils.format_size_values(process.get_mem_usage()));
if(process.mem_usage_percentages >= 90)
if(process.get_mem_usage_percentages() >= 90)
max_usage = true;
else
max_usage = false;
......@@ -211,17 +196,17 @@ namespace Usage
{
string values_string = "";
var values = new GLib.List<uint64?>();
foreach(Process sub_process in process.sub_processes.get_values())
values.insert_sorted((uint64) sub_process.net_all, sort);
foreach(Process sub_process in process.get_sub_processes().get_values())
values.insert_sorted((uint64) sub_process.get_net_all(), sort);
foreach(uint64 value in values)
values_string += " " + format_size_values(value);
values_string += " " + Utils.format_size_values(value);
load_label.set_label(values_string);
}
else
{
load_label.set_label(format_size_values(process.net_all));
load_label.set_label(Utils.format_size_values(process.get_net_all()));
}
break;
}
......@@ -258,7 +243,7 @@ namespace Usage
}
else
{
var dialog = new ProcessDialog(process.pid, display_name);
var dialog = new ProcessDialog(process.get_pid(), display_name);
dialog.show_all();
}
}
......
......@@ -5,22 +5,217 @@ namespace Usage
[Compact]
public class Process : Object
{
internal pid_t pid;
internal string cmdline;
internal string cmdline_parameter; //Isn't parameters as "-p" etc, but parameter for running app, for ex. "--writer' with libreoffice, or "privacy" with gnome-control-center
internal double cpu_load;
internal double x_cpu_load;
internal uint64 cpu_last_used;
internal uint64 x_cpu_last_used;
internal uint last_processor;
internal uint64 mem_usage;
internal double mem_usage_percentages;
internal uint64 net_download;
internal uint64 net_upload;
internal uint64 net_all;
internal HashTable<pid_t?, Process> sub_processes;
internal bool alive;
internal ProcessStatus status;
pid_t pid;
string cmdline;
string cmdline_parameter; //Isn't parameters as "-p" etc, but parameter for running app, for ex. "--writer' with libreoffice, or "privacy" with gnome-control-center
double cpu_load;
double x_cpu_load;
uint64 cpu_last_used;
uint64 x_cpu_last_used;
uint last_processor;
uint64 mem_usage;
double mem_usage_percentages;
uint64 net_download;
uint64 net_upload;
uint64 net_all;
HashTable<pid_t?, Process>? sub_processes;
bool alive;
ProcessStatus status;
public Process(pid_t pid, string cmdline, string cmdline_parameter)
{
this.pid = pid;
this.cmdline = cmdline;
this.cmdline_parameter = cmdline_parameter;
this.cpu_load = 0;
this.x_cpu_load = 0;
this.cpu_last_used = 0;
this.x_cpu_last_used = 0;
this.last_processor = 0;
this.mem_usage = 0;
this.mem_usage_percentages = 0;
this.net_download = 0;
this.net_upload = 0;
this.net_all = 0;
this.sub_processes = null;
this.alive = true;
this.status = ProcessStatus.SLEEPING;
}
public void update_from_process(Process process)
{
this.last_processor = process.get_last_processor();
this.cpu_load = process.get_cpu_load();
this.x_cpu_load = process.get_x_cpu_load();
this.cpu_last_used = process.get_cpu_last_used();
this.x_cpu_last_used = process.get_x_cpu_last_used();
this.mem_usage = process.get_mem_usage();
this.net_download = process.get_net_download();
this.net_upload = process.get_net_upload();
this.net_all = process.get_net_all();
this.alive = process.get_alive();
this.status = process.get_status();
}
public pid_t get_pid()
{
return pid;
}
public void set_pid(pid_t pid)
{
this.pid = pid;
}
public string get_cmdline()
{
return cmdline;
}
public void set_cmdline(string cmdline)
{
this.cmdline = cmdline;
}
public string get_cmdline_parameter()
{
return cmdline_parameter;
}
public void set_cmdline_parameter(string cmdline_parameter)
{
this.cmdline_parameter = cmdline_parameter;
}
public double get_cpu_load()
{
return cpu_load;
}
public void set_cpu_load(double cpu_load)
{
this.cpu_load = cpu_load;
}
public double get_x_cpu_load()
{
return x_cpu_load;
}
public void set_x_cpu_load(double x_cpu_load)
{
this.x_cpu_load = x_cpu_load;
}
public uint64 get_cpu_last_used()
{
return cpu_last_used;
}
public void set_cpu_last_used(uint64 cpu_last_used)
{
this.cpu_last_used = cpu_last_used;
}
public uint64 get_x_cpu_last_used()
{
return x_cpu_last_used;
}
public void set_x_cpu_last_used(uint64 x_cpu_last_used)
{
this.x_cpu_last_used = x_cpu_last_used;
}
public uint get_last_processor()
{
return last_processor;
}
public void set_last_processor(uint last_processor)
{
this.last_processor = last_processor;
}
public uint64 get_mem_usage()
{
return mem_usage;
}
public void set_mem_usage(uint64 mem_usage)
{
this.mem_usage = mem_usage;
}
public double get_mem_usage_percentages()
{