diff options
author | Magnus Ahltorp <map@kth.se> | 2015-11-19 17:57:34 +0100 |
---|---|---|
committer | Linus Nordberg <linus@nordu.net> | 2015-12-09 14:46:37 +0100 |
commit | 2024bf9b7c57cbf9c1917fdb33b8537542ef34cc (patch) | |
tree | 6f6bce1a85accbe03217509647c821e0301661c6 | |
parent | fb78a6a883ad7b45c7a0dc8dc550469eaff1e1a0 (diff) |
Better debug messages in permdb
-rw-r--r-- | src/permdb.erl | 15 |
1 files changed, 9 insertions, 6 deletions
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)}. |