Consolidate data source calls in 1, mockable, module.
[beam_stats.git] / src / beam_stats_ets_table.erl
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().
28 of_id(ID) ->
29 WordSize = beam_stats_source:erlang_system_info(wordsize),
30 NumberOfWords = beam_stats_source:ets_info(ID, memory),
31 NumberOfBytes = NumberOfWords * WordSize,
32 #?MODULE
33 { id = ID
34 , name = beam_stats_source:ets_info(ID, name)
35 , size = beam_stats_source:ets_info(ID, size)
36 , memory = NumberOfBytes
37 }.
38
39 -spec id_to_bin(atom() | ets:tid()) ->
40 binary().
41 id_to_bin(ID) when is_atom(ID) ->
42 atom_to_binary(ID, latin1);
43 id_to_bin(ID) when is_integer(ID) ->
44 integer_to_binary(ID).
This page took 0.050618 seconds and 4 git commands to generate.