From 2024bf9b7c57cbf9c1917fdb33b8537542ef34cc Mon Sep 17 00:00:00 2001 From: Magnus Ahltorp Date: Thu, 19 Nov 2015 17:57:34 +0100 Subject: Better debug messages in permdb --- src/permdb.erl | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/permdb.erl b/src/permdb.erl index 393e6df..6157a60 100644 --- a/src/permdb.erl +++ b/src/permdb.erl @@ -22,7 +22,7 @@ -define(DATAMAGIC, <<16#cb, 16#0e>>). -define(NODESIZE, (?MAGICSIZE+(?ENTRIESPERNODE*?BYTESPERENTRY))). --record(state, {cachename, port, datafile, indexfile, requests}). +-record(state, {cachename, name, port, datafile, indexfile, requests, requestcounter}). getvalue_port_command(Port, Key) -> Port ! {self(), {command, <<0:8, Key/binary>>}}. @@ -118,9 +118,11 @@ init([Name, Filename]) -> DataFile = none,%%openfile(Filename), IndexFile = none,%%openfile(Filename ++ ".idx"), {ok, #state{cachename = Cachename, + name = Name, port = Port, datafile = DataFile, indexfile = IndexFile, + requestcounter = 0, requests = queue:new()}}. init_module() -> @@ -139,7 +141,7 @@ handle_cast(_Request, State) -> handle_info({Port, {data, Data}}, State) when is_port(Port) -> lager:debug("response: ~p", [Data]), {{value, {From, Action}}, Requests} = queue:out(State#state.requests), - lager:debug("response: ~p", [Action]), + lager:debug("response ~p ~p: ~p", [State#state.name, State#state.requestcounter, Action]), gen_server:reply(From, case Action of getvalue -> case Data of @@ -172,14 +174,15 @@ terminate(_Reason, State) -> add_request(State, From, Action) -> State#state{ - requests = queue:in({From, Action}, State#state.requests) + requests = queue:in({From, Action}, State#state.requests), + requestcounter = State#state.requestcounter + 1 }. handle_call(stop, _From, State) -> {stop, normal, stopped, State}; handle_call({getvalue, Key}, From, State) -> - lager:debug("getvalue: ~p", [Key]), + lager:debug("getvalue ~p ~p: ~p", [State#state.name, State#state.requestcounter, Key]), Method = port, case Method of port -> @@ -191,11 +194,11 @@ handle_call({getvalue, Key}, From, State) -> end; handle_call({addvalue, Key, Value}, From, State) -> - lager:debug("addvalue: ~p ~p", [Key, Value]), + lager:debug("addvalue ~p ~p: ~p ~p", [State#state.name, State#state.requestcounter, Key, Value]), addvalue_port_command(State#state.port, Key, Value), {noreply, add_request(State, From, addvalue)}; handle_call({commit}, From, State) -> - lager:debug("commit", []), + lager:debug("commit ~p ~p", [State#state.name, State#state.requestcounter]), commit_port_command(State#state.port), {noreply, add_request(State, From, commit)}. -- cgit v1.1