~ubuntu-branches/debian/squeeze/erlang/squeeze

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Sergei Golovan
  • Date: 2010-03-09 17:34:57 UTC
  • mfrom: (10.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20100309173457-4yd6hlcb2osfhx31
Tags: 1:13.b.4-dfsg-3
Manpages in section 1 are needed even if only arch-dependent packages are
built. So, re-enabled them.

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),
255
251
find_service_pid_from_port([], _) ->
256
252
    undefined;
257
253
find_service_pid_from_port([{_, Pid, Options} | Services], Port) ->
258
 
    case lists:keysearch(port, 1, Options) of
 
254
    case lists:keyfind(port, 1, Options) of
259
255
        false ->
260
256
            find_service_pid_from_port(Services, Port);
261
 
        {value, {port, Port}} ->
 
257
        {port, Port} ->
262
258
            Pid
263
259
    end.
264
260
 
265
261
find_service_port_from_pid([], _) ->
266
262
    undefined;
267
263
find_service_port_from_pid([{_, Pid, Options} | _], Pid) ->
268
 
    case lists:keysearch(port, 1, Options) of
 
264
    case lists:keyfind(port, 1, Options) of
269
265
        false ->
270
266
            undefined;
271
 
        {value, {port, Port}} ->
 
267
        {port, Port} ->
272
268
           Port
273
269
    end;
274
270
find_service_port_from_pid([{_, _, _} | Services], Pid) ->