Skip to content

Commit 6c4d8f8

Browse files
authored
feat: ✨ 通用 profile 方式 (#532)
* feat: ✨ 通用 profile 方式 * feat: ✨ compile after starting capture frame --------- Co-authored-by: pshu <[email protected]>
1 parent f3731e4 commit 6c4d8f8

File tree

3 files changed

+41
-23
lines changed

3 files changed

+41
-23
lines changed

.cargo/config.toml

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ codecov = "llvm-cov nextest --workspace"
33
lint = "clippy --workspace --all-targets --all-features -- -D warnings -Aclippy::module_inception"
44
lintfix = "clippy --workspace --fix --allow-dirty --allow-staged --all-targets --all-features -- -D warnings -Aclippy::module_inception"
55
mako = "run --bin mako"
6+
profile_mako = "run --features profile --bin mako"
67

78
# macos
89
[target.x86_64-apple-darwin]

crates/mako/src/main.rs

+26-8
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ use std::sync::Arc;
55
use mako_core::anyhow::Result;
66
use mako_core::clap::Parser;
77
use mako_core::tokio;
8+
#[cfg(feature = "profile")]
9+
use mako_core::tokio::sync::Notify;
810
use mako_core::tracing::debug;
911

1012
use crate::compiler::Args;
@@ -91,23 +93,39 @@ async fn main() -> Result<()> {
9193

9294
#[cfg(feature = "profile")]
9395
{
96+
let notify = Arc::new(Notify::new());
97+
let to_be_notify = notify.clone();
98+
99+
tokio::spawn(async move {
100+
let compiler = compiler.clone();
101+
102+
to_be_notify.notified().await;
103+
104+
compiler.compile().unwrap();
105+
106+
if cli.watch {
107+
let d = crate::dev::DevServer::new(root.clone(), compiler.clone());
108+
d.serve().await;
109+
}
110+
});
111+
94112
mako_core::puffin::set_scopes_on(true);
95113
let native_options = Default::default();
96-
let compiler = compiler.clone();
97114
let _ = mako_core::eframe::run_native(
98115
"puffin egui eframe",
99116
native_options,
100-
Box::new(move |_cc| Box::new(ProfileApp::new(compiler))),
117+
Box::new(move |_cc| Box::new(ProfileApp::new(notify))),
101118
);
102119
}
103120

104121
#[cfg(not(feature = "profile"))]
105-
compiler.compile()?;
106-
107-
if cli.watch {
108-
let d = crate::dev::DevServer::new(root.clone(), compiler);
109-
// TODO: when in Dev Mode, Dev Server should start asap, and provider a loading while in first compiling
110-
d.serve().await;
122+
{
123+
compiler.compile()?;
124+
if cli.watch {
125+
let d = crate::dev::DevServer::new(root.clone(), compiler);
126+
// TODO: when in Dev Mode, Dev Server should start asap, and provider a loading while in first compiling
127+
d.serve().await;
128+
}
111129
}
112130
Ok(())
113131
}

crates/mako/src/profile_gui.rs

+14-15
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
1+
#[cfg(feature = "profile")]
12
use std::sync::Arc;
23

34
#[cfg(feature = "profile")]
45
use mako_core::eframe::egui;
6+
#[cfg(feature = "profile")]
7+
use mako_core::tokio::sync::Notify;
58

6-
use crate::compiler::Compiler;
7-
9+
#[cfg(feature = "profile")]
810
pub struct ProfileApp {
9-
#[allow(dead_code)]
10-
frame_counter: u64,
11-
#[allow(dead_code)]
12-
compiler: Arc<Compiler>,
11+
notified: bool,
12+
notify: Arc<Notify>,
1313
}
1414

15+
#[cfg(feature = "profile")]
1516
impl ProfileApp {
1617
#[allow(dead_code)]
17-
pub fn new(compiler: Arc<Compiler>) -> Self {
18+
pub fn new(notify: Arc<Notify>) -> Self {
1819
Self {
19-
frame_counter: 0,
20-
compiler,
20+
notified: false,
21+
notify,
2122
}
2223
}
2324
}
@@ -27,12 +28,10 @@ impl mako_core::eframe::App for ProfileApp {
2728
fn update(&mut self, ctx: &egui::Context, _frame: &mut mako_core::eframe::Frame) {
2829
mako_core::puffin::GlobalProfiler::lock().new_frame(); // call once per frame!
2930

30-
mako_core::puffin_egui::profiler_window(ctx);
31-
32-
if self.frame_counter == 0 {
33-
self.compiler.compile().unwrap();
31+
if !self.notified {
32+
self.notified = true;
33+
self.notify.notify_one();
3434
}
35-
36-
self.frame_counter += 1;
35+
mako_core::puffin_egui::profiler_window(ctx);
3736
}
3837
}

0 commit comments

Comments
 (0)