-
-
Save jtuple/244c578773962077e215 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-module(trace_large4). | |
-compile(export_all). | |
-record(r_object, {bucket = '_', | |
key = '_', | |
contents = '_', | |
vclock = '_', | |
updatemetadata = '_', | |
updatevalue = '_' | |
}). | |
go(Time, Count, Size) -> | |
ss(), | |
%% gets | |
GetMS = [{['_', | |
#r_object{bucket='$1', | |
key='$2'}], | |
[], | |
[{message,{{'$1','$2'}}}, {return_trace}]}], | |
erlang:trace_pattern({riak_kv_get_fsm, calculate_objsize, 2}, GetMS, [local]), | |
%% puts | |
PutMS = [{['$1','$2','_','$3','_'], | |
[{'>',{size,'$3'},Size}], | |
[{message,{{'$1','$2',{size,'$3'}}}}]}], | |
erlang:trace_pattern({riak_kv_eleveldb_backend, put, 5}, PutMS, [local]), | |
erlang:trace_pattern({riak_kv_bitcask_backend, put, 5}, PutMS, [local]), | |
erlang:trace_pattern({riak_kv_memory_backend, put, 5}, PutMS, [local]), | |
{Tracer, _} = spawn_monitor(?MODULE, tracer, [0, Count, Size, dict:new()]), | |
erlang:trace(all, true, [call, arity, {tracer, Tracer}]), | |
receive | |
{'DOWN', _, process, Tracer, _} -> | |
ok | |
after Time -> | |
exit(Tracer, kill), | |
receive | |
{'DOWN', _, process, Tracer, _} -> | |
ok | |
end | |
end, | |
ss(), | |
io:format("object trace stopped~n"). | |
tracer(Limit, Limit, _, _) -> | |
ok; | |
tracer(Count, Limit, Threshold, Objs) -> | |
receive | |
{trace,Pid,call,{riak_kv_get_fsm,calculate_objsize,2},{Bucket,Key}} -> | |
Objs2 = dict:store(Pid, {Bucket,Key}, Objs), | |
tracer(Count+1, Limit, Threshold, Objs2); | |
{trace,Pid,return_from,{riak_kv_get_fsm,calculate_objsize,2},Size} -> | |
case Size >= Threshold of | |
true -> | |
case dict:find(Pid, Objs) of | |
{ok, {Bucket, Key}} -> | |
io:format("~p: get: ~p~n", [ts(), {Bucket, Key, Size}]); | |
_ -> | |
ok | |
end; | |
false -> | |
ok | |
end, | |
Objs2 = dict:erase(Pid, Objs), | |
tracer(Count+1, Limit, Threshold, Objs2); | |
{trace,_Pid,call,{riak_kv_eleveldb_backend,put,5},{Bucket,Key,Size}} -> | |
io:format("~p: put(l): ~p~n", [ts(), {Bucket, Key, Size}]), | |
tracer(Count+1, Limit, Threshold, Objs); | |
{trace,_Pid,call,{riak_kv_bitcask_backend,put,5},{Bucket,Key,Size}} -> | |
io:format("~p: put(b): ~p~n", [ts(), {Bucket, Key, Size}]), | |
tracer(Count+1, Limit, Threshold, Objs); | |
{trace,_Pid,call,{riak_kv_memory_backend,put,5},{Bucket,Key,Size}} -> | |
io:format("~p: put(m): ~p~n", [ts(), {Bucket, Key, Size}]), | |
tracer(Count+1, Limit, Threshold, Objs); | |
Msg -> | |
io:format("tracer: ~p~n", [Msg]), | |
tracer(Count+1, Limit, Threshold, Objs) | |
end. | |
ts() -> | |
calendar:now_to_datetime(os:timestamp()). | |
ss() -> | |
erlang:trace_pattern({'_','_','_'}, false, [local]), | |
erlang:trace(all, false, [call, arity]). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment