|
40 | 40 | -export([terminate/2, code_change/3]).
|
41 | 41 | -export([add/2, add/3, add/5]).
|
42 | 42 | -export([get/2]).
|
| 43 | +-export([stat_t/0, stat_t/1, add_stat_t/2, upd_stat_t/3, upd_stat_t/4]). |
43 | 44 |
|
44 | 45 | %%%----------------------------------------------------------------------------
|
45 | 46 | %%% Includes
|
@@ -80,6 +81,11 @@ handle_call(stop, _From, St) ->
|
80 | 81 | handle_call(status, _From, St) ->
|
81 | 82 | {reply, St, St};
|
82 | 83 |
|
| 84 | +%% @doc returns time statistic |
| 85 | +handle_call({stat_t, Type}, _From, St) -> |
| 86 | + Res = ejobman_print_stat:make_stat_t_info(St, Type), |
| 87 | + {reply, Res, St}; |
| 88 | + |
83 | 89 | handle_call({get, Start, Stop}, _From, St) ->
|
84 | 90 | mpln_p_debug:pr({?MODULE, get1, ?LINE, Start, Stop}, St#est.debug, run, 2),
|
85 | 91 | Res = get_items(St, Start, Stop),
|
@@ -116,6 +122,12 @@ handle_cast({add_job, Time, Tag}, St) ->
|
116 | 122 | add_job_stat(Time, Tag),
|
117 | 123 | {noreply, St};
|
118 | 124 |
|
| 125 | +handle_cast({upd_job, Time, Tag, Work, Queued}, St) -> |
| 126 | + mpln_p_debug:pr({?MODULE, 'cast upd_job', ?LINE, Time, Tag}, |
| 127 | + St#est.debug, run, 4), |
| 128 | + upd_job_stat(Time, Tag, Work, Queued), |
| 129 | + {noreply, St}; |
| 130 | + |
119 | 131 | handle_cast(_Other, St) ->
|
120 | 132 | mpln_p_debug:pr({?MODULE, 'cast other', ?LINE, _Other},
|
121 | 133 | St#est.debug, run, 2),
|
@@ -232,6 +244,43 @@ add(Id1, Id2, Time, Now, Data) ->
|
232 | 244 | get(Start, Stop) ->
|
233 | 245 | gen_server:call(?MODULE, {get, Start, Stop}).
|
234 | 246 |
|
| 247 | +%%----------------------------------------------------------------------------- |
| 248 | +%% |
| 249 | +%% @doc asks ejobman_stat for time statistic |
| 250 | +%% @since 2012-02-02 14:09 |
| 251 | +%% |
| 252 | +-spec stat_t() -> string(). |
| 253 | + |
| 254 | +stat_t() -> |
| 255 | + stat_t(raw). |
| 256 | + |
| 257 | +stat_t(Type) -> |
| 258 | + gen_server:call(?MODULE, {stat_t, Type}). |
| 259 | + |
| 260 | +%%----------------------------------------------------------------------------- |
| 261 | +%% |
| 262 | +%% @doc api call to add time statistic |
| 263 | +%% @since 2012-02-02 14:09 |
| 264 | +%% |
| 265 | +-spec add_stat_t(tuple(), any()) -> ok. |
| 266 | + |
| 267 | +add_stat_t(Time, Tag) -> |
| 268 | + gen_server:cast(?MODULE, {add_job, Time, Tag}). |
| 269 | + |
| 270 | +%% |
| 271 | +%% @doc api call to update time statistic |
| 272 | +%% @since 2012-02-02 14:09 |
| 273 | +%% |
| 274 | +-spec upd_stat_t(any(), non_neg_integer(), non_neg_integer()) -> ok. |
| 275 | + |
| 276 | +upd_stat_t(Tag, Work, Queued) -> |
| 277 | + upd_stat_t(now(), Tag, Work, Queued). |
| 278 | + |
| 279 | +-spec upd_stat_t(tuple(), any(), non_neg_integer(), non_neg_integer()) -> ok. |
| 280 | + |
| 281 | +upd_stat_t(Time, Tag, Work, Queued) -> |
| 282 | + gen_server:cast(?MODULE, {upd_job, Time, Tag, Work, Queued}). |
| 283 | + |
235 | 284 | %%%----------------------------------------------------------------------------
|
236 | 285 | %%% Internal functions
|
237 | 286 | %%%----------------------------------------------------------------------------
|
@@ -342,11 +391,36 @@ add_item(#est{storage=S} = St, Id, {Time, Now}, Data) ->
|
342 | 391 | New = St#est{storage = [Item | S]},
|
343 | 392 | check_flush(New).
|
344 | 393 |
|
| 394 | +%%----------------------------------------------------------------------------- |
| 395 | +%% |
| 396 | +%% @doc updates items in job statistic (minute and hourly) |
| 397 | +%% |
| 398 | +-spec upd_job_stat(tuple(), any(), non_neg_integer(), non_neg_integer()) -> |
| 399 | + true. |
| 400 | + |
| 401 | +upd_job_stat(Time, Tag, Work, Queued) -> |
| 402 | + upd_minute_job_stat(Time, Tag, Work, Queued), |
| 403 | + upd_hourly_job_stat(Time, Tag, Work, Queued). |
| 404 | + |
| 405 | +upd_minute_job_stat(Time, Tag, Work, Queued) -> |
| 406 | + estat_misc:set_max_timed_stat(?STAT_TAB_M, 'minute', Time, {Tag, 'work'}, |
| 407 | + Work), |
| 408 | + estat_misc:set_max_timed_stat(?STAT_TAB_M, 'minute', Time, {Tag, 'queued'}, |
| 409 | + Queued). |
| 410 | + |
| 411 | +upd_hourly_job_stat(Time, Tag, Work, Queued) -> |
| 412 | + estat_misc:set_max_timed_stat(?STAT_TAB_H, 'hour', Time, {Tag, 'work'}, |
| 413 | + Work), |
| 414 | + estat_misc:set_max_timed_stat(?STAT_TAB_H, 'hour', Time, {Tag, 'queued'}, |
| 415 | + Queued). |
| 416 | + |
| 417 | + |
345 | 418 | %%-----------------------------------------------------------------------------
|
346 | 419 | %%
|
347 | 420 | %% @doc adds item to job statistic (minute and hourly)
|
348 | 421 | %%
|
349 | 422 | -spec add_job_stat(tuple(), any()) -> true.
|
| 423 | + |
350 | 424 | add_job_stat(Time, Tag) ->
|
351 | 425 | add_minute_job_stat(Time, Tag),
|
352 | 426 | add_hourly_job_stat(Time, Tag).
|
|
0 commit comments