4
%% Copyright Ericsson AB 2007-2009. All Rights Reserved.
4
%% Copyright Ericsson AB 2007-2010. All Rights Reserved.
6
6
%% The contents of this file are subject to the Erlang Public License,
7
7
%% Version 1.1, (the "License"); you may not use this file except in
8
8
%% compliance with the License. You should have received a copy of the
9
9
%% Erlang Public License along with this software. If not, it can be
10
10
%% retrieved online at http://www.erlang.org/.
12
12
%% Software distributed under the License is distributed on an "AS IS"
13
13
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
14
14
%% the License for the specific language governing rights and limitations
15
15
%% under the License.
73
73
%% @doc Starts or restarts the percept database.
75
-spec(start/0 :: () -> {'started', pid()} | {'restarted', pid()}).
75
-spec start() -> {'started', pid()} | {'restarted', pid()}.
78
78
case erlang:whereis(percept_db) of
80
Pid = spawn( fun() -> init_percept_db() end),
81
erlang:register(percept_db, Pid),
80
{started, do_start()};
84
erlang:unregister(percept_db),
85
PerceptDB ! {action, stop},
86
Pid = spawn( fun() -> init_percept_db() end),
87
erlang:register(percept_db, Pid),
82
{restarted, restart(PerceptDB)}
85
%% @spec restart(pid()) -> pid()
87
%% @doc restarts the percept database.
89
-spec restart(pid())-> pid().
95
%% @spec do_start(pid()) -> pid()
97
%% @doc starts the percept database.
99
-spec do_start()-> pid().
102
Pid = spawn( fun() -> init_percept_db() end),
103
erlang:register(percept_db, Pid),
91
106
%% @spec stop() -> not_started | {stopped, Pid}
93
108
%% @doc Stops the percept database.
95
-spec(stop/0 :: () -> 'not_started' | {'stopped', pid()}).
110
-spec stop() -> 'not_started' | {'stopped', pid()}.
98
113
case erlang:whereis(percept_db) of
121
%% @spec stop_sync(pid()) -> true
123
%% @doc Stops the percept database, with a synchronous call.
125
-spec stop_sync(pid())-> true.
128
MonitorRef = erlang:monitor(process, Pid),
131
{'DOWN', MonitorRef, _Type, Pid, _Info}->
133
after ?STOP_TIMEOUT->
106
137
%% @spec insert(tuple()) -> ok
107
138
%% @doc Inserts a trace or profile message to the database.
392
423
consolidate_runnability_loop(ets:next(pdb_activity, Key)).
395
ATs = [ Act#activity.timestamp ||
396
Act <- select_query({activity, []})],
397
STs = [ Act#activity.timestamp ||
398
Act <- select_query({scheduler, []})],
426
ATs = [Act#activity.timestamp || Act <- select_query({activity, []})],
427
STs = [Act#activity.timestamp || Act <- select_query({scheduler, []})],
399
428
ITs = lists:flatten([
400
429
[I#information.start,
401
430
I#information.stop] ||
402
431
I <- select_query({information, all})]),
403
% Filter out all undefined (non ts)
404
TsList = lists:filter(
410
end, ATs ++ STs ++ ITs),
432
%% Filter out all undefined (non ts)
433
[Elem || Elem = {_,_,_} <- ATs ++ STs ++ ITs].
413
435
%% get_runnable_count(Type, State) -> RunnableCount