Make default number of threads same as CPU cores

This commit is contained in:
timvisee
2018-01-11 20:14:55 +01:00
parent d1e6d0638c
commit 7a3ae058e8
5 changed files with 6 additions and 8 deletions

1
Cargo.lock generated
View File

@@ -221,6 +221,7 @@ dependencies = [
"bufstream 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "bufstream 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
"clap 2.29.0 (registry+https://github.com/rust-lang/crates.io-index)", "clap 2.29.0 (registry+https://github.com/rust-lang/crates.io-index)",
"image 0.18.0 (registry+https://github.com/rust-lang/crates.io-index)", "image 0.18.0 (registry+https://github.com/rust-lang/crates.io-index)",
"num_cpus 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"regex 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", "regex 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)",
] ]

View File

@@ -7,4 +7,5 @@ authors = ["Tim Visée <timvisee@gmail.com>"]
bufstream = "0.1" bufstream = "0.1"
clap = "2.29" clap = "2.29"
image = "0.18" image = "0.18"
num_cpus = "1.8"
regex = "0.2" regex = "0.2"

View File

@@ -120,7 +120,7 @@ OPTIONS:
-h, --height <PIXELS> Draw height (def: screen height) -h, --height <PIXELS> Draw height (def: screen height)
-x <PIXELS> Draw X offset (def: 0) -x <PIXELS> Draw X offset (def: 0)
-y <PIXELS> Draw Y offset (def: 0) -y <PIXELS> Draw Y offset (def: 0)
-c, --count <COUNT> Number of concurrent threads (def: 4) -c, --count <COUNT> Number of concurrent threads (def: CPUs)
-r, --fps <RATE> Frames per second with multiple images (def: 1) -r, --fps <RATE> Frames per second with multiple images (def: 1)
ARGS: ARGS:

View File

@@ -4,9 +4,6 @@ pub const APP_VERSION: &'static str = "0.1";
pub const APP_AUTHOR: &'static str = "Tim Visee <timvisee@gmail.com>"; pub const APP_AUTHOR: &'static str = "Tim Visee <timvisee@gmail.com>";
pub const APP_ABOUT: &'static str = "A quick pixelflut client, that pwns pixelflut panels."; pub const APP_ABOUT: &'static str = "A quick pixelflut client, that pwns pixelflut panels.";
// The default thread count
pub const DEFAULT_THREAD_COUNT: usize = 4;
// The default frames per second rate // The default frames per second rate
pub const DEFAULT_IMAGE_FPS: u32 = 1; pub const DEFAULT_IMAGE_FPS: u32 = 1;

View File

@@ -1,4 +1,5 @@
extern crate clap; extern crate clap;
extern crate num_cpus;
use clap::{Arg, ArgMatches, App}; use clap::{Arg, ArgMatches, App};
@@ -50,14 +51,12 @@ impl<'a: 'b, 'b> ArgHandler<'a> {
.takes_value(true)) .takes_value(true))
.arg(Arg::with_name("x") .arg(Arg::with_name("x")
.short("x") .short("x")
.long("x")
.value_name("PIXELS") .value_name("PIXELS")
.help("Draw X offset (def: 0)") .help("Draw X offset (def: 0)")
.display_order(4) .display_order(4)
.takes_value(true)) .takes_value(true))
.arg(Arg::with_name("y") .arg(Arg::with_name("y")
.short("y") .short("y")
.long("y")
.value_name("PIXELS") .value_name("PIXELS")
.help("Draw Y offset (def: 0)") .help("Draw Y offset (def: 0)")
.display_order(5) .display_order(5)
@@ -68,7 +67,7 @@ impl<'a: 'b, 'b> ArgHandler<'a> {
.alias("thread") .alias("thread")
.alias("threads") .alias("threads")
.value_name("COUNT") .value_name("COUNT")
.help("Number of concurrent threads (def: 4)") .help("Number of concurrent threads (def: CPUs)")
.display_order(6) .display_order(6)
.takes_value(true)) .takes_value(true))
.arg(Arg::with_name("fps") .arg(Arg::with_name("fps")
@@ -95,7 +94,7 @@ impl<'a: 'b, 'b> ArgHandler<'a> {
/// Get the thread count. /// Get the thread count.
pub fn count(&self) -> usize { pub fn count(&self) -> usize {
self.matches.value_of("count") self.matches.value_of("count")
.unwrap_or(&format!("{}", DEFAULT_THREAD_COUNT)) .unwrap_or(&format!("{}", num_cpus::get()))
.parse::<usize>() .parse::<usize>()
.expect("Invalid count specified") .expect("Invalid count specified")
} }