@@ -26,9 +26,13 @@ pub struct DataDisplayOptions {
26
26
27
27
/// Used for optionally converting message levels to strings
28
28
pub level_conversion : Option < LevelConversion > ,
29
+
30
+ /// Used for optionally including the size of messages
31
+ pub row_size_config : Option < RowSizeConfig > ,
29
32
}
30
33
31
- #[ derive( serde:: Deserialize , serde:: Serialize , Debug , PartialEq , Eq ) ]
34
+ #[ derive( Default , serde:: Deserialize , serde:: Serialize , Debug , PartialEq , Eq ) ]
35
+ #[ serde( default ) ]
32
36
pub struct FieldColoringRules {
33
37
/// Matches a field value to color
34
38
pub value_color_map : BTreeMap < String , Color32 > ,
@@ -45,6 +49,7 @@ pub enum RowParseErrorHandling {
45
49
}
46
50
47
51
#[ derive( serde:: Deserialize , serde:: Serialize , Debug , PartialEq , Eq ) ]
52
+ #[ serde( default ) ]
48
53
pub struct LevelConversion {
49
54
/// Skips record if field name already exists
50
55
pub display_field_name : String ,
@@ -53,6 +58,37 @@ pub struct LevelConversion {
53
58
pub convert_map : BTreeMap < i64 , String > ,
54
59
}
55
60
61
+ #[ derive( Default , serde:: Deserialize , serde:: Serialize , Debug , PartialEq , Eq ) ]
62
+ #[ serde( default ) ]
63
+ pub struct RowSizeConfig {
64
+ pub field_name : String ,
65
+ pub units : SizeUnits ,
66
+ }
67
+
68
+ #[ derive( Default , serde:: Deserialize , serde:: Serialize , Debug , PartialEq , Eq ) ]
69
+ pub enum SizeUnits {
70
+ Bytes ,
71
+ #[ default]
72
+ KB ,
73
+ MB ,
74
+ GB ,
75
+ TB ,
76
+ // TODO 5: Add an auto option to use smallest non fractional (would need to use str instead of f32)
77
+ }
78
+ impl SizeUnits {
79
+ pub ( crate ) fn convert ( & self , row_size_in_bytes : usize ) -> serde_json:: Value {
80
+ let scalar = match self {
81
+ SizeUnits :: Bytes => 1.0 ,
82
+ SizeUnits :: KB => 1024.0 ,
83
+ SizeUnits :: MB => 1024.0 * 1024.0 ,
84
+ SizeUnits :: GB => 1024.0 * 1024.0 * 1024.0 ,
85
+ SizeUnits :: TB => 1024.0 * 1024.0 * 1024.0 * 1024.0 ,
86
+ } ;
87
+ let result = row_size_in_bytes as f64 / scalar;
88
+ result. into ( )
89
+ }
90
+ }
91
+
56
92
impl DataDisplayOptions {
57
93
pub fn main_list_fields ( & self ) -> & [ String ] {
58
94
& self . main_list_fields
@@ -72,6 +108,7 @@ impl Default for DataDisplayOptions {
72
108
main_list_fields : [
73
109
"row#" ,
74
110
"level_str" ,
111
+ "row_size" ,
75
112
"time" ,
76
113
"request_id" ,
77
114
"otel.name" ,
@@ -108,6 +145,10 @@ impl Default for DataDisplayOptions {
108
145
. collect ( ) ,
109
146
emphasize_if_matching_field_idx : Some ( 3 ) ,
110
147
row_idx_field_name : Some ( "row#" . to_string ( ) ) ,
148
+ row_size_config : Some ( RowSizeConfig {
149
+ field_name : "row_size" . to_string ( ) ,
150
+ units : SizeUnits :: Bytes ,
151
+ } ) ,
111
152
row_parse_error_handling : Default :: default ( ) ,
112
153
level_conversion : Some ( Default :: default ( ) ) ,
113
154
colored_fields : [ (
0 commit comments