-
-
Notifications
You must be signed in to change notification settings - Fork 636
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[engine] rm python graphmaker; create dot formatted display #4295
Changes from 1 commit
d51e93a
8859afd
f103b04
df5f362
8eaec05
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
f3ae10a39f2b893026b4ebfa20c2e45dc8b293ee | ||
33d19203e5948e2c510aa872df99e2053ad44976 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,10 @@ use std::os::raw; | |
use std::path::Path; | ||
use std::sync::Arc; | ||
|
||
use std::fs::OpenOptions; | ||
use std::io::{BufWriter, Write}; | ||
use std::io; | ||
|
||
use core::{Function, Key, TypeConstraint, TypeId, Value}; | ||
use externs::{ | ||
Buffer, | ||
|
@@ -51,7 +55,7 @@ use graph::Graph; | |
use nodes::Failure; | ||
use scheduler::{RootResult, Scheduler, ExecutionStat}; | ||
use tasks::Tasks; | ||
use rule_graph::{GraphMaker, RootSubjectTypes}; | ||
use rule_graph::{GraphMaker, RootSubjectTypes, RuleGraph}; | ||
|
||
pub struct RawScheduler { | ||
scheduler: Scheduler, | ||
|
@@ -449,6 +453,69 @@ pub extern fn validator_run( | |
}) | ||
} | ||
|
||
#[no_mangle] | ||
pub extern fn rule_graph_visualize( | ||
scheduler_ptr: *mut RawScheduler, | ||
subject_types_ptr: *mut TypeId, | ||
subject_types_len: u64, | ||
path_ptr: *const raw::c_char | ||
) { | ||
with_scheduler(scheduler_ptr, |raw| { | ||
with_vec(subject_types_ptr, subject_types_len as usize, |subject_types| { | ||
let path_str = unsafe { CStr::from_ptr(path_ptr).to_string_lossy().into_owned() }; | ||
let path = Path::new(path_str.as_str()); | ||
|
||
let graph = graph_full(raw, subject_types); | ||
write_to_file(path, &graph).unwrap_or_else(|e| { | ||
println!("Failed to visualize to {}: {:?}", path.display(), e); | ||
}); | ||
}) | ||
}) | ||
} | ||
|
||
#[no_mangle] | ||
pub extern fn rule_subgraph_visualize( | ||
scheduler_ptr: *mut RawScheduler, | ||
subject_type: TypeId, | ||
product_type: TypeConstraint, | ||
path_ptr: *const raw::c_char | ||
) { | ||
with_scheduler(scheduler_ptr, |raw| { | ||
let path_str = unsafe { CStr::from_ptr(path_ptr).to_string_lossy().into_owned() }; | ||
let path = Path::new(path_str.as_str()); | ||
|
||
let graph = graph_sub(raw, subject_type, product_type); | ||
write_to_file(path, &graph).unwrap_or_else(|e| { | ||
println!("Failed to visualize to {}: {:?}", path.display(), e); | ||
}); | ||
}) | ||
} | ||
|
||
|
||
fn graph_full(raw: &mut RawScheduler, subject_types: &Vec<TypeId>) -> RuleGraph { | ||
let graph_maker = GraphMaker::new(&raw.scheduler.tasks, | ||
RootSubjectTypes { subject_types: subject_types.clone() }); | ||
graph_maker.full_graph() | ||
} | ||
|
||
fn graph_sub( | ||
raw: &mut RawScheduler, | ||
subject_type: TypeId, | ||
product_type: TypeConstraint | ||
) -> RuleGraph { | ||
let graph_maker = GraphMaker::new(&raw.scheduler.tasks, | ||
RootSubjectTypes { subject_types: vec![subject_type.clone()] }); | ||
graph_maker.sub_graph(&subject_type, &product_type) | ||
} | ||
|
||
fn write_to_file(path: &Path, graph: &RuleGraph) -> io::Result<()> { | ||
let file = try!(OpenOptions::new().append(true).open(path)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Append doesn't seem like a good default... I don't want a graph appended to an existing file, since dot isn't appendable afaik? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Makes sense. This was cargo culted from one of the other file creating fns. -- trace in graph.rs |
||
let mut f = BufWriter::new(file); | ||
|
||
try!(write!(&mut f, "{}\n", format!("{}", graph))); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We've mostly switched to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. updating to it. |
||
Ok(()) | ||
} | ||
|
||
fn with_scheduler<F, T>(scheduler_ptr: *mut RawScheduler, f: F) -> T | ||
where F: FnOnce(&mut RawScheduler)->T { | ||
let mut scheduler = unsafe { Box::from_raw(scheduler_ptr) }; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This struct doesn't appear to be carrying its weight. Could either make it a tuple struct so that you can construct it more easily (
RootSubjectTypes(vec![subject_type.clone())
) or just remove it, probably.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah. I added it thinking it might accrete more behavior, but then it didn't. xxing