summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon MacMullen <simon@rabbitmq.com>2014-11-06 12:49:44 +0000
committerSimon MacMullen <simon@rabbitmq.com>2014-11-06 12:49:44 +0000
commit28274a6f2ed0a6b0a26e9ea0a80ef3a16e98274b (patch)
tree6516728b4852ea0dbb0203c27bac4ba5af10c20f
parentc8c5c1504d8b39ceb956adf07f1cbba1147e6990 (diff)
downloadrabbitmq-server-28274a6f2ed0a6b0a26e9ea0a80ef3a16e98274b.tar.gz
Forgot to add that...
-rw-r--r--src/file_handle_cache_stats.erl53
1 files changed, 53 insertions, 0 deletions
diff --git a/src/file_handle_cache_stats.erl b/src/file_handle_cache_stats.erl
new file mode 100644
index 00000000..c8af20a2
--- /dev/null
+++ b/src/file_handle_cache_stats.erl
@@ -0,0 +1,53 @@
+%% The contents of this file are subject to the Mozilla Public License
+%% Version 1.1 (the "License"); you may not use this file except in
+%% compliance with the License. You may obtain a copy of the License
+%% at http://www.mozilla.org/MPL/
+%%
+%% 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.
+%%
+%% The Original Code is RabbitMQ.
+%%
+%% The Initial Developer of the Original Code is GoPivotal, Inc.
+%% Copyright (c) 2007-2014 GoPivotal, Inc. All rights reserved.
+%%
+
+-module(file_handle_cache_stats).
+
+%% stats about read / write operations that go through the fhc.
+
+-export([init/0, update/3, update/2, get/0]).
+
+-define(TABLE, ?MODULE).
+-define(MICRO_TO_MILLI, 1000).
+
+init() ->
+ ets:new(?TABLE, [public, named_table]),
+ [ets:insert(?TABLE, {{Op, Counter}, 0}) || Op <- [read, write],
+ Counter <- [count, bytes, time]],
+ [ets:insert(?TABLE, {{Op, Counter}, 0}) || Op <- [sync],
+ Counter <- [count, time]].
+
+update(Op, Bytes, Thunk) ->
+ {Time, Res} = timer:tc(Thunk),
+ ets:update_counter(?TABLE, {Op, count}, 1),
+ ets:update_counter(?TABLE, {Op, bytes}, Bytes),
+ ets:update_counter(?TABLE, {Op, time}, Time),
+ Res.
+
+update(Op, Thunk) ->
+ {Time, Res} = timer:tc(Thunk),
+ ets:update_counter(?TABLE, {Op, count}, 1),
+ ets:update_counter(?TABLE, {Op, time}, Time),
+ Res.
+
+get() ->
+ lists:sort([output(K, V) || {K, V} <- ets:tab2list(?TABLE)]).
+
+output({Op, time}, Val) -> {flatten_key(Op, time), Val / ?MICRO_TO_MILLI};
+output({Op, Ctr}, Val) -> {flatten_key(Op, Ctr), Val}.
+
+flatten_key(A, B) ->
+ list_to_atom("fhc_" ++ atom_to_list(A) ++ "_" ++ atom_to_list(B)).