summaryrefslogtreecommitdiffstats
path: root/README.md
blob: 417ca136dd7d8a5e0d907aa02f7a9c6216c4a677 (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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# bottom

[![Build Status](https://travis-ci.com/ClementTsang/bottom.svg?token=1wvzVgp94E1TZyPNs8JF&branch=master)](https://travis-ci.com/ClementTsang/bottom) [![crates.io link](https://img.shields.io/crates/v/bottom.svg)](https://crates.io/crates/bottom)

A top clone, written in Rust. Inspired by both [gtop](https://github.com/aksakalli/gtop) and [gotop](https://github.com/cjbassi/gotop)

![Quick demo recording](assets/recording_1.gif)
_Note that the background you see is not part of the app, that's just because I use a slightly transparent terminal._

## Installation

### Linux

You can install by cloning and using `cargo build --release`, or download the pre-compiled binary in Releases. Note this needs the nightly toolchain if you are building.

### Windows

You can currently install by cloning and building yourself. Note this needs the nightly toolchain if you are building.

### MacOS

Currently, I'm unable to really dev or test on MacOS, so I'm not sure how well this will work, if at all. I'll try to source MacOS hardware to test this application.

## Usage

### Command line options

- `-h`, `--help` to show the help screen and exit (basically has all of the below CLI option info).

- `-a`, `--avgcpu` enables showing the average CPU usage on rustop.

- `-m`, `--dot-marker` uses a dot marker instead of the default braille marker. This is useful for things like Powershell which display braille markers incorrectly.

- `-c`, `--celsius` displays the temperature type in Celsius. This is the default.

- `-f`, `--fahrenheit` displays the temperature type in Fahrenheit. This is the default.

- `-k`, `--kelvin` displays the temperature type in Kelvin. This is the default.

- `-v`, `--version` displays the version number and exits.

- `-r <RATE>`, `--rate <RATE>` will set the refresh rate in _milliseconds_. Pick a range from 250ms to `UINT_MAX`. Defaults to 1000ms, and higher values may take more resources due to more frequent polling of data, and may be less accurate in some circumstances.

### Keybinds

#### General

- `q`, `Ctrl-C` to quit.

- `Up/k`, `Down/j`, `Left/h`, `Right/l` to navigate between panels.

- `Shift+Up` and `Shift+Down` scrolls through the list if the panel is a table (Temperature, Disks, Processes).

- `Esc` to close a dialog window (help or dd confirmation).

- `?` to get a help screen explaining the controls.

#### Processes Panel

- `dd` to kill the selected process - **I would highly recommend you to be careful using this, lest you accidentally kill the wrong process**.

- `c` to sort by CPU usage. Sorts in descending order by default. Press again to reverse sorting order.

- `m` to sort by memory usage. Sorts in descending order by default. Press again to reverse sorting order.

- `p` to sort by PID. Sorts in ascending order by default. Press again to reverse sorting order.

- `n` to sort by process name. Sorts in ascending order by default. Press again to reverse sorting order.

### Mouse Actions

[* Scrolling either scrolls through the list if the panel is a table (Temperature, Disks, Processes), or zooms in and out if it is a chart.]: <>

- Scrolling currently only scrolls through the list if you are on the Processes panel. This will change in the future.

## Regarding Process Use Percentage (on Linux)

I cannot guarantee whether they are 100% accurate. I'm using a technique I found online which seems to be a better indicator of process use percentage at the current time, rather than pulling from, say, `ps` (which is average CPU usage over the _entire lifespan_ of the process). I found the options from the library I used to get other data (heim) to be a bit too inaccurate in my testing.

For reference, the formula I am using to calculate CPU process usage is along the lines of:

```rust
let idle = idle + iowait;
let non_idle = user + nice + system + irq + softirq + steal + guest;

let total = idle + non_idle;
let prev_total = prev_idle + prev_non_idle; // Both of these values are calculated using the same formula from the previous polling

let total_delta : f64 = total - prev_total;
let idle_delta : f64 = idle - prev_idle;

let final_delta : f64 = total_delta - idle_delta;

//...

// Get utime and stime from reading /proc/<PID>/stat
let after_proc_val = utime + stime;
(after_proc_val - before_proc_val) / cpu_usage * 100_f64; //This gives your use percentage.  before_proc_val comes from the previous polling
```

Any suggestions on more accurate data is welcome! Note all other fields should be accurate.

## Thanks

- As mentioned, this project is very much inspired by both [gotop](https://github.com/cjbassi/gotop) and [gtop](https://github.com/aksakalli/gtop) .

- This application was written with the following libraries:
  - [chrono](https://github.com/chronotope/chrono)
  - [clap](https://github.com/clap-rs/clap)
  - [crossterm](https://github.com/TimonPost/crossterm)
  - [failure](https://github.com/rust-lang-nursery/failure)
  - [fern](https://github.com/daboross/fern)
  - [futures-rs](https://github.com/rust-lang-nursery/futures-rs)
  - [futures-timer](https://github.com/rustasync/futures-timer)
  - [heim](https://github.com/heim-rs/heim)
  - [log](https://github.com/rust-lang-nursery/log)
  - [sysinfo](https://github.com/GuillaumeGomez/sysinfo)
  - [tokio](https://github.com/tokio-rs/tokio)
  - [tui-rs](https://github.com/fdehau/tui-rs) (note I used a fork due to some issues I faced, you can find that [here](https://github.com/ClementTsang/tui-rs))
  - [winapi](https://github.com/retep998/winapi-rs)

## Why

I was looking to try writing more things in Rust, and I love the gotop tool. And thus, this project was born.