File tree Expand file tree Collapse file tree 4 files changed +82
-0
lines changed
Expand file tree Collapse file tree 4 files changed +82
-0
lines changed Original file line number Diff line number Diff line change 7373 - run : cargo fmt --all -- --check
7474 working-directory : ./css-inline
7575
76+ - run : cargo fmt --all -- --check
77+ working-directory : ./profiler
78+
7679 - run : cargo fmt --all -- --check
7780 working-directory : ./bindings/c
7881
@@ -108,6 +111,10 @@ jobs:
108111 run : cargo clippy -- -D warnings
109112 working-directory : ./css-inline
110113
114+ - name : Profiler
115+ run : cargo clippy -- -D warnings
116+ working-directory : ./profiler
117+
111118 - name : Python
112119 run : cargo clippy -- -D warnings
113120 working-directory : ./bindings/python
Original file line number Diff line number Diff line change 44css-inline /target /
55css-inline /fuzz /target /
66css-inline /fuzz /corpus /
7+ profiler /target /
78bindings /* /target /
89
10+ perf.data
11+ perf.data.old
12+ trace.svg
13+ dhat-heap.json
14+
915# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
1016# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
1117Cargo.lock
Original file line number Diff line number Diff line change 1+ [package ]
2+ name = " profiler"
3+ version = " 0.1.0"
4+ authors = [" Dmitry Dygalo <dmitry@dygalo.dev>" ]
5+ edition = " 2021"
6+
7+ [dependencies ]
8+ pico-args = " 0.5"
9+ serde = { version = " 1" , features = [" derive" ] }
10+ serde_json = " 1"
11+ dhat = " *"
12+
13+ [dependencies .css-inline ]
14+ path = " ../css-inline"
15+ version = " *"
16+ default-features = false
17+ features = [" http" , " file" ]
18+
19+ [features ]
20+ dhat-heap = []
21+
22+ [profile .release ]
23+ debug = true
Original file line number Diff line number Diff line change 1+ use std:: fs;
2+
3+ #[ cfg( feature = "dhat-heap" ) ]
4+ #[ global_allocator]
5+ static ALLOC : dhat:: Alloc = dhat:: Alloc ;
6+
7+ struct Args {
8+ iterations : usize ,
9+ benchmark : String ,
10+ }
11+
12+ #[ derive( serde:: Deserialize , Debug ) ]
13+ struct Benchmark {
14+ name : String ,
15+ html : String ,
16+ }
17+
18+ fn main ( ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
19+ let mut args = pico_args:: Arguments :: from_env ( ) ;
20+ let args = Args {
21+ iterations : args. value_from_str ( "--iterations" ) ?,
22+ benchmark : args. value_from_str ( "--benchmark" ) ?,
23+ } ;
24+
25+ let benchmarks_str =
26+ fs:: read_to_string ( "../benchmarks/benchmarks.json" ) . expect ( "Failed to load benchmarks" ) ;
27+ let benchmarks: Vec < Benchmark > =
28+ serde_json:: from_str ( & benchmarks_str) . expect ( "Failed to load benchmarks" ) ;
29+ if let Some ( benchmark) = benchmarks. iter ( ) . find ( |x| x. name == args. benchmark ) {
30+ let mut output = Vec :: with_capacity (
31+ ( benchmark. html . len ( ) as f64 * 1.5 )
32+ . min ( usize:: MAX as f64 )
33+ . round ( ) as usize ,
34+ ) ;
35+ for _ in 0 ..args. iterations {
36+ #[ cfg( feature = "dhat-heap" ) ]
37+ let _profiler = dhat:: Profiler :: new_heap ( ) ;
38+ css_inline:: inline_to ( & benchmark. html , & mut output) . expect ( "Inlining failed" ) ;
39+ output. clear ( ) ;
40+ }
41+ } else {
42+ panic ! ( "Can not find benchmark: {}" , & args. benchmark)
43+ }
44+
45+ Ok ( ( ) )
46+ }
You can’t perform that action at this time.
0 commit comments