aboutsummaryrefslogtreecommitdiffstats
path: root/lib/dialyzer/src/dialyzer_timing.erl
diff options
context:
space:
mode:
authorStavros Aronis <[email protected]>2012-02-20 13:56:25 +0100
committerHenrik Nord <[email protected]>2012-05-21 15:31:19 +0200
commit60e682897f98d9374b96c6324759f302170b2a17 (patch)
treee6ccf2de74f0c77e118a58b40135b194d95d9999 /lib/dialyzer/src/dialyzer_timing.erl
parentc8f8c90f908ae06a3b2114b77447699b7d690496 (diff)
downloadotp-60e682897f98d9374b96c6324759f302170b2a17.tar.gz
otp-60e682897f98d9374b96c6324759f302170b2a17.tar.bz2
otp-60e682897f98d9374b96c6324759f302170b2a17.zip
Add --time option to Dialyzer
Diffstat (limited to 'lib/dialyzer/src/dialyzer_timing.erl')
-rw-r--r--lib/dialyzer/src/dialyzer_timing.erl88
1 files changed, 88 insertions, 0 deletions
diff --git a/lib/dialyzer/src/dialyzer_timing.erl b/lib/dialyzer/src/dialyzer_timing.erl
new file mode 100644
index 0000000000..73dbbf5a34
--- /dev/null
+++ b/lib/dialyzer/src/dialyzer_timing.erl
@@ -0,0 +1,88 @@
+%% -*- erlang-indent-level: 2 -*-
+%%-------------------------------------------------------------------
+%% %CopyrightBegin%
+%%
+%% Copyright Ericsson AB 2006-2012. All Rights Reserved.
+%%
+%% The contents of this file are subject to the Erlang Public License,
+%% Version 1.1, (the "License"); you may not use this file except in
+%% compliance with the License. You should have received a copy of the
+%% Erlang Public License along with this software. If not, it can be
+%% retrieved online at http://www.erlang.org/.
+%%
+%% Software distributed under the License is distributed on an "AS IS"
+%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
+%% the License for the specific language governing rights and limitations
+%% under the License.
+%%
+%% %CopyrightEnd%
+%%
+
+%%%-------------------------------------------------------------------
+%%% File : dialyzer_timing.erl
+%%% Authors : Stavros Aronis <[email protected]>
+%%% Description : Timing reports for Dialyzer
+%%%-------------------------------------------------------------------
+
+-module(dialyzer_timing).
+
+-export([init/1, start_stamp/1, end_stamp/0, stop/0]).
+
+-spec init(boolean()) -> ok.
+
+init(Active) ->
+ Pid = spawn(fun() -> loop_init(Active) end),
+ case whereis(?MODULE) of
+ undefined -> ok;
+ _ -> unregister(?MODULE)
+ end,
+ register(?MODULE, Pid),
+ ok.
+
+loop_init(Active) ->
+ case Active of
+ true ->
+ io:format("\n"),
+ loop(now());
+ false -> dummy_loop()
+ end.
+
+dummy_loop() ->
+ receive
+ {Pid, stop, _Now} -> Pid ! ok;
+ _ -> dummy_loop()
+ end.
+
+loop(LastNow) ->
+ receive
+ {stamp, Msg, Now} ->
+ io:format("~s\t(+~6.2fs): ", [Msg, diff(Now, LastNow)]),
+ loop(Now);
+ {stamp, Now} ->
+ io:format("~6.2fs\n", [diff(Now, LastNow)]),
+ loop(Now);
+ {Pid, stop, Now} ->
+ io:format("\t(+~6.2fs)\n", [diff(Now, LastNow)]),
+ Pid ! ok
+ end.
+
+-spec start_stamp(string()) -> ok.
+
+start_stamp(Msg) ->
+ ?MODULE ! {stamp, Msg, now()},
+ ok.
+
+-spec end_stamp() -> ok.
+
+end_stamp() ->
+ ?MODULE ! {stamp, now()},
+ ok.
+
+-spec stop() -> ok.
+
+stop() ->
+ ?MODULE ! {self(), stop, now()},
+ receive ok -> ok end.
+
+diff(T2, T1) ->
+ timer:now_diff(T2,T1) / 1000000.