switch to profiling crates

This switches to the profiling crate for compatible
profiling between rust libraries.

To enable:

$ cargo build --release --features puffin

Feel free to experiment with other profiling backends
as well! Would be great to get tracy working.
This commit is contained in:
William Casarin
2025-03-23 10:43:49 -07:00
parent 7b9e6f180c
commit 54deb2dd88
20 changed files with 46 additions and 80 deletions

View File

@@ -32,6 +32,7 @@ ehttp = {workspace = true }
mime_guess = { workspace = true }
egui-winit = { workspace = true }
tokenator = { workspace = true }
profiling = { workspace = true }
[dev-dependencies]
tempfile = { workspace = true }
@@ -40,4 +41,4 @@ tempfile = { workspace = true }
jni = { workspace = true }
[features]
profiling = ["puffin", "puffin_egui"]
puffin = ["puffin_egui", "dep:puffin"]

View File

@@ -76,8 +76,7 @@ fn render_notedeck(notedeck: &mut Notedeck, ctx: &egui::Context) {
impl eframe::App for Notedeck {
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
#[cfg(feature = "profiling")]
puffin::GlobalProfiler::lock().new_frame();
profiling::finish_frame!();
// handle account updates
self.accounts.update(&mut self.ndb, &mut self.pool, ctx);
@@ -97,7 +96,7 @@ impl eframe::App for Notedeck {
}
}
#[cfg(feature = "profiling")]
#[cfg(feature = "puffin")]
puffin_egui::profiler_window(ctx);
}
@@ -107,15 +106,16 @@ impl eframe::App for Notedeck {
}
}
#[cfg(feature = "profiling")]
fn setup_profiling() {
#[cfg(feature = "puffin")]
fn setup_puffin() {
info!("setting up puffin");
puffin::set_scopes_on(true); // tell puffin to collect data
}
impl Notedeck {
pub fn new<P: AsRef<Path>>(ctx: &egui::Context, data_path: P, args: &[String]) -> Self {
#[cfg(feature = "profiling")]
setup_profiling();
#[cfg(feature = "puffin")]
setup_puffin();
// Skip the first argument, which is the program name.
let (parsed_args, unrecognized_args) = Args::parse(&args[1..]);

View File

@@ -246,6 +246,7 @@ impl UnknownId {
/// We return all of this in a HashSet so that we can fetch these from
/// remote relays.
///
#[profiling::function]
pub fn get_unknown_note_ids<'a>(
ndb: &Ndb,
cached_note: &CachedNote,
@@ -253,9 +254,6 @@ pub fn get_unknown_note_ids<'a>(
note: &Note<'a>,
ids: &mut HashMap<UnknownId, HashSet<RelayUrl>>,
) -> Result<()> {
#[cfg(feature = "profiling")]
puffin::profile_function!();
// the author pubkey
if ndb.get_profile_by_pubkey(txn, note.pubkey()).is_err() {
ids.entry(UnknownId::Pubkey(Pubkey::new(*note.pubkey())))