5
5
use crate :: diagnostics:: { Diagnostics , Event } ;
6
6
use crate :: enums:: {
7
7
ClockCorrectionStrategy , ClockUpdateReason , FrequencyDiscardReason , InitializeRtcOutcome , Role ,
8
- SampleValidationError , TimeSourceError , Track , WriteRtcOutcome ,
8
+ SampleValidationError , TimeSourceError , Track , UserAdjustUtcOutcome , WriteRtcOutcome ,
9
9
} ;
10
10
use crate :: { MonitorTrack , PrimaryTrack , TimeSource } ;
11
11
use fidl_fuchsia_time_external:: Status ;
12
12
use fuchsia_inspect:: {
13
- Inspector , IntProperty , Node , NumericProperty , Property , StringProperty , UintProperty ,
13
+ BoolProperty , Inspector , IntProperty , Node , NumericProperty , Property , StringProperty ,
14
+ UintProperty ,
14
15
} ;
15
16
use fuchsia_runtime:: { UtcClock , UtcClockDetails , UtcDuration , UtcInstant } ;
16
17
use fuchsia_sync:: Mutex ;
@@ -187,6 +188,49 @@ impl RealTimeClockNode {
187
188
}
188
189
}
189
190
191
+ /// An inspect `Node` and properties used to describe the history of user UTC
192
+ /// adjustments.
193
+ struct UserAdjustUtcNode {
194
+ /// The count of successful user adjustment UTC attempts.
195
+ success_count : UintProperty ,
196
+ /// The count of failed user adjustment UTC attempts.
197
+ failure_count : UintProperty ,
198
+ /// The value of the offset resulting from the last successful proposal.
199
+ last_allowed_offset_nanos : IntProperty ,
200
+ /// Was last update was a failure?
201
+ last_update_failure : BoolProperty ,
202
+ /// The inspect node these fields are exported to.
203
+ _node : Node ,
204
+ }
205
+
206
+ impl UserAdjustUtcNode {
207
+ pub fn new ( node : Node ) -> Self {
208
+ Self {
209
+ success_count : node. create_uint ( "success_count" , 0 ) ,
210
+ failure_count : node. create_uint ( "failure_count" , 0 ) ,
211
+ last_allowed_offset_nanos : node. create_int ( "last_proposed_offset_nanos" , 0 ) ,
212
+ last_update_failure : node. create_bool ( "last_updated_failure" , false ) ,
213
+ _node : node,
214
+ }
215
+ }
216
+ }
217
+
218
+ impl UserAdjustUtcNode {
219
+ fn update_user_adjust_utc ( & mut self , outcome : UserAdjustUtcOutcome , offset : UtcDuration ) {
220
+ match outcome {
221
+ UserAdjustUtcOutcome :: Succeeded => {
222
+ self . success_count . add ( 1 ) ;
223
+ self . last_update_failure . set ( false ) ;
224
+ self . last_allowed_offset_nanos . set ( offset. into_nanos ( ) ) ;
225
+ }
226
+ UserAdjustUtcOutcome :: Failed => {
227
+ self . failure_count . add ( 1 ) ;
228
+ self . last_update_failure . set ( true ) ;
229
+ }
230
+ }
231
+ }
232
+ }
233
+
190
234
/// An inspect `Node` and properties used to describe the health of a time source.
191
235
struct TimeSourceNode {
192
236
/// The most recent status of the time source.
@@ -210,7 +254,7 @@ impl TimeSourceNode {
210
254
status_change : node. create_int ( "status_change_reference" , reference_time ( ) ) ,
211
255
failure_counters : HashMap :: new ( ) ,
212
256
rejection_counters : HashMap :: new ( ) ,
213
- node : node ,
257
+ node,
214
258
}
215
259
}
216
260
@@ -395,6 +439,8 @@ pub struct InspectDiagnostics {
395
439
tracks : Mutex < HashMap < Track , TrackNode > > ,
396
440
/// Details of interactions with the real time clock.
397
441
rtc : Mutex < Option < RealTimeClockNode > > ,
442
+ /// Details of user utc adjustments.
443
+ user_utc_adjustments : Mutex < Option < UserAdjustUtcNode > > ,
398
444
/// The inspect node used to export the contents of this `InspectDiagnostics`.
399
445
node : Node ,
400
446
}
@@ -406,6 +452,7 @@ impl InspectDiagnostics {
406
452
node : & Node ,
407
453
primary : & PrimaryTrack ,
408
454
optional_monitor : & Option < MonitorTrack > ,
455
+ allow_user_utc_adjustments : bool ,
409
456
) -> Self {
410
457
// Record fixed data directly into the node without retaining any references.
411
458
node. record_child ( "initialization" , |child| TimeSet :: now ( & primary. clock ) . record ( child) ) ;
@@ -434,11 +481,18 @@ impl InspectDiagnostics {
434
481
) ;
435
482
}
436
483
484
+ let user_utc_adjustments = Mutex :: new ( if allow_user_utc_adjustments {
485
+ Some ( UserAdjustUtcNode :: new ( node. create_child ( "user_utc_adjustments" ) ) )
486
+ } else {
487
+ None
488
+ } ) ;
489
+
437
490
let diagnostics = InspectDiagnostics {
438
491
time_sources : Mutex :: new ( time_sources_hashmap) ,
439
492
tracks : Mutex :: new ( tracks_hashmap) ,
440
493
rtc : Mutex :: new ( None ) ,
441
494
node : node. clone_weak ( ) ,
495
+ user_utc_adjustments,
442
496
} ;
443
497
let clock = Arc :: clone ( & primary. clock ) ;
444
498
node. record_lazy_child ( "current" , move || {
@@ -513,6 +567,11 @@ impl Diagnostics for InspectDiagnostics {
513
567
Event :: UpdateClock { track, reason } => {
514
568
self . update_track ( track, |tn| tn. update_clock ( Some ( reason) ) ) ;
515
569
}
570
+ Event :: UserAdjustUtc { outcome, offset } => {
571
+ if let Some ( ref mut utc_node) = * self . user_utc_adjustments . lock ( ) {
572
+ utc_node. update_user_adjust_utc ( outcome, offset) ;
573
+ }
574
+ }
516
575
}
517
576
}
518
577
}
@@ -589,7 +648,7 @@ mod tests {
589
648
false => None ,
590
649
} ;
591
650
592
- ( InspectDiagnostics :: new ( inspector. root ( ) , & primary, & monitor) , primary. clock )
651
+ ( InspectDiagnostics :: new ( inspector. root ( ) , & primary, & monitor, false ) , primary. clock )
593
652
}
594
653
595
654
#[ fuchsia:: test]
0 commit comments