Skip to content

Instantly share code, notes, and snippets.

@cstar
Created May 28, 2013 10:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cstar/5661909 to your computer and use it in GitHub Desktop.
Save cstar/5661909 to your computer and use it in GitHub Desktop.
Traces queries to mysql and pgsql
-module (boss_tracer).
-behaviour (gen_server).
-export([start/0]).
%% gen_server callbacks
-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
terminate/2, code_change/3]).
-define(SERVER, ?MODULE).
start()->
gen_server:start({local, ?SERVER}, ?MODULE, [], []).
init([])->
Tracer = erlang:trace(all, true, [call]),
erlang:trace_pattern({pgsql, equery, '_'}, true, [local]),
erlang:trace_pattern({mysql_conn, fetch, '_'}, true, [local]),
error_logger:info_msg("Started ~p~n", [Tracer]),
{ok, ""}.
handle_call(Msg, _From, State)->
{reply, ok, State}.
handle_cast(Msg, State) ->
{noreply, State}.
handle_info({trace_ts, Pid, call, {M, F, [Conn, Query, Params]}, Time}, State) ->
error_logger:info_msg("~s params: ~p", [Query, Params]),
{noreply, State};
handle_info(Msg, State) ->
{noreply, State}.
terminate(_Reason, _State)->
ok.
code_change(_OldVsn, State, _Extra) ->
{ok, State}.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment