mirror of
https://github.com/Cyrix126/gupaxx.git
synced 2024-12-22 22:59:27 +00:00
update inlines
This commit is contained in:
parent
582f915977
commit
9df40a79bf
14 changed files with 225 additions and 89 deletions
2
external/egui
vendored
2
external/egui
vendored
|
@ -1 +1 @@
|
|||
Subproject commit 62b4d427c01201898914594a9d00d1576bc23432
|
||||
Subproject commit 9cf535bd50b2602b0bce45c718d164bae2b4ed77
|
|
@ -4,7 +4,8 @@
|
|||
use crate::constants::*;
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
#[inline]
|
||||
#[cold]
|
||||
#[inline(never)]
|
||||
// Clamp the scaling resolution `f32` to a known good `f32`.
|
||||
pub fn clamp_scale(scale: f32) -> f32 {
|
||||
// Make sure it is finite.
|
||||
|
|
19
src/gupax.rs
19
src/gupax.rs
|
@ -82,8 +82,21 @@ pub enum Ratio {
|
|||
|
||||
//---------------------------------------------------------------------------------------------------- Gupax
|
||||
impl crate::disk::Gupax {
|
||||
#[inline(always)]
|
||||
pub fn show(&mut self, og: &Arc<Mutex<State>>, state_path: &Path, update: &Arc<Mutex<Update>>, file_window: &Arc<Mutex<FileWindow>>, error_state: &mut ErrorState, restart: &Arc<Mutex<Restart>>, width: f32, height: f32, frame: &mut eframe::Frame, _ctx: &egui::Context, ui: &mut egui::Ui) {
|
||||
#[inline(always)] // called once
|
||||
pub fn show(
|
||||
&mut self,
|
||||
og: &Arc<Mutex<State>>,
|
||||
state_path: &Path,
|
||||
update: &Arc<Mutex<Update>>,
|
||||
file_window: &Arc<Mutex<FileWindow>>,
|
||||
error_state: &mut ErrorState,
|
||||
restart: &Arc<Mutex<Restart>>,
|
||||
width: f32,
|
||||
height: f32,
|
||||
frame: &mut eframe::Frame,
|
||||
_ctx: &egui::Context,
|
||||
ui: &mut egui::Ui
|
||||
) {
|
||||
// Update button + Progress bar
|
||||
debug!("Gupax Tab | Rendering [Update] button + progress bar");
|
||||
ui.group(|ui| {
|
||||
|
@ -273,6 +286,8 @@ impl crate::disk::Gupax {
|
|||
}
|
||||
}
|
||||
|
||||
#[cold]
|
||||
#[inline(never)]
|
||||
fn spawn_file_window_thread(file_window: &Arc<Mutex<FileWindow>>, file_type: FileType) {
|
||||
use FileType::*;
|
||||
let name = match file_type {
|
||||
|
|
|
@ -177,10 +177,12 @@ impl Process {
|
|||
}
|
||||
|
||||
// Borrow a [&str], return an owned split collection
|
||||
#[inline]
|
||||
pub fn parse_args(args: &str) -> Vec<String> {
|
||||
args.split_whitespace().map(|s| s.to_owned()).collect()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
// Convenience functions
|
||||
pub fn is_alive(&self) -> bool {
|
||||
self.state == ProcessState::Alive ||
|
||||
|
@ -189,14 +191,17 @@ impl Process {
|
|||
self.state == ProcessState::NotMining
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn is_waiting(&self) -> bool {
|
||||
self.state == ProcessState::Middle || self.state == ProcessState::Waiting
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn is_syncing(&self) -> bool {
|
||||
self.state == ProcessState::Syncing
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn is_not_mining(&self) -> bool {
|
||||
self.state == ProcessState::NotMining
|
||||
}
|
||||
|
@ -268,6 +273,8 @@ impl Helper {
|
|||
}
|
||||
}
|
||||
|
||||
#[cold]
|
||||
#[inline(never)]
|
||||
fn read_pty_xmrig(output_parse: Arc<Mutex<String>>, output_pub: Arc<Mutex<String>>, reader: Box<dyn std::io::Read + Send>) {
|
||||
use std::io::BufRead;
|
||||
let mut stdout = std::io::BufReader::new(reader).lines();
|
||||
|
@ -293,6 +300,8 @@ impl Helper {
|
|||
}
|
||||
}
|
||||
|
||||
#[cold]
|
||||
#[inline(never)]
|
||||
fn read_pty_p2pool(output_parse: Arc<Mutex<String>>, output_pub: Arc<Mutex<String>>, reader: Box<dyn std::io::Read + Send>, gupax_p2pool_api: Arc<Mutex<GupaxP2poolApi>>) {
|
||||
use std::io::BufRead;
|
||||
let mut stdout = std::io::BufReader::new(reader).lines();
|
||||
|
@ -349,6 +358,8 @@ impl Helper {
|
|||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------- P2Pool specific
|
||||
#[cold]
|
||||
#[inline(never)]
|
||||
// Just sets some signals for the watchdog thread to pick up on.
|
||||
pub fn stop_p2pool(helper: &Arc<Mutex<Self>>) {
|
||||
info!("P2Pool | Attempting to stop...");
|
||||
|
@ -356,6 +367,8 @@ impl Helper {
|
|||
lock2!(helper,p2pool).state = ProcessState::Middle;
|
||||
}
|
||||
|
||||
#[cold]
|
||||
#[inline(never)]
|
||||
// The "restart frontend" to a "frontend" function.
|
||||
// Basically calls to kill the current p2pool, waits a little, then starts the below function in a a new thread, then exit.
|
||||
pub fn restart_p2pool(helper: &Arc<Mutex<Self>>, state: &crate::disk::P2pool, path: &std::path::PathBuf, backup_hosts: Option<Vec<crate::Node>>) {
|
||||
|
@ -379,6 +392,8 @@ impl Helper {
|
|||
info!("P2Pool | Restart ... OK");
|
||||
}
|
||||
|
||||
#[cold]
|
||||
#[inline(never)]
|
||||
// The "frontend" function that parses the arguments, and spawns either the [Simple] or [Advanced] P2Pool watchdog thread.
|
||||
pub fn start_p2pool(
|
||||
helper: &Arc<Mutex<Self>>,
|
||||
|
@ -419,6 +434,8 @@ impl Helper {
|
|||
head.to_owned() + "..." + tail
|
||||
}
|
||||
|
||||
#[cold]
|
||||
#[inline(never)]
|
||||
// Takes in some [State/P2pool] and parses it to build the actual command arguments.
|
||||
// Returns the [Vec] of actual arguments, and mutates the [ImgP2pool] for the main GUI thread
|
||||
// It returns a value... and mutates a deeply nested passed argument... this is some pretty bad code...
|
||||
|
@ -543,6 +560,8 @@ impl Helper {
|
|||
(args, api_path_local, api_path_network, api_path_pool)
|
||||
}
|
||||
|
||||
#[cold]
|
||||
#[inline(never)]
|
||||
// The P2Pool watchdog. Spawns 1 OS thread for reading a PTY (STDOUT+STDERR), and combines the [Child] with a PTY so STDIN actually works.
|
||||
fn spawn_p2pool_watchdog(process: Arc<Mutex<Process>>, gui_api: Arc<Mutex<PubP2poolApi>>, pub_api: Arc<Mutex<PubP2poolApi>>, args: Vec<String>, path: std::path::PathBuf, api_path_local: std::path::PathBuf, api_path_network: std::path::PathBuf, api_path_pool: std::path::PathBuf, gupax_p2pool_api: Arc<Mutex<GupaxP2poolApi>>) {
|
||||
// 1a. Create PTY
|
||||
|
@ -772,6 +791,8 @@ impl Helper {
|
|||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------- XMRig specific, most functions are very similar to P2Pool's
|
||||
#[cold]
|
||||
#[inline(never)]
|
||||
// If processes are started with [sudo] on macOS, they must also
|
||||
// be killed with [sudo] (even if I have a direct handle to it as the
|
||||
// parent process...!). This is only needed on macOS, not Linux.
|
||||
|
@ -791,6 +812,8 @@ impl Helper {
|
|||
child.wait().unwrap().success()
|
||||
}
|
||||
|
||||
#[cold]
|
||||
#[inline(never)]
|
||||
// Just sets some signals for the watchdog thread to pick up on.
|
||||
pub fn stop_xmrig(helper: &Arc<Mutex<Self>>) {
|
||||
info!("XMRig | Attempting to stop...");
|
||||
|
@ -798,6 +821,8 @@ impl Helper {
|
|||
lock2!(helper,xmrig).state = ProcessState::Middle;
|
||||
}
|
||||
|
||||
#[cold]
|
||||
#[inline(never)]
|
||||
// The "restart frontend" to a "frontend" function.
|
||||
// Basically calls to kill the current xmrig, waits a little, then starts the below function in a a new thread, then exit.
|
||||
pub fn restart_xmrig(helper: &Arc<Mutex<Self>>, state: &crate::disk::Xmrig, path: &std::path::PathBuf, sudo: Arc<Mutex<SudoState>>) {
|
||||
|
@ -821,6 +846,8 @@ impl Helper {
|
|||
info!("XMRig | Restart ... OK");
|
||||
}
|
||||
|
||||
#[cold]
|
||||
#[inline(never)]
|
||||
pub fn start_xmrig(helper: &Arc<Mutex<Self>>, state: &crate::disk::Xmrig, path: &std::path::PathBuf, sudo: Arc<Mutex<SudoState>>) {
|
||||
lock2!(helper,xmrig).state = ProcessState::Middle;
|
||||
|
||||
|
@ -840,6 +867,8 @@ impl Helper {
|
|||
});
|
||||
}
|
||||
|
||||
#[cold]
|
||||
#[inline(never)]
|
||||
// Takes in some [State/Xmrig] and parses it to build the actual command arguments.
|
||||
// Returns the [Vec] of actual arguments, and mutates the [ImgXmrig] for the main GUI thread
|
||||
// It returns a value... and mutates a deeply nested passed argument... this is some pretty bad code...
|
||||
|
@ -940,6 +969,8 @@ impl Helper {
|
|||
cmd
|
||||
}
|
||||
|
||||
#[cold]
|
||||
#[inline(never)]
|
||||
// The XMRig watchdog. Spawns 1 OS thread for reading a PTY (STDOUT+STDERR), and combines the [Child] with a PTY so STDIN actually works.
|
||||
// This isn't actually async, a tokio runtime is unfortunately needed because [Hyper] is an async library (HTTP API calls)
|
||||
#[tokio::main]
|
||||
|
@ -1151,6 +1182,7 @@ impl Helper {
|
|||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------- The "helper"
|
||||
#[inline(always)] // called once
|
||||
fn update_pub_sys_from_sysinfo(sysinfo: &sysinfo::System, pub_sys: &mut Sys, pid: &sysinfo::Pid, helper: &Helper, max_threads: usize) {
|
||||
let gupax_uptime = helper.uptime.to_string();
|
||||
let cpu = &sysinfo.cpus()[0];
|
||||
|
@ -1180,6 +1212,8 @@ impl Helper {
|
|||
};
|
||||
}
|
||||
|
||||
#[cold]
|
||||
#[inline(never)]
|
||||
// The "helper" thread. Syncs data between threads here and the GUI.
|
||||
pub fn spawn_helper(helper: &Arc<Mutex<Self>>, mut sysinfo: sysinfo::System, pid: sysinfo::Pid, max_threads: usize) {
|
||||
// The ordering of these locks is _very_ important. They MUST be in sync with how the main GUI thread locks stuff
|
||||
|
@ -1428,6 +1462,7 @@ impl PubP2poolApi {
|
|||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
// The issue with just doing [gui_api = pub_api] is that values get overwritten.
|
||||
// This doesn't matter for any of the values EXCEPT for the output, so we must
|
||||
// manually append it instead of overwriting.
|
||||
|
@ -1443,6 +1478,7 @@ impl PubP2poolApi {
|
|||
};
|
||||
}
|
||||
|
||||
#[inline]
|
||||
// Essentially greps the output for [x.xxxxxxxxxxxx XMR] where x = a number.
|
||||
// It sums each match and counts along the way, handling an error by not adding and printing to console.
|
||||
fn calc_payouts_and_xmr(output: &str) -> (u128 /* payout count */, f64 /* total xmr */) {
|
||||
|
@ -1607,6 +1643,7 @@ impl PubP2poolApi {
|
|||
};
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn calculate_share_or_block_time(hashrate: u64, difficulty: u64) -> HumanTime {
|
||||
if hashrate == 0 {
|
||||
HumanTime::new()
|
||||
|
@ -1615,6 +1652,7 @@ impl PubP2poolApi {
|
|||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn calculate_dominance(my_hashrate: u64, global_hashrate: u64) -> HumanNumber {
|
||||
if global_hashrate == 0 {
|
||||
HumanNumber::unknown()
|
||||
|
@ -1854,6 +1892,7 @@ impl PubXmrigApi {
|
|||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn combine_gui_pub_api(gui_api: &mut Self, pub_api: &mut Self) {
|
||||
let output = std::mem::take(&mut gui_api.output);
|
||||
let buf = std::mem::take(&mut pub_api.output);
|
||||
|
@ -1938,6 +1977,8 @@ impl PrivXmrigApi {
|
|||
hashrate: Hashrate::new(),
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
// Send an HTTP request to XMRig's API, serialize it into [Self] and return it
|
||||
async fn request_xmrig_api(client: hyper::Client<hyper::client::HttpConnector>, api_uri: &str) -> std::result::Result<Self, anyhow::Error> {
|
||||
let request = hyper::Request::builder()
|
||||
|
|
53
src/human.rs
53
src/human.rs
|
@ -36,22 +36,21 @@ impl Default for HumanTime {
|
|||
}
|
||||
|
||||
impl HumanTime {
|
||||
#[inline(always)]
|
||||
#[inline]
|
||||
pub const fn new() -> HumanTime {
|
||||
HumanTime(ZERO_SECONDS)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
#[inline]
|
||||
pub const fn into_human(d: Duration) -> HumanTime {
|
||||
HumanTime(d)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
#[inline]
|
||||
pub const fn from_u64(u: u64) -> HumanTime {
|
||||
HumanTime(Duration::from_secs(u))
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn plural(f: &mut std::fmt::Formatter, started: &mut bool, name: &str, value: u64) -> std::fmt::Result {
|
||||
if value > 0 {
|
||||
if *started {
|
||||
|
@ -114,19 +113,19 @@ impl std::fmt::Display for HumanNumber {
|
|||
}
|
||||
|
||||
impl HumanNumber {
|
||||
#[inline(always)]
|
||||
#[inline]
|
||||
pub fn unknown() -> Self {
|
||||
Self("???".to_string())
|
||||
}
|
||||
#[inline(always)]
|
||||
#[inline]
|
||||
pub fn from_str(s: &str) -> Self {
|
||||
Self(s.to_string())
|
||||
}
|
||||
#[inline(always)]
|
||||
#[inline]
|
||||
pub fn to_hashrate(f: f32) -> Self {
|
||||
Self(format!("{} H/s", Self::from_f32(f)))
|
||||
}
|
||||
#[inline(always)]
|
||||
#[inline]
|
||||
pub fn to_percent(f: f32) -> Self {
|
||||
if f < 0.01 {
|
||||
Self("0%".to_string())
|
||||
|
@ -134,67 +133,67 @@ impl HumanNumber {
|
|||
Self(format!("{:.2}%", f))
|
||||
}
|
||||
}
|
||||
#[inline(always)]
|
||||
#[inline]
|
||||
pub fn to_percent_3_point(f: f32) -> Self {
|
||||
Self(format!("{:.3}%", f))
|
||||
}
|
||||
#[inline(always)]
|
||||
#[inline]
|
||||
pub fn to_percent_no_fmt(f: f32) -> Self {
|
||||
Self(format!("{}%", f))
|
||||
}
|
||||
#[inline(always)]
|
||||
#[inline]
|
||||
pub fn from_f64_to_percent_3_point(f: f64) -> Self {
|
||||
Self(format!("{:.3}%", f))
|
||||
}
|
||||
#[inline(always)]
|
||||
#[inline]
|
||||
pub fn from_f64_to_percent_6_point(f: f64) -> Self {
|
||||
Self(format!("{:.6}%", f))
|
||||
}
|
||||
#[inline(always)]
|
||||
#[inline]
|
||||
pub fn from_f64_to_percent_9_point(f: f64) -> Self {
|
||||
Self(format!("{:.9}%", f))
|
||||
}
|
||||
#[inline(always)]
|
||||
#[inline]
|
||||
pub fn from_f64_to_percent_no_fmt(f: f64) -> Self {
|
||||
Self(format!("{}%", f))
|
||||
}
|
||||
#[inline(always)]
|
||||
#[inline]
|
||||
pub fn from_f32(f: f32) -> Self {
|
||||
let mut buf = num_format::Buffer::new();
|
||||
buf.write_formatted(&(f as u64), &LOCALE);
|
||||
Self(buf.as_str().to_string())
|
||||
}
|
||||
#[inline(always)]
|
||||
#[inline]
|
||||
pub fn from_f64(f: f64) -> Self {
|
||||
let mut buf = num_format::Buffer::new();
|
||||
buf.write_formatted(&(f as u128), &LOCALE);
|
||||
Self(buf.as_str().to_string())
|
||||
}
|
||||
#[inline(always)]
|
||||
#[inline]
|
||||
pub fn from_u16(u: u16) -> Self {
|
||||
let mut buf = num_format::Buffer::new();
|
||||
buf.write_formatted(&u, &LOCALE);
|
||||
Self(buf.as_str().to_string())
|
||||
}
|
||||
#[inline(always)]
|
||||
#[inline]
|
||||
pub fn from_u32(u: u32) -> Self {
|
||||
let mut buf = num_format::Buffer::new();
|
||||
buf.write_formatted(&u, &LOCALE);
|
||||
Self(buf.as_str().to_string())
|
||||
}
|
||||
#[inline(always)]
|
||||
#[inline]
|
||||
pub fn from_u64(u: u64) -> Self {
|
||||
let mut buf = num_format::Buffer::new();
|
||||
buf.write_formatted(&u, &LOCALE);
|
||||
Self(buf.as_str().to_string())
|
||||
}
|
||||
#[inline(always)]
|
||||
#[inline]
|
||||
pub fn from_u128(u: u128) -> Self {
|
||||
let mut buf = num_format::Buffer::new();
|
||||
buf.write_formatted(&u, &LOCALE);
|
||||
Self(buf.as_str().to_string())
|
||||
}
|
||||
#[inline(always)]
|
||||
#[inline]
|
||||
pub fn from_hashrate(array: [Option<f32>; 3]) -> Self {
|
||||
let mut string = "[".to_string();
|
||||
let mut buf = num_format::Buffer::new();
|
||||
|
@ -221,7 +220,7 @@ impl HumanNumber {
|
|||
|
||||
Self(string)
|
||||
}
|
||||
#[inline(always)]
|
||||
#[inline]
|
||||
pub fn from_load(array: [Option<f32>; 3]) -> Self {
|
||||
let mut string = "[".to_string();
|
||||
let mut n = 0;
|
||||
|
@ -241,30 +240,30 @@ impl HumanNumber {
|
|||
Self(string)
|
||||
}
|
||||
// [1_000_000] -> [1.000 MH/s]
|
||||
#[inline(always)]
|
||||
#[inline]
|
||||
pub fn from_u64_to_megahash_3_point(hash: u64) -> Self {
|
||||
let hash = (hash as f64)/1_000_000.0;
|
||||
let hash = format!("{:.3} MH/s", hash);
|
||||
Self(hash)
|
||||
}
|
||||
// [1_000_000_000] -> [1.000 GH/s]
|
||||
#[inline(always)]
|
||||
#[inline]
|
||||
pub fn from_u64_to_gigahash_3_point(hash: u64) -> Self {
|
||||
let hash = (hash as f64)/1_000_000_000.0;
|
||||
let hash = format!("{:.3} GH/s", hash);
|
||||
Self(hash)
|
||||
}
|
||||
#[inline(always)]
|
||||
#[inline]
|
||||
pub fn from_f64_12_point(f: f64) -> Self {
|
||||
let f = format!("{:.12}", f);
|
||||
Self(f)
|
||||
}
|
||||
#[inline(always)]
|
||||
#[inline]
|
||||
pub fn from_f64_no_fmt(f: f64) -> Self {
|
||||
let f = format!("{}", f);
|
||||
Self(f)
|
||||
}
|
||||
#[inline(always)]
|
||||
#[inline]
|
||||
pub fn as_str(&self) -> &str {
|
||||
self.0.as_str()
|
||||
}
|
||||
|
|
105
src/main.rs
105
src/main.rs
|
@ -174,6 +174,8 @@ pub struct App {
|
|||
}
|
||||
|
||||
impl App {
|
||||
#[cold]
|
||||
#[inline(never)]
|
||||
fn cc(cc: &eframe::CreationContext<'_>, app: Self) -> Self {
|
||||
let resolution = cc.integration_info.window_info.size;
|
||||
init_text_styles(&cc.egui_ctx, resolution[0], crate::free::clamp_scale(app.state.gupax.selected_scale));
|
||||
|
@ -184,12 +186,16 @@ impl App {
|
|||
}
|
||||
}
|
||||
|
||||
#[cold]
|
||||
#[inline(never)]
|
||||
fn save_before_quit(&mut self) {
|
||||
if let Err(e) = State::save(&mut self.state, &self.state_path) { error!("State file: {}", e); }
|
||||
if let Err(e) = Node::save(&self.node_vec, &self.node_path) { error!("Node list: {}", e); }
|
||||
if let Err(e) = Pool::save(&self.pool_vec, &self.pool_path) { error!("Pool list: {}", e); }
|
||||
}
|
||||
|
||||
#[cold]
|
||||
#[inline(never)]
|
||||
fn new(now: Instant) -> Self {
|
||||
info!("Initializing App Struct...");
|
||||
info!("App Init | P2Pool & XMRig processes...");
|
||||
|
@ -533,6 +539,8 @@ impl App {
|
|||
app
|
||||
}
|
||||
|
||||
#[cold]
|
||||
#[inline(never)]
|
||||
pub fn gather_backup_hosts(&self) -> Option<Vec<Node>> {
|
||||
if !self.state.p2pool.backup_host {
|
||||
return None;
|
||||
|
@ -733,6 +741,8 @@ struct Images {
|
|||
}
|
||||
|
||||
impl Images {
|
||||
#[cold]
|
||||
#[inline(never)]
|
||||
fn new() -> Self {
|
||||
Self {
|
||||
banner: RetainedImage::from_image_bytes("banner.png", BYTES_BANNER).unwrap(),
|
||||
|
@ -771,46 +781,23 @@ enum KeyPressed {
|
|||
}
|
||||
|
||||
impl KeyPressed {
|
||||
fn is_f11(&self) -> bool {
|
||||
*self == Self::F11
|
||||
}
|
||||
fn is_z(&self) -> bool {
|
||||
*self == Self::Z
|
||||
}
|
||||
fn is_x(&self) -> bool {
|
||||
*self == Self::X
|
||||
}
|
||||
fn is_up(&self) -> bool {
|
||||
*self == Self::Up
|
||||
}
|
||||
fn is_down(&self) -> bool {
|
||||
*self == Self::Down
|
||||
}
|
||||
fn is_esc(&self) -> bool {
|
||||
*self == Self::Esc
|
||||
}
|
||||
fn is_s(&self) -> bool {
|
||||
*self == Self::S
|
||||
}
|
||||
fn is_r(&self) -> bool {
|
||||
*self == Self::R
|
||||
}
|
||||
fn is_d(&self) -> bool {
|
||||
*self == Self::D
|
||||
}
|
||||
fn is_c(&self) -> bool {
|
||||
*self == Self::C
|
||||
}
|
||||
fn is_v(&self) -> bool {
|
||||
*self == Self::V
|
||||
}
|
||||
fn is_none(&self) -> bool {
|
||||
*self == Self::None
|
||||
}
|
||||
#[inline] fn is_f11(&self) -> bool { *self == Self::F11 }
|
||||
#[inline] fn is_z(&self) -> bool { *self == Self::Z }
|
||||
#[inline] fn is_x(&self) -> bool { *self == Self::X }
|
||||
#[inline] fn is_up(&self) -> bool { *self == Self::Up }
|
||||
#[inline] fn is_down(&self) -> bool { *self == Self::Down }
|
||||
#[inline] fn is_esc(&self) -> bool { *self == Self::Esc }
|
||||
#[inline] fn is_s(&self) -> bool { *self == Self::S }
|
||||
#[inline] fn is_r(&self) -> bool { *self == Self::R }
|
||||
#[inline] fn is_d(&self) -> bool { *self == Self::D }
|
||||
#[inline] fn is_c(&self) -> bool { *self == Self::C }
|
||||
#[inline] fn is_v(&self) -> bool { *self == Self::V }
|
||||
#[inline] fn is_none(&self) -> bool { *self == Self::None }
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------- Init functions
|
||||
#[inline(always)]
|
||||
#[cold]
|
||||
#[inline(never)]
|
||||
fn init_text_styles(ctx: &egui::Context, width: f32, pixels_per_point: f32) {
|
||||
let scale = width / 30.0;
|
||||
let mut style = (*ctx.style()).clone();
|
||||
|
@ -836,7 +823,8 @@ fn init_text_styles(ctx: &egui::Context, width: f32, pixels_per_point: f32) {
|
|||
ctx.request_repaint();
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
#[cold]
|
||||
#[inline(never)]
|
||||
fn init_logger(now: Instant) {
|
||||
use env_logger::fmt::Color;
|
||||
let filter_env = std::env::var("RUST_LOG").unwrap_or_else(|_| "INFO".to_string());
|
||||
|
@ -872,7 +860,8 @@ fn init_logger(now: Instant) {
|
|||
info!("Log level ... {}", filter);
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
#[cold]
|
||||
#[inline(never)]
|
||||
fn init_options(initial_window_size: Option<Vec2>) -> NativeOptions {
|
||||
let mut options = eframe::NativeOptions::default();
|
||||
options.min_window_size = Some(Vec2::new(APP_MIN_WIDTH, APP_MIN_HEIGHT));
|
||||
|
@ -891,7 +880,8 @@ fn init_options(initial_window_size: Option<Vec2>) -> NativeOptions {
|
|||
options
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
#[cold]
|
||||
#[inline(never)]
|
||||
fn init_auto(app: &mut App) {
|
||||
// Return early if [--no-startup] was not passed
|
||||
if app.no_startup {
|
||||
|
@ -953,6 +943,8 @@ fn init_auto(app: &mut App) {
|
|||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------- Reset functions
|
||||
#[cold]
|
||||
#[inline(never)]
|
||||
fn reset_state(path: &PathBuf) -> Result<(), TomlError> {
|
||||
match State::create_new(path) {
|
||||
Ok(_) => { info!("Resetting [state.toml] ... OK"); Ok(()) },
|
||||
|
@ -960,7 +952,8 @@ fn reset_state(path: &PathBuf) -> Result<(), TomlError> {
|
|||
}
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
#[cold]
|
||||
#[inline(never)]
|
||||
fn reset_nodes(path: &PathBuf) -> Result<(), TomlError> {
|
||||
match Node::create_new(path) {
|
||||
Ok(_) => { info!("Resetting [node.toml] ... OK"); Ok(()) },
|
||||
|
@ -968,7 +961,8 @@ fn reset_nodes(path: &PathBuf) -> Result<(), TomlError> {
|
|||
}
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
#[cold]
|
||||
#[inline(never)]
|
||||
fn reset_pools(path: &PathBuf) -> Result<(), TomlError> {
|
||||
match Pool::create_new(path) {
|
||||
Ok(_) => { info!("Resetting [pool.toml] ... OK"); Ok(()) },
|
||||
|
@ -976,7 +970,8 @@ fn reset_pools(path: &PathBuf) -> Result<(), TomlError> {
|
|||
}
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
#[cold]
|
||||
#[inline(never)]
|
||||
fn reset_gupax_p2pool_api(path: &PathBuf) -> Result<(), TomlError> {
|
||||
match GupaxP2poolApi::create_new(path) {
|
||||
Ok(_) => { info!("Resetting GupaxP2poolApi ... OK"); Ok(()) },
|
||||
|
@ -984,7 +979,8 @@ fn reset_gupax_p2pool_api(path: &PathBuf) -> Result<(), TomlError> {
|
|||
}
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
#[cold]
|
||||
#[inline(never)]
|
||||
fn reset(path: &PathBuf, state: &PathBuf, node: &PathBuf, pool: &PathBuf, gupax_p2pool_api: &PathBuf) {
|
||||
let mut code = 0;
|
||||
// Attempt to remove directory first
|
||||
|
@ -1021,7 +1017,8 @@ fn reset(path: &PathBuf, state: &PathBuf, node: &PathBuf, pool: &PathBuf, gupax_
|
|||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------- Misc functions
|
||||
#[inline(always)]
|
||||
#[cold]
|
||||
#[inline(never)]
|
||||
fn parse_args<S: Into<String>>(mut app: App, panic: S) -> App {
|
||||
info!("Parsing CLI arguments...");
|
||||
let mut args: Vec<String> = env::args().collect();
|
||||
|
@ -1064,7 +1061,8 @@ fn parse_args<S: Into<String>>(mut app: App, panic: S) -> App {
|
|||
}
|
||||
|
||||
// Get absolute [Gupax] binary path
|
||||
#[inline(always)]
|
||||
#[cold]
|
||||
#[inline(never)]
|
||||
pub fn get_exe() -> Result<String, std::io::Error> {
|
||||
match std::env::current_exe() {
|
||||
Ok(path) => { Ok(path.display().to_string()) },
|
||||
|
@ -1073,7 +1071,8 @@ pub fn get_exe() -> Result<String, std::io::Error> {
|
|||
}
|
||||
|
||||
// Get absolute [Gupax] directory path
|
||||
#[inline(always)]
|
||||
#[cold]
|
||||
#[inline(never)]
|
||||
pub fn get_exe_dir() -> Result<String, std::io::Error> {
|
||||
match std::env::current_exe() {
|
||||
Ok(mut path) => { path.pop(); Ok(path.display().to_string()) },
|
||||
|
@ -1083,7 +1082,8 @@ pub fn get_exe_dir() -> Result<String, std::io::Error> {
|
|||
|
||||
// Clean any [gupax_update_.*] directories
|
||||
// The trailing random bits must be exactly 10 alphanumeric characters
|
||||
#[inline(always)]
|
||||
#[cold]
|
||||
#[inline(never)]
|
||||
pub fn clean_dir() -> Result<(), anyhow::Error> {
|
||||
let regex = Regex::new("^gupax_update_[A-Za-z0-9]{10}$").unwrap();
|
||||
for entry in std::fs::read_dir(get_exe_dir()?)? {
|
||||
|
@ -1101,7 +1101,8 @@ pub fn clean_dir() -> Result<(), anyhow::Error> {
|
|||
}
|
||||
|
||||
// Print disk files to console
|
||||
#[inline(always)]
|
||||
#[cold]
|
||||
#[inline(never)]
|
||||
fn print_disk_file(path: &PathBuf) {
|
||||
match std::fs::read_to_string(path) {
|
||||
Ok(string) => { print!("{}", string); exit(0); },
|
||||
|
@ -1110,7 +1111,8 @@ fn print_disk_file(path: &PathBuf) {
|
|||
}
|
||||
|
||||
// Prints the GupaxP2PoolApi files.
|
||||
#[inline(always)]
|
||||
#[cold]
|
||||
#[inline(never)]
|
||||
fn print_gupax_p2pool_api(gupax_p2pool_api: &Arc<Mutex<GupaxP2poolApi>>) {
|
||||
let api = lock!(gupax_p2pool_api);
|
||||
let log = match std::fs::read_to_string(&api.path_log) {
|
||||
|
@ -1133,7 +1135,7 @@ fn print_gupax_p2pool_api(gupax_p2pool_api: &Arc<Mutex<GupaxP2poolApi>>) {
|
|||
exit(0);
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
#[inline]
|
||||
fn cmp_f64(a: f64, b: f64) -> std::cmp::Ordering {
|
||||
match (a <= b, a >= b) {
|
||||
(false, true) => std::cmp::Ordering::Greater,
|
||||
|
@ -1198,7 +1200,6 @@ impl eframe::App for App {
|
|||
}
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn update(&mut self, ctx: &egui::Context, frame: &mut eframe::Frame) {
|
||||
// *-------*
|
||||
// | DEBUG |
|
||||
|
|
|
@ -291,6 +291,8 @@ impl Ping {
|
|||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------- Main Ping function
|
||||
#[cold]
|
||||
#[inline(never)]
|
||||
// Intermediate function for spawning thread
|
||||
pub fn spawn_thread(ping: &Arc<Mutex<Self>>) {
|
||||
info!("Spawning ping thread...");
|
||||
|
@ -333,6 +335,8 @@ impl Ping {
|
|||
// >500ms = RED
|
||||
// timeout = BLACK
|
||||
// default = GRAY
|
||||
#[cold]
|
||||
#[inline(never)]
|
||||
#[tokio::main]
|
||||
pub async fn ping(ping: &Arc<Mutex<Self>>) -> Result<String, anyhow::Error> {
|
||||
// Start ping
|
||||
|
@ -384,6 +388,8 @@ impl Ping {
|
|||
Ok(fastest_info)
|
||||
}
|
||||
|
||||
#[cold]
|
||||
#[inline(never)]
|
||||
async fn response(
|
||||
client: Client<HttpConnector>,
|
||||
request: Request<Body>,
|
||||
|
|
|
@ -36,8 +36,21 @@ use crate::regex::{
|
|||
};
|
||||
|
||||
impl crate::disk::P2pool {
|
||||
#[inline(always)]
|
||||
pub fn show(&mut self, node_vec: &mut Vec<(String, Node)>, _og: &Arc<Mutex<State>>, ping: &Arc<Mutex<Ping>>, process: &Arc<Mutex<Process>>, api: &Arc<Mutex<PubP2poolApi>>, buffer: &mut String, width: f32, height: f32, _ctx: &egui::Context, ui: &mut egui::Ui) {
|
||||
#[inline(always)] // called once
|
||||
pub fn show(
|
||||
&mut self,
|
||||
node_vec: &mut Vec<(String,
|
||||
Node)>,
|
||||
_og: &Arc<Mutex<State>>,
|
||||
ping: &Arc<Mutex<Ping>>,
|
||||
process: &Arc<Mutex<Process>>,
|
||||
api: &Arc<Mutex<PubP2poolApi>>,
|
||||
buffer: &mut String,
|
||||
width: f32,
|
||||
height: f32,
|
||||
_ctx: &egui::Context,
|
||||
ui: &mut egui::Ui
|
||||
) {
|
||||
let text_edit = height / 25.0;
|
||||
//---------------------------------------------------------------------------------------------------- [Simple] Console
|
||||
debug!("P2Pool Tab | Rendering [Console]");
|
||||
|
|
|
@ -8,6 +8,8 @@ use crate::constants::{
|
|||
};
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
#[cold]
|
||||
#[inline(never)]
|
||||
/// Set custom panic hook.
|
||||
pub(crate) fn set_panic_hook(now: std::time::Instant) {
|
||||
std::panic::set_hook(Box::new(move |panic_info| {
|
||||
|
|
|
@ -37,6 +37,8 @@ pub struct Regexes {
|
|||
}
|
||||
|
||||
impl Regexes {
|
||||
#[cold]
|
||||
#[inline(never)]
|
||||
fn new() -> Self {
|
||||
Self {
|
||||
name: Regex::new("^[A-Za-z0-9-_.]+( [A-Za-z0-9-_.]+)*$").unwrap(),
|
||||
|
@ -47,6 +49,7 @@ impl Regexes {
|
|||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
// Check if a Monero address is correct.
|
||||
// This actually only checks for length & Base58, and doesn't do any checksum validation
|
||||
// (the last few bytes of a Monero address are a Keccak hash checksum) so some invalid addresses can trick this function.
|
||||
|
@ -85,6 +88,8 @@ pub struct P2poolRegex {
|
|||
}
|
||||
|
||||
impl P2poolRegex {
|
||||
#[cold]
|
||||
#[inline(never)]
|
||||
fn new() -> Self {
|
||||
Self {
|
||||
date: Regex::new("[0-9]+-[0-9]+-[0-9]+ [0-9]+:[0-9]+:[0-9]+.[0-9]+").unwrap(),
|
||||
|
|
|
@ -42,8 +42,23 @@ use egui::{
|
|||
};
|
||||
|
||||
impl crate::disk::Status {
|
||||
#[inline(always)]
|
||||
pub fn show(&mut self, sys: &Arc<Mutex<Sys>>, p2pool_api: &Arc<Mutex<PubP2poolApi>>, xmrig_api: &Arc<Mutex<PubXmrigApi>>, p2pool_img: &Arc<Mutex<ImgP2pool>>, xmrig_img: &Arc<Mutex<ImgXmrig>>, p2pool_alive: bool, xmrig_alive: bool, max_threads: usize, gupax_p2pool_api: &Arc<Mutex<GupaxP2poolApi>>, benchmarks: &[Benchmark], width: f32, height: f32, _ctx: &egui::Context, ui: &mut egui::Ui) {
|
||||
#[inline(always)] // called once
|
||||
pub fn show(&mut self,
|
||||
sys: &Arc<Mutex<Sys>>,
|
||||
p2pool_api: &Arc<Mutex<PubP2poolApi>>,
|
||||
xmrig_api: &Arc<Mutex<PubXmrigApi>>,
|
||||
p2pool_img: &Arc<Mutex<ImgP2pool>>,
|
||||
xmrig_img: &Arc<Mutex<ImgXmrig>>,
|
||||
p2pool_alive: bool,
|
||||
xmrig_alive: bool,
|
||||
max_threads: usize,
|
||||
gupax_p2pool_api: &Arc<Mutex<GupaxP2poolApi>>,
|
||||
benchmarks: &[Benchmark],
|
||||
width: f32,
|
||||
height: f32,
|
||||
_ctx: &egui::Context,
|
||||
ui: &mut egui::Ui
|
||||
) {
|
||||
//---------------------------------------------------------------------------------------------------- [Processes]
|
||||
if self.submenu == Submenu::Processes {
|
||||
let width = (width/3.0)-(SPACE*1.666);
|
||||
|
|
10
src/sudo.rs
10
src/sudo.rs
|
@ -54,6 +54,8 @@ impl Default for SudoState {
|
|||
}
|
||||
|
||||
impl SudoState {
|
||||
#[cold]
|
||||
#[inline(never)]
|
||||
#[cfg(target_os = "windows")]
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
|
@ -66,6 +68,8 @@ impl SudoState {
|
|||
signal: ProcessSignal::None,
|
||||
}
|
||||
}
|
||||
#[cold]
|
||||
#[inline(never)]
|
||||
#[cfg(target_family = "unix")]
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
|
@ -79,6 +83,8 @@ impl SudoState {
|
|||
}
|
||||
}
|
||||
|
||||
#[cold]
|
||||
#[inline(never)]
|
||||
// Resets the state.
|
||||
pub fn reset(state: &Arc<Mutex<Self>>) {
|
||||
Self::wipe(state);
|
||||
|
@ -88,6 +94,8 @@ impl SudoState {
|
|||
// state.signal = ProcessSignal::None;
|
||||
}
|
||||
|
||||
#[cold]
|
||||
#[inline(never)]
|
||||
// Swaps the pass with another 256-capacity String,
|
||||
// zeroizes the old and drops it.
|
||||
pub fn wipe(state: &Arc<Mutex<Self>>) {
|
||||
|
@ -100,6 +108,8 @@ impl SudoState {
|
|||
info!("Sudo | Password wipe with 0's ... OK");
|
||||
}
|
||||
|
||||
#[cold]
|
||||
#[inline(never)]
|
||||
// Spawns a thread and tests sudo with the provided password.
|
||||
// Sudo takes the password through STDIN via [--stdin].
|
||||
// Sets the appropriate state fields on success/failure.
|
||||
|
|
|
@ -286,6 +286,8 @@ impl Update {
|
|||
Ok(tmp_dir)
|
||||
}
|
||||
|
||||
#[cold]
|
||||
#[inline(never)]
|
||||
// Get an HTTPS client. Uses [Arti] if Tor is enabled.
|
||||
// The base type looks something like [hyper::Client<...>].
|
||||
// This is then wrapped with the custom [ClientEnum] type to implement
|
||||
|
@ -319,6 +321,8 @@ impl Update {
|
|||
}
|
||||
}
|
||||
|
||||
#[cold]
|
||||
#[inline(never)]
|
||||
// Intermediate function that spawns a new thread
|
||||
// which starts the async [start()] function that
|
||||
// actually contains the code. This is so that everytime
|
||||
|
@ -422,6 +426,8 @@ impl Update {
|
|||
});
|
||||
}
|
||||
|
||||
#[cold]
|
||||
#[inline(never)]
|
||||
// Download process:
|
||||
// 0. setup tor, client, http, etc
|
||||
// 1. fill vector with all enums
|
||||
|
@ -791,6 +797,8 @@ pub struct Pkg {
|
|||
}
|
||||
|
||||
impl Pkg {
|
||||
#[cold]
|
||||
#[inline(never)]
|
||||
pub fn new(name: Name) -> Self {
|
||||
let link_metadata = match name {
|
||||
Gupax => GUPAX_METADATA,
|
||||
|
@ -824,6 +832,8 @@ impl Pkg {
|
|||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------- Pkg functions
|
||||
#[cold]
|
||||
#[inline(never)]
|
||||
// Generate fake [User-Agent] HTTP header
|
||||
pub fn get_user_agent() -> &'static str {
|
||||
let index = FAKE_USER_AGENT.len() - 1;
|
||||
|
@ -834,6 +844,8 @@ impl Pkg {
|
|||
user_agent
|
||||
}
|
||||
|
||||
#[cold]
|
||||
#[inline(never)]
|
||||
// Generate GET request based off input URI + fake user agent
|
||||
fn get_request(link: String, user_agent: &'static str) -> Result<Request<Body>, anyhow::Error> {
|
||||
let request = Request::builder()
|
||||
|
@ -844,6 +856,8 @@ impl Pkg {
|
|||
Ok(request)
|
||||
}
|
||||
|
||||
#[cold]
|
||||
#[inline(never)]
|
||||
// Get metadata using [Generic hyper::client<C>] & [Request]
|
||||
// and change [version, prog] under an Arc<Mutex>
|
||||
async fn get_metadata<C>(new_ver: Arc<Mutex<String>>, client: Client<C>, link: String, user_agent: &'static str) -> Result<(), Error>
|
||||
|
@ -856,6 +870,8 @@ impl Pkg {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[cold]
|
||||
#[inline(never)]
|
||||
// Takes a [Request], fills the appropriate [Pkg]
|
||||
// [bytes] field with the [Archive/Standalone]
|
||||
async fn get_bytes<C>(bytes: Arc<Mutex<bytes::Bytes>>, client: Client<C>, link: String, user_agent: &'static str) -> Result<(), anyhow::Error>
|
||||
|
@ -874,6 +890,8 @@ impl Pkg {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[cold]
|
||||
#[inline(never)]
|
||||
// Take in a [Name] and [Vec] of [Pkg]s, find
|
||||
// that [Name]'s corresponding new version.
|
||||
fn get_new_pkg_version(name: Name, vec: &[&Pkg]) -> Result<String, Error> {
|
||||
|
|
14
src/xmrig.rs
14
src/xmrig.rs
|
@ -37,8 +37,18 @@ use crate::regex::{
|
|||
};
|
||||
|
||||
impl crate::disk::Xmrig {
|
||||
#[inline(always)]
|
||||
pub fn show(&mut self, pool_vec: &mut Vec<(String, Pool)>, process: &Arc<Mutex<Process>>, api: &Arc<Mutex<PubXmrigApi>>, buffer: &mut String, width: f32, height: f32, _ctx: &egui::Context, ui: &mut egui::Ui) {
|
||||
#[inline(always)] // called once
|
||||
pub fn show(
|
||||
&mut self,
|
||||
pool_vec: &mut Vec<(String, Pool)>,
|
||||
process: &Arc<Mutex<Process>>,
|
||||
api: &Arc<Mutex<PubXmrigApi>>,
|
||||
buffer: &mut String,
|
||||
width: f32,
|
||||
height: f32,
|
||||
_ctx: &egui::Context,
|
||||
ui: &mut egui::Ui
|
||||
) {
|
||||
let text_edit = height / 25.0;
|
||||
//---------------------------------------------------------------------------------------------------- [Simple] Console
|
||||
debug!("XMRig Tab | Rendering [Console]");
|
||||
|
|
Loading…
Reference in a new issue