GitLab will be upgraded to the 12.10.14-ce.0 on 28 Sept 2020 at 2.00pm (AEDT) to 2.30pm (AEDT). During the update, GitLab and Mattermost services will not be available. If you have any concerns with this, please talk to us at N110 (b) CSIT building.

Commit f5b1e9d9 authored by qinsoon's avatar qinsoon

put all logging information to stderr (use stderrlog instead of

simple_logger)
parent 485c6b38
......@@ -24,7 +24,7 @@ gc = {path = "src/gc"}
libloading = "0.3"
lazy_static = "0.1.15"
log = "0.3.5"
simple_logger = "0.4.0"
stderrlog = "0.2.2"
hprof = "0.1.3"
memmap = "0.4.0"
memsec = "0.1.9"
......
......@@ -41,7 +41,8 @@ impl <'vm> Compiler<'vm> {
}
drop(_p);
hprof::profiler().print_timing();
hprof_print_timing(hprof::profiler().root());
func.set_compiled();
}
......@@ -83,3 +84,66 @@ impl Default for CompilerPolicy {
CompilerPolicy{passes: passes}
}
}
use self::hprof::ProfileNode;
use std::rc::Rc;
fn hprof_print_timing(root: Rc<ProfileNode>) {
info!("Timing information for {}:", root.name);
for child in &*root.children.borrow() {
hprof_print_child(child, 2);
}
}
fn hprof_print_child(this: &ProfileNode, indent: usize) {
let mut indent_str = "".to_string();
for _ in 0..indent {
indent_str += " ";
}
let parent_time = this.parent
.as_ref()
.map(|p| p.total_time.get())
.unwrap_or(this.total_time.get()) as f64;
let percent = 100.0 * (this.total_time.get() as f64 / parent_time);
if percent.is_infinite() {
info!("{}{name} - {calls} * {each} = {total} @ {hz:.1}hz",
indent_str,
name = this.name,
calls = this.calls.get(),
each = Nanoseconds((this.total_time.get() as f64 / this.calls.get() as f64) as u64),
total = Nanoseconds(this.total_time.get()),
hz = this.calls.get() as f64 / this.total_time.get() as f64 * 1e9f64
);
} else {
info!("{}{name} - {calls} * {each} = {total} ({percent:.1}%)",
indent_str,
name = this.name,
calls = this.calls.get(),
each = Nanoseconds((this.total_time.get() as f64 / this.calls.get() as f64) as u64),
total = Nanoseconds(this.total_time.get()),
percent = percent
);
}
for c in &*this.children.borrow() {
hprof_print_child(c, indent+2);
}
}
// used to do a pretty printing of time
struct Nanoseconds(u64);
use std::fmt;
impl fmt::Display for Nanoseconds {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
if self.0 < 1_000 {
write!(f, "{}ns", self.0)
} else if self.0 < 1_000_000 {
write!(f, "{:.1}us", self.0 as f64 / 1_000.)
} else if self.0 < 1_000_000_000 {
write!(f, "{:.1}ms", self.0 as f64 / 1_000_000.)
} else {
write!(f, "{:.1}s", self.0 as f64 / 1_000_000_000.)
}
}
}
......@@ -3,7 +3,7 @@ extern crate lazy_static;
#[macro_use]
extern crate log;
extern crate rustc_serialize;
extern crate simple_logger;
extern crate stderrlog;
#[macro_use]
extern crate maplit;
......
......@@ -31,19 +31,19 @@ pub fn exec (cmd: Command) -> Output {
}
pub fn exec_nocheck (mut cmd: Command) -> Output {
println!("executing: {:?}", cmd);
trace!("executing: {:?}", cmd);
let output = match cmd.output() {
Ok(res) => res,
Err(e) => panic!("failed to execute: {}", e)
};
println!("---out---");
println!("{}", String::from_utf8_lossy(&output.stdout));
println!("---err---");
println!("{}", String::from_utf8_lossy(&output.stderr));
trace!("---out---");
trace!("{}", String::from_utf8_lossy(&output.stdout));
trace!("---err---");
trace!("{}", String::from_utf8_lossy(&output.stderr));
if output.status.signal().is_some() {
println!("terminated by a signal: {}", output.status.signal().unwrap());
trace!("terminated by a signal: {}", output.status.signal().unwrap());
}
output
......
......@@ -489,11 +489,19 @@ impl <'a> VM {
}
fn start_logging_internal(level: LogLevel) {
use simple_logger;
use stderrlog;
let verbose = match level {
LogLevel::Error => 0,
LogLevel::Warn => 1,
LogLevel::Info => 2,
LogLevel::Debug => 3,
LogLevel::Trace => 4,
};
match simple_logger::init_with_level(level) {
Ok(_) => {},
Err(_) => {}
match stderrlog::new().verbosity(verbose).init() {
Ok(()) => info!("logger initialized"),
Err(e) => error!("failed to init logger, probably already initialized: {:?}", e)
}
}
......
......@@ -43,13 +43,13 @@ pub enum MuLogLevel {
impl VMOptions {
pub fn init(str: &str) -> VMOptions {
println!("init vm options with: {:?}", str);
info!("init vm options with: {:?}", str);
let ret : VMOptions = Docopt::new(USAGE)
.and_then(|d| d.argv(str.split_whitespace().into_iter()).parse())
.unwrap_or_else(|e| e.exit()).decode().unwrap();
println!("parsed as {:?}", ret);
info!("parsed as {:?}", ret);
ret
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment