summaryrefslogtreecommitdiffstats
path: root/src/main.rs
blob: c5c3165b82700a8f379285b4acf1fff6ef7c342a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
use sysinfo::{ProcessExt, ProcessStatus, RefreshKind, System, SystemExt};

// TODO: Fix this - CPU Up, and CPU Down!
enum ProcessSorting {
	CPU,
	MEM,
	PID,
	Status,
}

fn main() {
	let mut system = System::new();
	system.refresh_all();
	draw_sorted_processes(ProcessSorting::CPU, true, &system);
}

// Possible process info struct?
#[derive(Debug)]
struct ProcessInfo<'a> {
	pid: u32,
	cpu_usage: f32,
	mem_usage: u64,
	uptime: u64,
	command: &'a str,
	//status: &'a str,
	// TODO: Env?
}

fn get_status(status: ProcessStatus) -> &'static str {
	match status {
		ProcessStatus::Idle => "Idle",
		ProcessStatus::Run => "Run",
		ProcessStatus::Sleep => "Sleep",
		ProcessStatus::Zombie => "Zombie",
		ProcessStatus::Tracing => "Tracing",
		ProcessStatus::Dead => "Dead",
		_ => "Unknown",
	}
}

fn draw_sorted_processes(sorting_method: ProcessSorting, reverse_order: bool, sys: &System) {
	let process_hashmap = sys.get_process_list();

	// Read into a btreemap, based on sorting type.
	// TODO: Evaluate whether this is too slow!

	let mut process_vector: Vec<sysinfo::Process> = process_hashmap.iter().map(|(_, process)| process.clone()).collect();

	match sorting_method {
		ProcessSorting::CPU => process_vector.sort_by(|a, b| {
			let a_usage = a.cpu_usage();
			let b_usage = b.cpu_usage();

			if a_usage > b_usage {
				if reverse_order {
					std::cmp::Ordering::Less
				} else {
					std::cmp::Ordering::Greater
				}
			} else if a_usage < b_usage {
				if reverse_order {
					std::cmp::Ordering::Greater
				} else {
					std::cmp::Ordering::Less
				}
			} else {
				std::cmp::Ordering::Equal
			}
		}),
		ProcessSorting::MEM => {}
		ProcessSorting::PID => {}
		ProcessSorting::Status => {}
	}

	let mut formatted_vector: Vec<ProcessInfo> = Vec::new();
	for process in &mut process_vector {
		formatted_vector.push(ProcessInfo {
			cpu_usage: process.cpu_usage(),
			command: process.name(),
			mem_usage: process.memory(),
			uptime: process.start_time(),
			pid: process.pid() as u32,
		});
	}

	for process in formatted_vector {
		println!("{:?}", process);
	}
}

fn get_timestamped_temperature() {}

fn draw_temperatures() {}

fn get_timestamped_cpu_data() {}

fn draw_cpu_data() {}

fn get_timestamped_ram_data() {}

fn draw_ram_data() {}

fn get_timestamped_network_data() {}

fn draw_network_data() {}

fn get_timestamped_drive_data() {}

fn draw_drive_usage_data() {}