~ubuntu-branches/ubuntu/trusty/erlang/trusty

« back to all changes in this revision

Viewing changes to lib/percept/src/percept_db.erl

  • Committer: Bazaar Package Importer
  • Author(s): Clint Byrum
  • Date: 2011-05-05 15:48:43 UTC
  • mfrom: (3.5.13 sid)
  • Revision ID: james.westby@ubuntu.com-20110505154843-0om6ekzg6m7ugj27
Tags: 1:14.b.2-dfsg-3ubuntu1
* Merge from debian unstable.  Remaining changes:
  - Drop libwxgtk2.8-dev build dependency. Wx isn't in main, and not
    supposed to.
  - Drop erlang-wx binary.
  - Drop erlang-wx dependency from -megaco, -common-test, and -reltool, they
    do not really need wx. Also drop it from -debugger; the GUI needs wx,
    but it apparently has CLI bits as well, and is also needed by -megaco,
    so let's keep the package for now.
  - debian/patches/series: Do what I meant, and enable build-options.patch
    instead.
* Additional changes:
  - Drop erlang-wx from -et
* Dropped Changes:
  - patches/pcre-crash.patch: CVE-2008-2371: outer level option with
    alternatives caused crash. (Applied Upstream)
  - fix for ssl certificate verification in newSSL: 
    ssl_cacertfile_fix.patch (Applied Upstream)
  - debian/patches/series: Enable native.patch again, to get stripped beam
    files and reduce the package size again. (build-options is what
    actually accomplished this)
  - Remove build-options.patch on advice from upstream and because it caused
    odd build failures.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
%% 
2
2
%% %CopyrightBegin%
3
 
%% 
4
 
%% Copyright Ericsson AB 2007-2009. All Rights Reserved.
5
 
%% 
 
3
%%
 
4
%% Copyright Ericsson AB 2007-2010. All Rights Reserved.
 
5
%%
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/.
11
 
%% 
 
11
%%
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.
16
 
%% 
 
16
%%
17
17
%% %CopyrightEnd%
18
18
 
19
19
%% 
33
33
        ]).
34
34
 
35
35
-include("percept.hrl").
36
 
 
 
36
-define(STOP_TIMEOUT, 1000).
37
37
%%==========================================================================
38
38
%%
39
39
%%              Type definitions 
72
72
%%      Pid = pid()
73
73
%% @doc Starts or restarts the percept database.
74
74
 
75
 
-spec(start/0 :: () -> {'started', pid()} | {'restarted', pid()}).
 
75
-spec start() -> {'started', pid()} | {'restarted', pid()}.
76
76
 
77
77
start() ->
78
78
    case erlang:whereis(percept_db) of
79
79
        undefined ->
80
 
            Pid = spawn( fun() -> init_percept_db() end),
81
 
            erlang:register(percept_db, Pid),
82
 
            {started, Pid};
 
80
            {started, do_start()};
83
81
        PerceptDB ->
84
 
            erlang:unregister(percept_db),
85
 
            PerceptDB ! {action, stop},
86
 
            Pid = spawn( fun() -> init_percept_db() end),
87
 
            erlang:register(percept_db, Pid),
88
 
            {restarted, Pid}
 
82
            {restarted, restart(PerceptDB)}
89
83
    end.
90
84
 
 
85
%% @spec restart(pid()) -> pid()
 
86
%% @private
 
87
%% @doc restarts the percept database.
 
88
 
 
89
-spec restart(pid())-> pid().
 
90
 
 
91
restart(PerceptDB)->
 
92
        stop_sync(PerceptDB),
 
93
        do_start().
 
94
 
 
95
%% @spec do_start(pid()) -> pid()
 
96
%% @private
 
97
%% @doc starts the percept database.
 
98
 
 
99
-spec do_start()-> pid().
 
100
 
 
101
do_start()->
 
102
    Pid = spawn( fun() -> init_percept_db() end),
 
103
    erlang:register(percept_db, Pid),
 
104
    Pid.
 
105
 
91
106
%% @spec stop() -> not_started | {stopped, Pid}
92
107
%%      Pid = pid()
93
108
%% @doc Stops the percept database.
94
109
 
95
 
-spec(stop/0 :: () -> 'not_started' | {'stopped', pid()}).
 
110
-spec stop() -> 'not_started' | {'stopped', pid()}.
96
111
 
97
112
stop() ->
98
113
    case erlang:whereis(percept_db) of
103
118
            {stopped, Pid}
104
119
    end.
105
120
 
 
121
%% @spec stop_sync(pid()) -> true
 
122
%% @private
 
123
%% @doc Stops the percept database, with a synchronous call.
 
124
 
 
125
-spec stop_sync(pid())-> true.
 
126
 
 
127
stop_sync(Pid)->
 
128
    MonitorRef = erlang:monitor(process, Pid),
 
129
    stop(),
 
130
    receive
 
131
        {'DOWN', MonitorRef, _Type, Pid, _Info}->
 
132
            true
 
133
    after ?STOP_TIMEOUT->
 
134
            exit(Pid, kill)
 
135
    end.
 
136
 
106
137
%% @spec insert(tuple()) -> ok
107
138
%% @doc Inserts a trace or profile message to the database.  
108
139
 
392
423
    consolidate_runnability_loop(ets:next(pdb_activity, Key)).
393
424
 
394
425
list_all_ts() ->
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(
405
 
        fun(Element) -> 
406
 
            case Element of
407
 
                {_,_,_} -> true;
408
 
                _ -> false
409
 
            end
410
 
        end, ATs ++ STs ++ ITs),
411
 
    TsList.
 
432
    %% Filter out all undefined (non ts)
 
433
    [Elem || Elem = {_,_,_} <- ATs ++ STs ++ ITs].
412
434
 
413
435
%% get_runnable_count(Type, State) -> RunnableCount
414
436
%% In: