Skip to content

Commit 4de66c7

Browse files
committed
Implement own profiling macro that supports multi-threading
1 parent 8103db9 commit 4de66c7

17 files changed

Lines changed: 422 additions & 65 deletions

Cargo.lock

Lines changed: 3 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

splashsurf/src/convert.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use crate::io;
22
use anyhow::anyhow;
33
use anyhow::Context;
4-
use splashsurf_lib::coarse_prof::profile;
54
use splashsurf_lib::nalgebra::Vector3;
5+
use splashsurf_lib::profile;
66
use std::path::PathBuf;
77
use structopt::StructOpt;
88

splashsurf/src/io.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ use std::path::Path;
44

55
use anyhow::{anyhow, Context};
66
use log::info;
7-
use splashsurf_lib::coarse_prof::profile;
87
use splashsurf_lib::nalgebra::Vector3;
8+
use splashsurf_lib::profile;
99
use splashsurf_lib::Real;
1010

1111
pub mod bgeo_format;

splashsurf/src/main.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ fn run_splashsurf() -> Result<(), anyhow::Error> {
8080

8181
// Write coarse_prof stats using log::info
8282
info!("Timings:");
83-
coarse_prof_write_string()?
83+
splashsurf_lib::profiling::write_to_string()
84+
.unwrap()
8485
.split("\n")
8586
.filter(|l| l.len() > 0)
8687
.for_each(|l| info!("{}", l));
@@ -182,13 +183,6 @@ fn log_program_info() {
182183
info!("Called with command line: {}", cmd_line);
183184
}
184185

185-
/// Returns the coarse_prof::write output as a string
186-
fn coarse_prof_write_string() -> Result<String, anyhow::Error> {
187-
let mut buffer = Vec::new();
188-
splashsurf_lib::coarse_prof::write(&mut buffer)?;
189-
Ok(String::from_utf8_lossy(buffer.as_slice()).into_owned())
190-
}
191-
192186
#[derive(Copy, Clone, Debug)]
193187
enum VerbosityLevel {
194188
None,

splashsurf/src/reconstruction.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ use arguments::{
55
};
66
use log::info;
77
use rayon::prelude::*;
8-
use splashsurf_lib::coarse_prof::profile;
98
use splashsurf_lib::mesh::PointCloud3d;
9+
use splashsurf_lib::profile;
1010
use splashsurf_lib::vtkio::model::UnstructuredGridPiece;
1111
use splashsurf_lib::{density_map, Index, Real};
1212
use std::convert::TryFrom;

splashsurf_lib/Cargo.toml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,25 +22,29 @@ exclude = [
2222
[features]
2323
default = []
2424
vtk_extras = ["vtkio"]
25-
profiling = ["coarse-prof"]
25+
profiling = ["lazy_static"]
2626

2727
[dependencies]
2828
log = "0.4"
2929
nalgebra = "0.24"
3030
num = "0.3"
3131
anyhow = "1.0"
3232
thiserror = "1.0"
33-
coarse-prof = { version = "0.2", optional = true }
3433
itertools = "0.10"
3534
rayon = "1.5"
3635
dashmap = "4.0"
3736
fxhash = "0.2"
38-
vtkio = { version = "0.5", optional = true }
3937
thread_local = "1.1"
40-
smallvec = { version = "1.6", features = ["union"] }
4138
bitflags = "1.2"
39+
smallvec = { version = "1.6", features = ["union"] }
4240
arrayvec = "0.5"
4341

42+
# VTK extras
43+
vtkio = { version = "0.5", optional = true }
44+
45+
# Needed for profiling feature
46+
lazy_static = { version = "1.4", optional = true }
47+
4448
[dev-dependencies]
4549
criterion = "0.3"
4650

splashsurf_lib/src/density_map.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,12 @@
1818
//! Note that all density mapping functions always use the global background grid for flat point
1919
//! indices, even if the density map is only generated for a smaller subdomain.
2020
21+
use crate::aabb::AxisAlignedBoundingBox3d;
2122
use crate::kernel::DiscreteSquaredDistanceCubicKernel;
2223
use crate::mesh::{HexMesh3d, MeshWithPointData};
2324
use crate::uniform_grid::{OwningSubdomainGrid, Subdomain, UniformGrid};
2425
use crate::utils::{ChunkSize, ParallelPolicy};
25-
use crate::{new_map, AxisAlignedBoundingBox3d, HashState, Index, MapType, ParallelMapType, Real};
26+
use crate::{new_map, profile, HashState, Index, MapType, ParallelMapType, Real};
2627
use dashmap::ReadOnlyView as ReadDashMap;
2728
use log::{info, trace, warn};
2829
use nalgebra::Vector3;

splashsurf_lib/src/lib.rs

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,7 @@
22
//! Library for surface reconstruction of SPH particle data using marching cubes.
33
//!
44
//! Entry points are the [`reconstruct_surface`] or [`reconstruct_surface_inplace`] functions.
5-
//!
65
7-
/// Re-export the version of `coarse_prof` used by this crate, if profiling is enabled
8-
#[cfg(feature = "profiling")]
9-
pub use coarse_prof;
106
use log::info;
117
/// Re-export the version of `nalgebra` used by this crate
128
pub use nalgebra;
@@ -30,20 +26,9 @@ use crate::reconstruction::{
3026
use crate::workspace::ReconstructionWorkspace;
3127

3228
#[cfg(feature = "profiling")]
33-
/// Invokes coarse_prof::profile! with the given expression
34-
macro_rules! profile {
35-
($body:expr) => {
36-
coarse_prof::profile!($body);
37-
};
38-
}
39-
40-
#[cfg(not(feature = "profiling"))]
41-
/// No-op macro if profiling is disabled
42-
macro_rules! profile {
43-
($body:expr) => {
44-
$body
45-
};
46-
}
29+
pub mod profiling;
30+
#[doc(hidden)]
31+
pub mod profiling_macro;
4732

4833
mod aabb;
4934
pub mod density_map;

splashsurf_lib/src/marching_cubes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use crate::marching_cubes::triangulation::{
99
};
1010
use crate::mesh::TriMesh3d;
1111
use crate::uniform_grid::{DummySubdomain, OwningSubdomainGrid, Subdomain};
12-
use crate::{new_map, DensityMap, Index, MapType, Real, UniformGrid};
12+
use crate::{new_map, profile, DensityMap, Index, MapType, Real, UniformGrid};
1313
use nalgebra::Vector3;
1414

1515
pub mod marching_cubes_lut;

splashsurf_lib/src/marching_cubes/narrow_band_extraction.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::marching_cubes::stitching::{collect_boundary_cell_data, BoundaryData}
22
use crate::marching_cubes::{CellData, MarchingCubesInput, RelativeToThreshold};
33
use crate::topology::{Axis, DirectedAxisArray};
44
use crate::uniform_grid::{CellIndex, GridBoundaryFaceFlags, PointIndex, Subdomain};
5-
use crate::{DensityMap, Index, MapType, Real};
5+
use crate::{profile, DensityMap, Index, MapType, Real};
66
use log::trace;
77
use nalgebra::Vector3;
88

0 commit comments

Comments
 (0)