Skip to content

Commit

Permalink
Expose size and memory used of a table
Browse files Browse the repository at this point in the history
At the moment, the only way to do that via the API is to retrieve all
the entries and then call `length/1` or count the memory usage manually.
This should help speed things up when tables are particularly large.
  • Loading branch information
AntoineGagne committed Apr 5, 2024
1 parent c7e08cc commit 60debbe
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/rig.erl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

-export([
all/1,
info/1,
lock/1, lock_t/1,
unlock/1, locks/0,
read/2, read/3,
Expand Down Expand Up @@ -37,6 +38,16 @@ all(Table) ->
{error, unknown_table}
end.

info(Table) ->
try
Tid = tid(Table),
Information = ets:info(Tid),
maps:with([memory, size], maps:from_list(Information))
catch
_:_ ->
{error, unknown_table}
end.

% lock current version of the table
-spec lock(table()) -> {ok, ets:tid()} | {error, Error :: _}.

Expand Down

0 comments on commit 60debbe

Please sign in to comment.