File tree 4 files changed +82
-0
lines changed
4 files changed +82
-0
lines changed Original file line number Diff line number Diff line change 73
73
- run : cargo fmt --all -- --check
74
74
working-directory : ./css-inline
75
75
76
+ - run : cargo fmt --all -- --check
77
+ working-directory : ./profiler
78
+
76
79
- run : cargo fmt --all -- --check
77
80
working-directory : ./bindings/c
78
81
@@ -108,6 +111,10 @@ jobs:
108
111
run : cargo clippy -- -D warnings
109
112
working-directory : ./css-inline
110
113
114
+ - name : Profiler
115
+ run : cargo clippy -- -D warnings
116
+ working-directory : ./profiler
117
+
111
118
- name : Python
112
119
run : cargo clippy -- -D warnings
113
120
working-directory : ./bindings/python
Original file line number Diff line number Diff line change 4
4
css-inline /target /
5
5
css-inline /fuzz /target /
6
6
css-inline /fuzz /corpus /
7
+ profiler /target /
7
8
bindings /* /target /
8
9
10
+ perf.data
11
+ perf.data.old
12
+ trace.svg
13
+ dhat-heap.json
14
+
9
15
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
10
16
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
11
17
Cargo.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 <[email protected] >" ]
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