Skip to content
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

Add a visualization of thread activity #443

Merged
merged 3 commits into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions fontc/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ pub struct Args {
#[arg(long, default_value = "false")]
pub flatten_components: bool,

/// Whether to out timing data, notably a visualization of threadpool execution of tasks.
///
/// See <https://github.com/googlefonts/fontc/pull/443>
#[arg(long, default_value = "false")]
pub emit_timing: bool,

/// Working directory for the build process. If emit-ir is on, written here.
#[arg(short, long, default_value = "build")]
pub build_dir: PathBuf,
Expand All @@ -53,6 +59,7 @@ impl Args {
flags.set(Flags::EMIT_DEBUG, self.emit_debug);
flags.set(Flags::PREFER_SIMPLE_GLYPHS, self.prefer_simple_glyphs);
flags.set(Flags::FLATTEN_COMPONENTS, self.flatten_components);
flags.set(Flags::EMIT_TIMING, self.emit_timing);

flags
}
Expand All @@ -69,6 +76,7 @@ impl Args {
source,
emit_ir: true,
emit_debug: false, // they get destroyed by test cleanup
emit_timing: false,
build_dir: build_dir.to_path_buf(),
prefer_simple_glyphs: Flags::default().contains(Flags::PREFER_SIMPLE_GLYPHS),
flatten_components: Flags::default().contains(Flags::FLATTEN_COMPONENTS),
Expand Down
6 changes: 3 additions & 3 deletions fontc/src/change_detector.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! tracking changes during compilation

use std::{ffi::OsStr, fmt::Debug, fs, path::Path};
use std::{ffi::OsStr, fmt::Debug, fs, path::Path, time::Instant};

use bitflags::bitflags;
use fontbe::{
Expand Down Expand Up @@ -165,8 +165,8 @@ impl ChangeDetector {
workload.add(work, run);
}

pub fn create_workload(&mut self) -> Result<Workload, Error> {
let mut workload = Workload::new(self);
pub fn create_workload(&mut self, t0: Instant) -> Result<Workload, Error> {
let mut workload = Workload::new(self, t0);

// Create work roughly in the order it would typically occur
// Work is eligible to run as soon as all dependencies are complete
Expand Down
12 changes: 9 additions & 3 deletions fontc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ mod args;
mod change_detector;
mod config;
mod error;
mod timing;
pub mod work;
mod workload;

Expand All @@ -17,6 +18,7 @@ use workload::Workload;
use std::{
fs, io,
path::{Path, PathBuf},
time::Instant,
};

use fontbe::{
Expand Down Expand Up @@ -260,8 +262,11 @@ fn add_glyph_be_job(workload: &mut Workload, glyph_name: GlyphName) {
}

//FIXME: I should be a method on ChangeDetector
pub fn create_workload(change_detector: &mut ChangeDetector) -> Result<Workload, Error> {
let mut workload = change_detector.create_workload()?;
pub fn create_workload(
change_detector: &mut ChangeDetector,
t0: Instant,
) -> Result<Workload, Error> {
let mut workload = change_detector.create_workload(t0)?;

// FE: f(source) => IR
add_feature_ir_job(&mut workload)?;
Expand Down Expand Up @@ -462,6 +467,7 @@ mod tests {
}

fn compile(args: Args) -> TestCompile {
let t0 = Instant::now();
let _ = env_logger::builder().is_test(true).try_init();

info!("Compile {args:?}");
Expand All @@ -474,7 +480,7 @@ mod tests {
let mut change_detector =
ChangeDetector::new(config.clone(), ir_paths.clone(), prev_inputs).unwrap();

let mut workload = create_workload(&mut change_detector).unwrap();
let mut workload = create_workload(&mut change_detector, t0).unwrap();

// Try to do the work
// As we currently don't stress dependencies just run one by one
Expand Down
24 changes: 20 additions & 4 deletions fontc/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
use std::io::Write;
use std::{
fs::OpenOptions,
io::{BufWriter, Write},
time::Instant,
};

use clap::Parser;

use fontbe::orchestration::Context as BeContext;
use fontc::{init_paths, write_font_file, Args, ChangeDetector, Config, Error};
use fontir::orchestration::Context as FeContext;
use fontir::orchestration::{Context as FeContext, Flags};

fn main() {
// catch and print errors manually, to avoid just seeing the Debug impls
Expand All @@ -16,6 +20,7 @@ fn main() {
}

fn run() -> Result<(), Error> {
let t0 = Instant::now();
env_logger::builder()
.format(|buf, record| {
let ts = buf.timestamp_micros();
Expand All @@ -38,15 +43,26 @@ fn run() -> Result<(), Error> {
let prev_inputs = config.init()?;

let mut change_detector = ChangeDetector::new(config.clone(), ir_paths.clone(), prev_inputs)?;
let workload = fontc::create_workload(&mut change_detector)?;
let workload = fontc::create_workload(&mut change_detector, t0)?;

let fe_root = FeContext::new_root(
config.args.flags(),
ir_paths,
workload.current_inputs().clone(),
);
let be_root = BeContext::new_root(config.args.flags(), be_paths, &fe_root);
workload.exec(&fe_root, &be_root)?;
let mut timing = workload.exec(&fe_root, &be_root)?;

if config.args.flags().contains(Flags::EMIT_TIMING) {
let out_file = OpenOptions::new()
.write(true)
.create(true)
.truncate(true)
.open(config.args.build_dir.join("threads.svg"))
.map_err(Error::IoError)?;
let mut buf = BufWriter::new(out_file);
timing.write_svg(&mut buf)?
}

change_detector.finish_successfully()?;

Expand Down
Loading