Skip to content

Commit b1bb642

Browse files
committed
add more tests
1 parent b49d3cd commit b1bb642

18 files changed

Lines changed: 1315 additions & 0 deletions

tests/testthat/_snaps/call-analysis.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,24 @@
5555
pv_focus(p, "outer")
5656
pv_callers(p, "outer")
5757

58+
# pv_print_callers_callees shows none when callees empty
59+
60+
Code
61+
pv_print_callers_callees(p, "bar")
62+
Output
63+
## FUNCTION ANALYSIS: bar
64+
65+
66+
Total time: 10 ms (33.3% of profile)
67+
Appearances: 1 samples
68+
69+
### Called by
70+
1 samples (100.0%) foo
71+
72+
### Calls to
73+
Callees: none
74+
75+
### Next steps
76+
pv_focus(p, "bar")
77+
pv_focus(p, "foo")
78+

tests/testthat/_snaps/compare.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,71 @@
2020
pv_focus(p_before, "deep")
2121
pv_focus(p_after, "deep")
2222

23+
# pv_print_compare shows improvements and regressions
24+
25+
Code
26+
pv_print_compare(p1, p2)
27+
Output
28+
## PROFILE COMPARISON
29+
30+
31+
32+
### Overall
33+
before_ms: 100
34+
after_ms: 100
35+
diff_ms: +0
36+
speedup: 1.00x
37+
38+
### Biggest Changes
39+
Function Before After Diff Change
40+
slow_func 50 0 -50 -100%
41+
new_func 0 50 +50 new
42+
43+
### Top Improvements
44+
slow_func: 50 -> 0 (-50 ms)
45+
46+
### Regressions
47+
new_func: 0 -> 50 (+50 ms)
48+
49+
### Next steps
50+
pv_focus(p_before, "slow_func")
51+
pv_focus(p_after, "slow_func")
52+
53+
# pv_compare_many requires at least 2 profiles
54+
55+
Code
56+
pv_compare_many(a = p)
57+
Condition
58+
Error:
59+
! At least 2 profiles are required for comparison.
60+
61+
# pv_compare_many requires named profiles
62+
63+
Code
64+
pv_compare_many(p1, p2)
65+
Condition
66+
Error:
67+
! All profiles must be named.
68+
69+
# pv_compare_many rejects non-profvis input
70+
71+
Code
72+
pv_compare_many(a = p, b = list())
73+
Condition
74+
Error:
75+
! 'b' must be a profvis object.
76+
77+
# pv_print_compare_many snapshot
78+
79+
Code
80+
pv_print_compare_many(a = p1, b = p2)
81+
Output
82+
## MULTI-PROFILE COMPARISON
83+
84+
85+
Rank Profile Time (ms) Samples vs Fastest
86+
1* a 50 5 fastest
87+
2 b 50 5 fastest
88+
89+
* = fastest
90+

tests/testthat/_snaps/diagnostics.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,14 @@
8686
pv_focus(p, "x")
8787
pv_gc_pressure(p)
8888

89+
# pv_print_suggestions handles profile with truly no suggestions
90+
91+
Code
92+
pv_print_suggestions(p)
93+
Output
94+
## OPTIMIZATION SUGGESTIONS
95+
96+
97+
No suggestions.
98+
Run pv_help() to see all available functions.
99+

tests/testthat/_snaps/focus.md

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,124 @@
8181
pv_focus(p, "bar")
8282
pv_callers(p, "foo")
8383

84+
# pv_focus handles more than 5 callers
85+
86+
Code
87+
pv_focus(p, "target")
88+
Output
89+
## FOCUS: target
90+
91+
92+
### Time Analysis
93+
Total time: 60 ms (100.0%) - time on call stack
94+
Self time: 60 ms (100.0%) - time at top of stack
95+
Child time: 0 ms ( 0.0%) - time in callees
96+
Appearances: 6 samples
97+
98+
### Called By
99+
1 calls ( 16.7%) caller1
100+
1 calls ( 16.7%) caller2
101+
1 calls ( 16.7%) caller3
102+
1 calls ( 16.7%) caller4
103+
1 calls ( 16.7%) caller5
104+
... and 1 more callers
105+
106+
### Calls To
107+
Callees: none
108+
109+
### Source Locations
110+
Source references not available.
111+
Use devtools::load_all() to enable.
112+
113+
### Next steps
114+
pv_callers(p, "target")
115+
pv_focus(p, "caller1")
116+
117+
# pv_focus shows callees none for leaf function
118+
119+
Code
120+
pv_focus(p, "bar")
121+
Output
122+
## FOCUS: bar
123+
124+
125+
### Time Analysis
126+
Total time: 10 ms ( 33.3%) - time on call stack
127+
Self time: 10 ms ( 33.3%) - time at top of stack
128+
Child time: 0 ms ( 0.0%) - time in callees
129+
Appearances: 1 samples
130+
131+
### Called By
132+
1 calls (100.0%) foo
133+
134+
### Calls To
135+
Callees: none
136+
137+
### Source Locations
138+
Source references not available.
139+
Use devtools::load_all() to enable.
140+
141+
### Next steps
142+
pv_callers(p, "bar")
143+
pv_focus(p, "foo")
144+
145+
# pv_focus handles more than 5 callees
146+
147+
Code
148+
pv_focus(p, "target")
149+
Output
150+
## FOCUS: target
151+
152+
153+
### Time Analysis
154+
Total time: 60 ms (100.0%) - time on call stack
155+
Self time: 0 ms ( 0.0%) - time at top of stack
156+
Child time: 60 ms (100.0%) - time in callees
157+
Appearances: 6 samples
158+
159+
### Called By
160+
6 calls (100.0%) (top-level)
161+
162+
### Calls To
163+
1 calls ( 16.7%) callee1
164+
1 calls ( 16.7%) callee2
165+
1 calls ( 16.7%) callee3
166+
1 calls ( 16.7%) callee4
167+
1 calls ( 16.7%) callee5
168+
... and 1 more callees
169+
170+
### Source Locations
171+
Source references not available.
172+
Use devtools::load_all() to enable.
173+
174+
### Next steps
175+
pv_focus(p, "callee1")
176+
pv_callers(p, "target")
177+
178+
# pv_focus handles function with source refs but no self-time with source
179+
180+
Code
181+
pv_focus(p, "target")
182+
Output
183+
## FOCUS: target
184+
185+
186+
### Time Analysis
187+
Total time: 10 ms (100.0%) - time on call stack
188+
Self time: 0 ms ( 0.0%) - time at top of stack
189+
Child time: 10 ms (100.0%) - time in callees
190+
Appearances: 1 samples
191+
192+
### Called By
193+
1 calls (100.0%) (top-level)
194+
195+
### Calls To
196+
1 calls (100.0%) deep
197+
198+
### Source Locations
199+
No self-time with source info.
200+
201+
### Next steps
202+
pv_focus(p, "deep")
203+
pv_callers(p, "target")
204+

0 commit comments

Comments
 (0)