Skip to content

Commit b5b2e42

Browse files
committed
Update function hit and line mapping calculations
1 parent 94b80e9 commit b5b2e42

File tree

6 files changed

+110
-170
lines changed

6 files changed

+110
-170
lines changed

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ use std::{
7575
ptr::null_mut,
7676
str::FromStr,
7777
sync::mpsc::{Receiver, Sender},
78-
thread::{spawn, JoinHandle},
78+
thread::JoinHandle,
7979
time::SystemTime,
8080
};
8181
use tracer::{

src/os/windows/debug_info.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -456,9 +456,7 @@ impl ProcessModule {
456456
self.full_name.clone(),
457457
lines,
458458
);
459-
if let Ok(o) = get_object("tsffs") {
460-
debug!(o, "Got symbol: {:?}", info);
461-
}
459+
462460
Some(info)
463461
})
464462
.collect::<Vec<_>>()
@@ -665,9 +663,6 @@ impl Module {
665663
lines,
666664
);
667665

668-
if let Ok(o) = get_object("tsffs") {
669-
debug!(o, "Got symbol: {:?}", info);
670-
}
671666
Some(info)
672667
})
673668
.collect::<Vec<_>>()

src/os/windows/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ impl WindowsOsInfo {
226226
&si.name,
227227
);
228228
si.lines.iter().for_each(|l| {
229-
(l.start_line..l.end_line).for_each(|line| {
229+
(l.start_line..=l.end_line).for_each(|line| {
230230
record.add_line_if_not_exists(line as usize);
231231
});
232232
});

src/source_cov/html.rs

Lines changed: 47 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -104,31 +104,22 @@ define! {
104104
th[style = "text-align: right;"] {
105105
"Lines"
106106
}
107-
@if (summary.hit_lines as f32 / summary.total_lines as f32)
108-
* 100.0 >= 90.0 {
107+
@let ratio = if summary.total_lines == 0 {
108+
0.0
109+
} else {
110+
summary.hit_lines as f32 / summary.total_lines as f32 * 100.0
111+
};
112+
@if ratio >= 90.0 {
109113
td[style = "text-align: right; background-color: #a7fc9d;"] {
110-
@format!(
111-
"{:.02}%",
112-
(summary.hit_lines as f32 / summary.total_lines as f32)
113-
* 100.0
114-
)
114+
@format!("{ratio:.02}%")
115115
}
116-
} else if (summary.hit_lines as f32 / summary.total_lines as f32)
117-
* 100.0 >= 30.0 {
116+
} else if ratio >= 30.0 {
118117
td[style = "text-align: right; background-color: #ffea20;"] {
119-
@format!(
120-
"{:.02}%",
121-
(summary.hit_lines as f32 / summary.total_lines as f32)
122-
* 100.0
123-
)
118+
@format!("{ratio:.02}%")
124119
}
125120
} else {
126121
td[style = "text-align: right; background-color: #ff6230;"] {
127-
@format!(
128-
"{:.02}%",
129-
(summary.hit_lines as f32 / summary.total_lines as f32)
130-
* 100.0
131-
)
122+
@format!("{ratio:.02}%")
132123
}
133124
}
134125

@@ -143,32 +134,23 @@ define! {
143134
th[style = "text-align: right;"] {
144135
"Functions"
145136
}
146-
@if (summary.hit_functions as f32 / summary.total_functions as f32)
147-
* 100.0 >= 90.0 {
137+
@let ratio = if summary.total_functions == 0 {
138+
0.0
139+
} else {
140+
summary.hit_functions as f32 / summary.total_functions as f32 * 100.0
141+
};
142+
@if ratio >= 90.0 {
148143
td[style = "text-align: right; background-color: #a7fc9d;"] {
149-
@format!(
150-
"{:.02}%",
151-
(summary.hit_functions as f32 / summary.total_functions as f32)
152-
* 100.0
153-
)
144+
@format!("{ratio:.02}%")
154145
}
155-
} else if (summary.hit_functions as f32 / summary.total_functions as f32)
156-
* 100.0 >= 30.0 {
146+
} else if ratio >= 30.0 {
157147
td[style = "text-align: right; background-color: #ffea20;"] {
158-
@format!(
159-
"{:.02}%",
160-
(summary.hit_functions as f32 / summary.total_functions as f32)
161-
* 100.0
162-
)
148+
@format!("{ratio:.02}%")
163149
}
164150

165151
} else {
166152
td[style = "text-align: right; background-color: #ff6230;"] {
167-
@format!(
168-
"{:.02}%",
169-
(summary.hit_functions as f32 / summary.total_functions as f32)
170-
* 100.0
171-
)
153+
@format!("{ratio:.02}%")
172154
}
173155
}
174156
td[style = "text-align: right; background-color: #cad7fe;"] {
@@ -351,69 +333,58 @@ define! {
351333
"<unknown>"
352334
}
353335
}
354-
@if (summary.hit_lines as f32 / summary.total_lines as f32)
355-
* 100.0 >= 90.0 {
336+
@let line_ratio = if summary.total_lines == 0 {
337+
0.0
338+
} else {
339+
summary.hit_lines as f32 / summary.total_lines as f32 * 100.0
340+
};
341+
342+
@let function_ratio = if summary.total_functions == 0 {
343+
0.0
344+
} else {
345+
summary.hit_functions as f32 / summary.total_functions as f32 * 100.0
346+
};
347+
348+
@if line_ratio >= 90.0 {
356349
td[style = "text-align: right; background-color: #a7fc9d;"] {
357-
@format!(
358-
"{:.02}%",
359-
(summary.hit_lines as f32 / summary.total_lines as f32)
360-
* 100.0
361-
)
350+
@format!("{line_ratio:.02}%")
362351
}
363-
} else if (summary.hit_lines as f32 / summary.total_lines as f32)
364-
* 100.0 >= 30.0 {
352+
} else if line_ratio >= 30.0 {
365353
td[style = "text-align: right; background-color: #ffea20;"] {
366-
@format!(
367-
"{:.02}%",
368-
(summary.hit_lines as f32 / summary.total_lines as f32)
369-
* 100.0
370-
)
354+
@format!("{line_ratio:.02}%")
371355
}
372356
} else {
373357
td[style = "text-align: right; background-color: #ff6230;"] {
374-
@format!(
375-
"{:.02}%",
376-
(summary.hit_lines as f32 / summary.total_lines as f32)
377-
* 100.0
378-
)
358+
@format!("{line_ratio:.02}%")
379359
}
380360
}
361+
381362
td[style = "text-align: right; background-color: #cad7fe;"] {
382363
@summary.total_lines
383364
}
365+
384366
td[style = "text-align: right; background-color: #cad7fe;"] {
385367
@summary.hit_lines
386368
}
387-
@if (summary.hit_functions as f32 / summary.total_functions as f32)
388-
* 100.0 >= 90.0 {
369+
370+
@if function_ratio >= 90.0 {
389371
td[style = "text-align: right; background-color: #a7fc9d;"] {
390-
@format!(
391-
"{:.02}%",
392-
(summary.hit_functions as f32 / summary.total_functions as f32)
393-
* 100.0
394-
)
372+
@format!("{function_ratio:.02}%")
395373
}
396-
} else if (summary.hit_functions as f32 / summary.total_functions as f32)
397-
* 100.0 >= 30.0 {
374+
} else if function_ratio >= 30.0 {
398375
td[style = "text-align: right; background-color: #ffea20;"] {
399-
@format!(
400-
"{:.02}%",
401-
(summary.hit_functions as f32 / summary.total_functions as f32)
402-
* 100.0
403-
)
376+
@format!("{function_ratio:.02}%")
404377
}
405378
} else {
406379
td[style = "text-align: right; background-color: #ff6230;"] {
407-
@format!(
408-
"{:.02}%",
409-
(summary.hit_functions as f32 / summary.total_functions as f32)
410-
* 100.0
411-
)
380+
@format!("{function_ratio:.02}%")
412381
}
413382
}
383+
414384
td[style = "text-align: right; background-color: #cad7fe;"] {
415385
@summary.total_functions
416386
}
387+
417388
td[style = "text-align: right; background-color: #cad7fe;"] {
418389
@summary.hit_functions
419390
}

src/source_cov/lcov.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -508,9 +508,6 @@ impl Records {
508508
let mut traversal = DfsPostOrder::new(&graph, *root);
509509

510510
while let Some(node) = traversal.next(&graph) {
511-
let weight = graph
512-
.node_weight(node)
513-
.ok_or_else(|| anyhow!("No weight for node"))?;
514511
let path = graph
515512
.node_weight(node)
516513
.ok_or_else(|| anyhow!("No weight for node"))?

0 commit comments

Comments
 (0)