Skip to content

Instantly share code, notes, and snippets.

@kellymclaughlin
Created March 12, 2014 16:10
Show Gist options
  • Save kellymclaughlin/9510156 to your computer and use it in GitHub Desktop.
Save kellymclaughlin/9510156 to your computer and use it in GitHub Desktop.
-module(cs_manifest_siblings).
-compile(export_all).
start() ->
start(1).
%% @doc Trace to determine the number of siblings of Riak CS manifest
%% objects. The `Threshold' parameter is used to limit the output to
%% manifest objects whose sibling count is >= to `Threshold'.
start(Threshold) ->
dbg:tracer(process, {fun trace/2, {orddict:new(), {threshold, Threshold}}}),
dbg:p(all, call),
dbg:tpl(riak_cs_utils, get_manifests, 3, [{'_', [], [{return_trace}]}]).
stop() -> dbg:stop_clear().
trace({trace, Pid, call, {riak_cs_utils, get_manifests, [_, Bucket, Key]}},
{D, Threshold}) ->
D2 = orddict:store({Pid, riak_cs_utils, get_manifests}, {Bucket, Key}, D),
{D2, Threshold};
trace({trace, Pid, return_from, {riak_cs_utils, get_manifests, _}, Result}, Acc={D, {threshold, Threshold}}) ->
case orddict:find({Pid, riak_cs_utils, get_manifests}, D) of
{ok, {Bucket, Key}} ->
case Result of
{ok, RiakObj, _} ->
ValueCount = riakc_obj:value_count(RiakObj),
case ValueCount >= Threshold of
true ->
lager:log(info, Pid, "The manifest object for ~p:~p has ~p siblings\n",
[Bucket, Key, ValueCount]);
false ->
ok
end;
_ ->
ok
end,
D2 = orddict:erase(Key, D),
{D2, {threshold, Threshold}};
error -> Acc
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment