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

Method calcW

fbclock/daemon/daemon.go:273–332  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

271 s.stats.SetCounter("master_offset_ns.60.abs_max", 0)
272 s.stats.SetCounter("path_delay_ns.60.abs_max", 0)
273 s.stats.SetCounter("freq_adj_ppb.60.abs_max", 0)
274 return s, nil
275}
276
277func (s *Daemon) calcW() (float64, error) {
278 lastN := s.state.takeDataPoint(s.cfg.RingSize)
279 params := prepareMathParameters(lastN)
280 logSample := &LogSample{
281 MasterOffsetNS: params["offset"][0],
282 MasterOffsetMeanNS: mean(params["offset"]),
283 MasterOffsetStddevNS: stddev(params["offset"]),
284 PathDelayNS: params["delay"][0],
285 PathDelayMeanNS: mean(params["delay"]),
286 PathDelayStddevNS: stddev(params["delay"]),
287 FreqAdjustmentPPB: params["freq"][0],
288 FreqAdjustmentMeanPPB: mean(params["freq"]),
289 FreqAdjustmentStddevPPB: stddev(params["freq"]),
290 ClockAccuracyMean: mean(params["clockaccuracy"]),
291 }
292 mRaw, err := s.cfg.Math.mExpr.Evaluate(mapOfInterface(params))
293 if err != nil {
294 return 0, err
295 }
296 m := mRaw.(float64)
297 logSample.MeasurementNS = m
298 s.stats.SetCounter("m_ns", int64(m))
299
300 // push m to ring buffer
301 s.state.pushM(m)
302
303 ms := s.state.takeM(s.cfg.RingSize)
304 minN := s.cfg.RingSize
305 if s.cfg.GradualWindow {
306 // Publish from n=2 (skip n=1: stddev is 0). len(ms) <= RingSize, so flag-off keeps today's gate.
307 minN = 2
308 }
309 if len(ms) < minN {
310 return 0, fmt.Errorf("%w getting W: want >= %d, got %d", errNotEnoughData, minN, len(ms))
311 }
312
313 n := len(ms)
314 // k is the precomputed factor for this sample count: coverageZP (4.0) at the full ring, so steady
315 // state and the flag-off path stay byte-identical. n and k are always injected; govaluate ignores
316 // vars a formula does not reference.
317 parameters := map[string]any{
318 "m": ms,
319 "n": float64(n),
320 "k": s.cfg.gradualFactor(n),
321 }
322 logSample.MeasurementMeanNS = mean(ms)
323 logSample.MeasurementStddevNS = stddev(ms)
324
325 wRaw, err := s.cfg.Math.wExpr.Evaluate(parameters)
326 if err != nil {
327 return 0, err
328 }
329 w := wRaw.(float64)
330 logSample.WindowNS = w

Callers 1

calculateSHMDataMethod · 0.95

Calls 10

prepareMathParametersFunction · 0.85
mapOfInterfaceFunction · 0.85
takeDataPointMethod · 0.80
pushMMethod · 0.80
takeMMethod · 0.80
gradualFactorMethod · 0.80
meanFunction · 0.70
stddevFunction · 0.70
SetCounterMethod · 0.65
LogMethod · 0.65

Tested by

no test coverage detected