@@ -23,11 +23,19 @@ use anyhow::Context;
23
23
use crate :: eval:: runtime:: profile:: bc:: BcPairsProfileData ;
24
24
use crate :: eval:: runtime:: profile:: bc:: BcProfileData ;
25
25
use crate :: eval:: ProfileMode ;
26
+ use crate :: values:: AggregateHeapProfileInfo ;
27
+
28
+ #[ derive( Debug , thiserror:: Error ) ]
29
+ enum ProfileDataError {
30
+ #[ error( "Profile data is not consistent with profile mode (internal error)" ) ]
31
+ ProfileDataNotConsistent ,
32
+ }
26
33
27
34
#[ derive( Clone , Debug ) ]
28
35
pub ( crate ) enum ProfileDataImpl {
29
36
Bc ( Box < BcProfileData > ) ,
30
37
BcPairs ( BcPairsProfileData ) ,
38
+ AggregateHeapProfileInfo ( Box < AggregateHeapProfileInfo > ) ,
31
39
Other ( String ) ,
32
40
}
33
41
@@ -49,10 +57,21 @@ impl ProfileData {
49
57
50
58
/// Generate a string with profile data (e.g. CSV or flamegraph, depending on profile type).
51
59
pub fn gen ( & self ) -> anyhow:: Result < String > {
52
- match & self . profile {
53
- ProfileDataImpl :: Other ( profile) => Ok ( profile. clone ( ) ) ,
54
- ProfileDataImpl :: Bc ( bc) => Ok ( bc. gen_csv ( ) ) ,
55
- ProfileDataImpl :: BcPairs ( bc_pairs) => Ok ( bc_pairs. gen_csv ( ) ) ,
60
+ match ( & self . profile , & self . profile_mode ) {
61
+ ( ProfileDataImpl :: Other ( profile) , _) => Ok ( profile. clone ( ) ) ,
62
+ ( ProfileDataImpl :: Bc ( bc) , _) => Ok ( bc. gen_csv ( ) ) ,
63
+ ( ProfileDataImpl :: BcPairs ( bc_pairs) , _) => Ok ( bc_pairs. gen_csv ( ) ) ,
64
+ (
65
+ ProfileDataImpl :: AggregateHeapProfileInfo ( profile) ,
66
+ ProfileMode :: HeapFlameRetained | ProfileMode :: HeapFlameAllocated ,
67
+ ) => Ok ( profile. gen_flame_graph ( ) ) ,
68
+ (
69
+ ProfileDataImpl :: AggregateHeapProfileInfo ( profile) ,
70
+ ProfileMode :: HeapSummaryRetained | ProfileMode :: HeapSummaryAllocated ,
71
+ ) => Ok ( profile. gen_summary_csv ( ) ) ,
72
+ ( ProfileDataImpl :: AggregateHeapProfileInfo ( _) , _) => {
73
+ Err ( ProfileDataError :: ProfileDataNotConsistent . into ( ) )
74
+ }
56
75
}
57
76
}
58
77
0 commit comments