MCPcopy Create free account
hub / github.com/facebook/time / doWork

Method doWork

fbclock/daemon/daemon.go:395–443  ·  view source on GitHub ↗
(shm *fbclock.Shm, data *DataPoint)

Source from the content-addressed store, hash-verified

393 SmearingEndS: clockSmearing.smearingEndS,
394 UTCOffsetPreS: clockSmearing.utcOffsetPreS,
395 UTCOffsetPostS: clockSmearing.utcOffsetPostS,
396 }, nil
397}
398
399func (s *Daemon) doWork(shm *fbclock.Shm, data *DataPoint) error {
400 // push stats
401 s.stats.SetCounter("master_offset_ns", int64(data.MasterOffsetNS))
402 s.stats.SetCounter("path_delay_ns", int64(data.PathDelayNS))
403 s.stats.SetCounter("ingress_time_ns", data.IngressTimeNS)
404 s.stats.SetCounter("freq_adj_ppb", int64(data.FreqAdjustmentPPB))
405 s.stats.SetCounter("clock_accuracy_ns", int64(data.ClockAccuracyNS))
406 // try and calculate how long ago was the ingress time
407 // use clock_gettime as the fastest and widely available method
408 phcTime, err := s.getPHCTime()
409 if err != nil {
410 return fmt.Errorf("failed to get PHC time from %s: %w", s.cfg.Iface, errors.Join(errNoPHC, err))
411 }
412
413 if data.IngressTimeNS > 0 {
414 s.state.updateIngressTimeNS(data.IngressTimeNS)
415 }
416 it := s.state.ingressTimeNS()
417 if it > 0 {
418 timeSinceIngress := phcTime.UnixNano() - it
419 log.Debugf("Time since ingress: %dns", timeSinceIngress)
420 } else {
421 log.Warning("No data for time since ingress")
422 }
423 // read tzdata for leap seconds
424 leaps, err := leapSeconds()
425 if err != nil {
426 log.Warningf("Failed to get leap seconds: %v", err)
427 }
428 // store everything in shared memory
429 d, err := s.calculateSHMData(data, leaps)
430 if err != nil {
431 if errors.Is(err, errNotEnoughData) {
432 log.Warning(err)
433 return nil
434 }
435 return err
436 }
437 s.state.lastStoredData = d
438 if err := fbclock.StoreFBClockDataV1(shm.File.Fd(), *d); err != nil {
439 return err
440 }
441 // aggregated stats over 1 minute
442 maxDp := s.state.aggregateDataPointsMax(minRingSize(s.cfg.RingSize, s.cfg.Interval))
443 s.stats.SetCounter("master_offset_ns.60.abs_max", int64(maxDp.MasterOffsetNS))
444 s.stats.SetCounter("path_delay_ns.60.abs_max", int64(maxDp.PathDelayNS))
445 s.stats.SetCounter("freq_adj_ppb.60.abs_max", int64(maxDp.FreqAdjustmentPPB))
446 return nil

Callers 3

RunMethod · 0.95
TestDaemonDoWorkFunction · 0.80
TestNoPHCFunction · 0.80

Calls 9

calculateSHMDataMethod · 0.95
StoreFBClockDataV1Function · 0.92
leapSecondsFunction · 0.85
minRingSizeFunction · 0.85
updateIngressTimeNSMethod · 0.80
ingressTimeNSMethod · 0.80
SetCounterMethod · 0.65
FdMethod · 0.65

Tested by 2

TestDaemonDoWorkFunction · 0.64
TestNoPHCFunction · 0.64