Skip to content

Commit f50dea8

Browse files
Merge pull request #10994 from rabbitmq/mergify/bp/v3.13.x/pr-10928
Prefer `erlang:monotonic_time/0` for elapsed time measurements (backport #10928)
2 parents bac6591 + 8ca49c0 commit f50dea8

File tree

5 files changed

+19
-18
lines changed

5 files changed

+19
-18
lines changed

deps/rabbit/src/rabbit_boot_steps.erl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ find_steps() ->
3434
find_steps(loaded_applications()).
3535

3636
find_steps(Apps) ->
37-
T0 = erlang:timestamp(),
37+
T0 = erlang:monotonic_time(),
3838
AttrsPerApp = rabbit_misc:rabbitmq_related_module_attributes(rabbit_boot_step),
39-
T1 = erlang:timestamp(),
39+
T1 = erlang:monotonic_time(),
4040
?LOG_DEBUG(
4141
"Boot steps: time to find boot steps: ~tp us",
42-
[timer:now_diff(T1, T0)],
42+
[erlang:convert_time_unit(T1 - T0, native, microsecond)],
4343
#{domain => ?RMQLOG_DOMAIN_GLOBAL}),
4444
All = sort_boot_steps(AttrsPerApp),
4545
[Step || {App, _, _} = Step <- All, lists:member(App, Apps)].

deps/rabbit/src/rabbit_deprecated_features.erl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -589,12 +589,12 @@ maybe_log_warning(FeatureName, Permitted) ->
589589

590590
should_log_warning(FeatureName) ->
591591
Key = ?PT_DEPRECATION_WARNING_TS(FeatureName),
592-
Now = erlang:timestamp(),
592+
Now = erlang:monotonic_time(),
593593
try
594594
Last = persistent_term:get(Key),
595-
Diff = timer:now_diff(Now, Last),
595+
Diff = erlang:convert_time_unit(Now - Last, native, second),
596596
if
597-
Diff >= 24 * 60 * 60 * 1000 * 1000 ->
597+
Diff >= 24 * 60 * 60 ->
598598
persistent_term:put(Key, Now),
599599
true;
600600
true ->

deps/rabbit/src/rabbit_feature_flags.erl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -830,7 +830,7 @@ query_supported_feature_flags() ->
830830
?LOG_DEBUG(
831831
"Feature flags: query feature flags in loaded applications",
832832
#{domain => ?RMQLOG_DOMAIN_FEAT_FLAGS}),
833-
T0 = erlang:timestamp(),
833+
T0 = erlang:monotonic_time(),
834834
%% We need to know the list of applications we scanned for feature flags.
835835
%% We can't derive that list of the returned feature flags because an
836836
%% application might be loaded/present and not have a specific feature
@@ -842,11 +842,11 @@ query_supported_feature_flags() ->
842842
rabbit_deprecated_feature, ScannedApps),
843843
AttrsFromTestsuite = module_attributes_from_testsuite(),
844844
TestsuiteProviders = [App || {App, _, _} <- AttrsFromTestsuite],
845-
T1 = erlang:timestamp(),
845+
T1 = erlang:monotonic_time(),
846846
?LOG_DEBUG(
847847
"Feature flags: time to find supported feature flags and deprecated "
848848
"features: ~tp us",
849-
[timer:now_diff(T1, T0)],
849+
[erlang:convert_time_unit(T1 - T0, native, microsecond)],
850850
#{domain => ?RMQLOG_DOMAIN_FEAT_FLAGS}),
851851
AllAttributes = AttrsPerAppA ++ AttrsPerAppB ++ AttrsFromTestsuite,
852852
AllApps = lists:usort(ScannedApps ++ TestsuiteProviders),

deps/rabbit/src/rabbit_ff_registry_factory.erl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -341,16 +341,16 @@ maybe_initialize_registry(NewSupportedFeatureFlags,
341341
"Feature flags: (re)initialize registry (~tp)",
342342
[self()],
343343
#{domain => ?RMQLOG_DOMAIN_FEAT_FLAGS}),
344-
T0 = erlang:timestamp(),
344+
T0 = erlang:monotonic_time(),
345345
Ret = do_initialize_registry(RegistryVsn,
346346
AllFeatureFlags,
347347
FeatureStates,
348348
Inventory,
349349
WrittenToDisk),
350-
T1 = erlang:timestamp(),
350+
T1 = erlang:monotonic_time(),
351351
?LOG_DEBUG(
352352
"Feature flags: time to regen registry: ~tp us",
353-
[timer:now_diff(T1, T0)],
353+
[erlang:convert_time_unit(T1 - T0, native, microsecond)],
354354
#{domain => ?RMQLOG_DOMAIN_FEAT_FLAGS}),
355355
Ret;
356356
false ->

deps/rabbitmq_ct_helpers/src/rabbit_ct_broker_helpers.erl

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -878,21 +878,22 @@ cluster_nodes1(_, _, _, []) ->
878878
ok.
879879

880880
handle_nodes_in_parallel(NodeConfigs, Fun) ->
881-
T0 = erlang:timestamp(),
881+
T0 = erlang:monotonic_time(),
882882
Parent = self(),
883883
Procs = [
884884
begin
885885
timer:sleep(rand:uniform(1000)),
886886
spawn_link(fun() ->
887-
T1 = erlang:timestamp(),
887+
T1 = erlang:monotonic_time(),
888888
Ret = Fun(NodeConfig),
889-
T2 = erlang:timestamp(),
889+
T2 = erlang:monotonic_time(),
890890
ct:pal(
891891
?LOW_IMPORTANCE,
892892
"Time to run ~tp for node ~ts: ~b us",
893893
[Fun,
894894
?config(nodename, NodeConfig),
895-
timer:now_diff(T2, T1)]),
895+
erlang:convert_time_unit(
896+
T2 - T1, native, microsecond)]),
896897
Parent ! {parallel_handling_ret,
897898
self(),
898899
NodeConfig,
@@ -903,11 +904,11 @@ handle_nodes_in_parallel(NodeConfigs, Fun) ->
903904
wait_for_node_handling(Procs, Fun, T0, []).
904905

905906
wait_for_node_handling([], Fun, T0, Results) ->
906-
T3 = erlang:timestamp(),
907+
T3 = erlang:monotonic_time(),
907908
ct:pal(
908909
?LOW_IMPORTANCE,
909910
"Time to run ~tp for all nodes: ~b us",
910-
[Fun, timer:now_diff(T3, T0)]),
911+
[Fun, erlang:convert_time_unit(T3 - T0, native, microsecond)]),
911912
Results;
912913
wait_for_node_handling(Procs, Fun, T0, Results) ->
913914
receive

0 commit comments

Comments
 (0)