[erlang-questions] how can I access test_server_loc in the process dict of another process?

Steve Kirsch steve.kirsch@REDACTED
Thu Apr 30 09:17:57 CEST 2009


I wrote a simple statistical profiler that basically snapshots a spawned
MFA every 10 msec for 100 samples using process_info(Pid,
current_function)

that's pretty cool.

But way cooler is to include:

-compile({parse_transform,ct_line}). 

in the module I want to statistically profile.

This essentially pushes your M, F, line number in the process dictionary
(under key test_server_loc) each time you execute a line of code
(replacing it if in the same function so you get a call stack more or
less to a max depth of 10).

That's way cool.

So I'd like to access that key (test_server_loc) from my statistical
profiler which is running in another process.

How can I access that key? there isn't a get(test_server_loc, Pid) BIF.



=====================================
P.S. Here's my statistical profiler and test function... this all works
fine. 

% statistical profiler. Spawns the MFA and then takes 100 samples, 10
msec apart.
sprof(M, F, A)->
    Pid=spawn_link(M,F,A),
    Time=10,
    L=lists:seq(1,100),
    GetCurrentMFA=fun()->
			  timer:sleep(Time),
			  case process_info(Pid, current_function) of
			      {_, MFA}->MFA;
			      undefined -> x
			  end
			  end,
    OutList=[GetCurrentMFA()||_X<-L],
    io:format("~p~n", [OutList]).

t1()->
    ok.
t2()->
    bye.
t3()->
    fooey.

sprof_test(0)->
    ok;	
sprof_test(N)->
    t1(),
    t2(),
    t3(),
    sprof_test(N-1).
sprof_test()->    
    sprof(?MODULE, sprof_test, [100000000]).



More information about the erlang-questions mailing list