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

« back to all changes in this revision

Viewing changes to lib/percept/src/percept.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
 
50
50
 
51
51
%% @type percept_option() = procs | ports | exclusive
52
52
 
53
 
-type(percept_option() :: 'procs' | 'ports' | 'exclusive' | 'scheduler').
 
53
-type percept_option() :: 'procs' | 'ports' | 'exclusive' | 'scheduler'.
54
54
 
55
55
%%==========================================================================
56
56
%%
85
85
 
86
86
%% profiling
87
87
 
88
 
-spec(profile/1 :: (Filename :: string()) -> 
89
 
        {'ok', port()} | {'already_started', port()}).
 
88
-spec profile(Filename :: file:filename()) ->
 
89
        {'ok', port()} | {'already_started', port()}.
90
90
 
91
91
profile(Filename) ->
92
92
    percept_profile:start(Filename, [procs]).
94
94
%% @spec profile(Filename::string(), [percept_option()]) -> {ok, Port} | {already_started, Port}
95
95
%% @see percept_profile
96
96
 
97
 
-spec(profile/2 :: (
98
 
        Filename :: string(),
99
 
        Options :: [percept_option()]) ->
100
 
        {'ok', port()} | {'already_started', port()}).
 
97
-spec profile(Filename :: file:filename(),
 
98
              Options :: [percept_option()]) ->
 
99
        {'ok', port()} | {'already_started', port()}.
101
100
 
102
101
profile(Filename, Options) ->
103
102
    percept_profile:start(Filename, Options). 
105
104
%% @spec profile(Filename::string(), MFA::mfa(), [percept_option()]) -> ok | {already_started, Port} | {error, not_started}
106
105
%% @see percept_profile
107
106
 
108
 
-spec(profile/3 :: (
109
 
        Filename :: string(),
110
 
        Entry :: {atom(), atom(), list()},
111
 
        Options :: [percept_option()]) ->
112
 
        'ok' | {'already_started', port()} | {'error', 'not_started'}).
 
107
-spec profile(Filename :: file:filename(),
 
108
              Entry :: {atom(), atom(), list()},
 
109
              Options :: [percept_option()]) ->
 
110
        'ok' | {'already_started', port()} | {'error', 'not_started'}.
113
111
 
114
112
profile(Filename, MFA, Options) ->
115
113
    percept_profile:start(Filename, MFA, Options).
116
114
 
117
 
-spec(stop_profile/0 :: () -> 'ok' | {'error', 'not_started'}).
 
115
-spec stop_profile() -> 'ok' | {'error', 'not_started'}.
118
116
 
119
117
%% @spec stop_profile() -> ok | {'error', 'not_started'}
120
118
%% @see percept_profile
125
123
%% @spec analyze(string()) -> ok | {error, Reason} 
126
124
%% @doc Analyze file.
127
125
 
128
 
-spec(analyze/1 :: (Filename :: string()) -> 
129
 
        'ok' | {'error', any()}).
 
126
-spec analyze(Filename :: file:filename()) ->
 
127
        'ok' | {'error', any()}.
130
128
 
131
129
analyze(Filename) ->
132
130
    case percept_db:start() of 
142
140
%%      Reason = term() 
143
141
%% @doc Starts webserver.
144
142
 
145
 
-spec(start_webserver/0 :: () -> 
146
 
        {'started', string(), pos_integer()} | 
147
 
        {'error', any()}).
 
143
-spec start_webserver() ->
 
144
        {'started', string(), pos_integer()} | {'error', any()}.
148
145
 
149
146
start_webserver() ->
150
147
    start_webserver(0).
156
153
%% @doc Starts webserver. If port number is 0, an available port number will 
157
154
%%      be assigned by inets.
158
155
 
159
 
-spec(start_webserver/1 :: (Port :: non_neg_integer()) -> 
160
 
        {'started', string(), pos_integer()} | 
161
 
        {'error', any()}).
 
156
-spec start_webserver(Port :: non_neg_integer()) ->
 
157
        {'started', string(), pos_integer()} | {'error', any()}.
162
158
 
163
159
start_webserver(Port) when is_integer(Port) ->
164
160
    application:load(percept),
189
185
        undefined -> 
190
186
            {error, not_started};
191
187
        Pid ->
192
 
            Pid ! {self(), get_port},
193
 
            receive Port -> ok end,
194
 
            Pid ! quit,
195
 
            stop_webserver(Port)
 
188
            do_stop([], Pid)
 
189
    end.
 
190
 
 
191
do_stop([], Pid)->
 
192
    Pid ! {self(), get_port},
 
193
    Port = receive P -> P end,
 
194
    do_stop(Port, Pid);
 
195
do_stop(Port, [])->
 
196
    case whereis(percept_httpd) of
 
197
        undefined ->
 
198
            {error, not_started};
 
199
        Pid ->
 
200
            do_stop(Port, Pid)
 
201
    end;
 
202
do_stop(Port, Pid)->
 
203
    case find_service_pid_from_port(inets:services_info(), Port) of
 
204
        undefined ->
 
205
            {error, not_started};
 
206
        Pid2 ->
 
207
            Pid ! quit,
 
208
            inets:stop(httpd, Pid2)
196
209
    end.
197
210
 
198
211
%% @spec stop_webserver(integer()) -> ok | {error, not_started}
200
213
%% @hidden
201
214
 
202
215
stop_webserver(Port) ->
203
 
    case find_service_pid_from_port(inets:services_info(), Port) of
204
 
        undefined ->
205
 
            {error, not_started};
206
 
        Pid ->
207
 
            inets:stop(httpd, Pid)
208
 
    end. 
 
216
    do_stop(Port,[]).
209
217
 
210
218
%%==========================================================================
211
219
%%
255
263
find_service_pid_from_port([], _) ->
256
264
    undefined;
257
265
find_service_pid_from_port([{_, Pid, Options} | Services], Port) ->
258
 
    case lists:keysearch(port, 1, Options) of
 
266
    case lists:keyfind(port, 1, Options) of
259
267
        false ->
260
268
            find_service_pid_from_port(Services, Port);
261
 
        {value, {port, Port}} ->
 
269
        {port, Port} ->
262
270
            Pid
263
271
    end.
264
272
 
265
273
find_service_port_from_pid([], _) ->
266
274
    undefined;
267
275
find_service_port_from_pid([{_, Pid, Options} | _], Pid) ->
268
 
    case lists:keysearch(port, 1, Options) of
 
276
    case lists:keyfind(port, 1, Options) of
269
277
        false ->
270
278
            undefined;
271
 
        {value, {port, Port}} ->
 
279
        {port, Port} ->
272
280
           Port
273
281
    end;
274
282
find_service_port_from_pid([{_, _, _} | Services], Pid) ->