diff options
author | Péter Gömöri <[email protected]> | 2013-11-15 21:46:30 +0100 |
---|---|---|
committer | Henrik Nord <[email protected]> | 2014-01-10 11:48:54 +0100 |
commit | 919576189693a5c0968e2ada9eef2ccaa6eb37b6 (patch) | |
tree | fef28cd2ce01a70b4303cc2ccf270ae1ff96a9f6 /lib | |
parent | 039ea3a6ed5dc147478f294910ba042850db2383 (diff) | |
download | otp-919576189693a5c0968e2ada9eef2ccaa6eb37b6.tar.gz otp-919576189693a5c0968e2ada9eef2ccaa6eb37b6.tar.bz2 otp-919576189693a5c0968e2ada9eef2ccaa6eb37b6.zip |
Fix etop trace handler in smp environment
There could be multiple processes scheduled to run
Diffstat (limited to 'lib')
-rw-r--r-- | lib/observer/src/etop_tr.erl | 38 |
1 files changed, 22 insertions, 16 deletions
diff --git a/lib/observer/src/etop_tr.erl b/lib/observer/src/etop_tr.erl index dd326fe639..e6c69e4e1e 100644 --- a/lib/observer/src/etop_tr.erl +++ b/lib/observer/src/etop_tr.erl @@ -59,7 +59,7 @@ reader(Config) -> Port = getopt(port, Config), {ok, Sock} = gen_tcp:connect(Host, Port, [{active, false}]), - spawn_link(fun() -> reader_init(Sock,getopt(store,Config),nopid) end). + spawn_link(fun() -> reader_init(Sock,getopt(store,Config),[]) end). %%%%%%%%%%%%%% Socket reader %%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -73,24 +73,30 @@ reader(Sock, Store, Last) -> New = handle_data(Last, Data, Store), reader(Sock, Store, New). -handle_data(_, {_, Pid, in, _, Time}, _) -> - {Pid,Time}; -handle_data({Pid,Time1}, {_, Pid, out, _, Time2}, Store) -> - Elapsed = elapsed(Time1, Time2), - case ets:member(Store,Pid) of - true -> ets:update_counter(Store, Pid, Elapsed); - false -> ets:insert(Store,{Pid,Elapsed}) - end, - nopid; +handle_data(Last, {_, Pid, in, _, Time}, _) -> + [{Pid,Time}|Last]; +handle_data([], {_, _, out, _, _}, _Store) -> + %% ignore - there was probably just a 'drop' + []; +handle_data(Last, {_, Pid, out, _, Time2} = G, Store) -> + case lists:keytake(Pid, 1, Last) of + {_, {_, Time1}, New} -> + Elapsed = elapsed(Time1, Time2), + case ets:member(Store,Pid) of + true -> ets:update_counter(Store, Pid, Elapsed); + false -> ets:insert(Store,{Pid,Elapsed}) + end, + New; + false -> + io:format("Erlang top got garbage ~p~n", [G]), + Last + end; handle_data(_W, {drop, D}, _) -> %% Error case we are missing data here! io:format("Erlang top dropped data ~p~n", [D]), - nopid; -handle_data(nopid, {_, _, out, _, _}, _Store) -> - %% ignore - there was probably just a 'drop' - nopid; -handle_data(_, G, _) -> + []; +handle_data(Last, G, _) -> io:format("Erlang top got garbage ~p~n", [G]), - nopid. + Last. elapsed({Me1, S1, Mi1}, {Me2, S2, Mi2}) -> Me = (Me2 - Me1) * 1000000, |