The post has been translated automatically. Original language: Russian
A support ticket asks whether an export met a three-second target. The stored duration is negative. Before closing the ticket, reproduce how the timer was measured.
A teaching example uses one process. Its wall clock reads 14:00:10 at the start. The clock moves back five seconds during the job. Two real seconds after the start it reads 14:00:07. Subtracting the timestamps gives −3 seconds. Clamping the result to zero would label a two-second job instantaneous.
Take a second pair of readings. Suppose a monotonic timer reads 500.00 s at the start and 502.00 s at the end. The difference is 2.00 s. In Python, take two time.monotonic_ns() readings, store the difference in nanoseconds and convert at display time. Keep the wall-clock timestamp for finding the event.
Report line: “Start 14:00:10, end 14:00:07, elapsed 2.00 s, wall-clock correction observed.” Inject a fake clock for the test so the server clock can stay untouched. Do not subtract monotonic readings taken on different machines.
Учебный протокол одного процесса. На старте настенные часы показали 14:00:10. Во время операции их перевели на пять секунд назад. Работа завершилась через две реальные секунды, и в журнал попало 14:00:07. Вычитание меток дало −3 секунды. Замена минуса нулём сделала бы медленную операцию мгновенной.
Снимем вторую пару показаний. Пусть монотонный таймер показал в начале 500,00 с, а в конце 502,00 с. Разность равна 2,00 с. В Python для этого подходит time.monotonic_ns(): сохраняем разность в наносекундах и переводим в секунды при выводе. Календарную метку оставляем для поиска события.
Строка протокола: «Старт 14:00:10, конец 14:00:07, длительность 2,00 с, обнаружена коррекция часов». Проверка на стенде: подменить источник времени в тесте, не переводя часы сервера. Показания монотонных часов разных машин напрямую не вычитать.
Comments 0
Newest Popular