Merge pull request #5 from ibnfirnas/allow-custom-nodename-in-statsd-consumer
[beam_stats.git] / src / beam_stats_ets_table.erl
... / ...
CommitLineData
1-module(beam_stats_ets_table).
2
3-include("include/beam_stats_ets_table.hrl").
4
5-export_type(
6 [ t/0
7 , id/0
8 ]).
9
10-export(
11 [ of_id/1
12 , id_to_bin/1
13 ]).
14
15-type id() ::
16 atom()
17 | ets:tid()
18 % integer() is just a workaround, to let us mock ets:tid(), which is
19 % opaque, but represented as an integer, without Dialyzer complaining.
20 | integer()
21 .
22
23-type t() ::
24 #?MODULE{}.
25
26-spec of_id(id()) ->
27 t().
28of_id(ID) ->
29 WordSize = erlang:system_info(wordsize),
30 NumberOfWords = ets:info(ID, memory),
31 NumberOfBytes = NumberOfWords * WordSize,
32 #?MODULE
33 { id = ID
34 , name = ets:info(ID, name)
35 , size = ets:info(ID, size)
36 , memory = NumberOfBytes
37 }.
38
39-spec id_to_bin(atom() | ets:tid()) ->
40 binary().
41id_to_bin(ID) when is_atom(ID) ->
42 atom_to_binary(ID, latin1);
43id_to_bin(ID) when is_integer(ID) ->
44 integer_to_binary(ID).
This page took 0.024658 seconds and 4 git commands to generate.