-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
7 changed files
with
118 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,3 +18,5 @@ clap = "~2.26" | |
digits = "~1.1.0" | ||
rayon = "~0.8.2" | ||
num_cpus = "~1.7" | ||
serde = "1.0.24" | ||
serde_json = "1.0.8" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
extern crate serde; | ||
extern crate serde_json; | ||
|
||
#[macro_use] | ||
extern crate serde_derive; | ||
|
||
use serde_json::Error; | ||
use ::reporter::{Reporter,ReportData}; | ||
use std::io::{self, Write}; | ||
pub struct JSON; | ||
|
||
impl Reporter for JSON { | ||
fn report(data: ReportData) { | ||
let _a = serde_json::to_string(&ReportData)?; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
extern crate serde; | ||
use serde::ser::{Serialize, Serializer, SerializeStruct}; | ||
extern crate serde_json; | ||
use serde_json::Error; | ||
use std::sync::{Arc, Mutex}; | ||
use ::Digits; | ||
mod ticker_tape; | ||
mod spinner; | ||
mod json; | ||
|
||
mod prelude { | ||
pub use ticker_tape::*; | ||
pub use spinner::*; | ||
pub use json::*; | ||
} | ||
|
||
pub struct ReportData { | ||
pub cores: u8, | ||
pub chunk: usize, | ||
pub cluster: Option<(usize,usize)>, | ||
pub character_set: String, | ||
pub start_time: SystemTime, | ||
pub start_at: String, | ||
pub adjacent_limit: Option<u8>, | ||
pub iterations: &usize, // Atomic global | ||
pub five_min_progress: Arc<Mutex<(usize, String)>>, // Mutex try_lock | ||
} | ||
|
||
impl Serialize for ReportData { | ||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> | ||
where S: Serializer { | ||
|
||
let mut struct_fields = 8; | ||
if self.cluster.is_some() { struct_fields += 2; } | ||
if self.adjacent_limit.is_some() { struct_fields += 1; } | ||
|
||
let mut state = serializer.serialize_struct("ReportData", struct_fields)?; | ||
state.serialize_field("cores", &self.cores)?; | ||
state.serialize_field("chunk", &self.chunk)?; | ||
if let Some(node, cluster_size) = self.cluster { | ||
state.serialize_field("cluster_node", &node)?; | ||
state.serialize_field("cluster_size", &cluster_size)?; | ||
} | ||
state.serialize_field("character_set", &self.character_set)?; | ||
state.serialize_field("start_time", &self.start_time)?; | ||
state.serialize_field("start_at", &self.start_at)?; | ||
if let Some(adj) = self.adjacent_limit { | ||
state.serialize_field("adjacent_limit", &self.adjacent_limit)?; | ||
} | ||
state.serialize_field("iterations", &self.iterations.load(Ordering::SeqCst))?; | ||
let (five_min_iters, last_string) = self.five_min_progress.lock().unwrap(); | ||
state.serialize_field("last_five_minute_iterations", &five_min_iters)?; | ||
state.serialize_field("last_attempt", &last_string)?; | ||
state.end() | ||
} | ||
} | ||
|
||
pub trait Reporter { | ||
fn report(data: ReportData); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
use ::reporter::{Reporter,ReportData}; | ||
use std::io::{self, Write}; | ||
|
||
const SPINNER: &[char] = &['⠋','⠙','⠹','⠸','⠼','⠴','⠦','⠧','⠇','⠏']; | ||
|
||
struct Spinner; | ||
|
||
impl Reporter for Spinner { | ||
fn report(data: ReportData) { | ||
print!(":"); | ||
io::stdout().flush().unwrap(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
use std::io::{self, Write}; | ||
pub struct TickerTape; | ||
|
||
impl Reporter for TickerTape { | ||
fn report(data: ReportData) { | ||
print!("{}..", ReportData.last.to_s()); | ||
io::stdout().flush().unwrap(); | ||
} | ||
} |