aboutsummaryrefslogtreecommitdiffstats
path: root/lib/observer/src/cdv_sched_cb.erl
blob: d2696a276f12d7676b9e4dc8d36a4ef349898c6b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
%%
%% %CopyrightBegin%
%%
%% Copyright Ericsson AB 2013-2016. All Rights Reserved.
%%
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
%% You may obtain a copy of the License at
%%
%%     http://www.apache.org/licenses/LICENSE-2.0
%%
%% Unless required by applicable law or agreed to in writing, software
%% distributed under the License is distributed on an "AS IS" BASIS,
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
%% See the License for the specific language governing permissions and
%% limitations under the License.
%%
%% %CopyrightEnd%
-module(cdv_sched_cb).

-export([col_to_elem/1,
	 col_spec/0,
	 get_info/1,
	 get_details/2,
	 get_detail_cols/1,
	 detail_pages/0
	]).

-include_lib("wx/include/wx.hrl").
-include("crashdump_viewer.hrl").

%% Columns
-define(COL_ID,  0).
-define(COL_TYPE,  ?COL_ID+1).
-define(COL_PROC,  ?COL_TYPE+1).
-define(COL_PORT,  ?COL_PROC+1).
-define(COL_RQL,   ?COL_PORT+1).
-define(COL_PQL,   ?COL_RQL+1).

%% Callbacks for cdv_virtual_list_wx
col_to_elem(id) -> col_to_elem(?COL_ID);
col_to_elem(?COL_ID)  -> #sched.name;
col_to_elem(?COL_TYPE)  -> #sched.type;
col_to_elem(?COL_PROC)  -> #sched.process;
col_to_elem(?COL_PORT)  -> #sched.port;
col_to_elem(?COL_RQL)   -> #sched.run_q;
col_to_elem(?COL_PQL)   -> #sched.port_q.

col_spec() ->
    [{"Id",                ?wxLIST_FORMAT_RIGHT,   50},
     {"Type",              ?wxLIST_FORMAT_CENTER, 100},
     {"Current Process",   ?wxLIST_FORMAT_CENTER, 130},
     {"Current Port",      ?wxLIST_FORMAT_CENTER, 130},
     {"Run Queue Length",  ?wxLIST_FORMAT_RIGHT,  180},
     {"Port Queue Length", ?wxLIST_FORMAT_RIGHT,  180}].

get_info(_) ->
    {ok,Info,TW} = crashdump_viewer:schedulers(),
    {Info,TW}.

get_details(_Id, not_found) ->
    Info = "The scheduler you are searching for could not be found.",
    {info,Info};
get_details(Id, Data) ->
    Proplist = crashdump_viewer:to_proplist(record_info(fields,sched),Data),
    {ok,{"Scheduler: " ++ Id,Proplist,""}}.

get_detail_cols(all) ->
    {[{sched, ?COL_ID}, {process, ?COL_PROC}, {process, ?COL_PORT}],true};
get_detail_cols(_) ->
    {[],false}.

%%%%%%%%%%%%%%%%%%%%%%%%

detail_pages() ->
    [{"Scheduler Information", fun init_gen_page/2}].

init_gen_page(Parent, Info0) ->
    Type = proplists:get_value(type, Info0),
    Fields = info_fields(Type),
    Details = proplists:get_value(details, Info0),
    Info = if is_map(Details) -> Info0 ++ maps:to_list(Details);
	      true -> Info0
	   end,
    cdv_info_wx:start_link(Parent,{Fields,Info,[]}).

%%% Internal
info_fields(Type) ->
    [{"Scheduler Overview",
      [{"Id",             id},
       {"Type",           type},
       {"Current Process",process},
       {"Current Port",   port},
       {"Sleep Info Flags", sleep_info},
       {"Sleep Aux Work",   sleep_aux}
      ]},
     {run_queues_header(Type),
      [{"Flags",                   runq_flags},
       {"Priority Max Length",     runq_max},
       {"Priority High Length",    runq_high},
       {"Priority Normal Length",  runq_norm},
       {"Priority Low Length",     runq_low},
       {"Port Length",     port_q}
      ]},
     {"Current Process",
      [{"State",           currp_state},
       {"Internal State",  currp_int_state},
       {"Program Counter", currp_prg_cnt},
       {"CP",              currp_cp},
       {"Stack",           {currp_stack, 0}},
       {"     ",           {currp_stack, 1}},
       {"     ",           {currp_stack, 2}},
       {"     ",           {currp_stack, 3}},
       {"     ",           {currp_stack, 4}},
       {"     ",           {currp_stack, 5}},
       {"     ",           {currp_stack, 6}},
       {"     ",           {currp_stack, 7}},
       {"     ",           {currp_stack, 8}},
       {"     ",           {currp_stack, 9}},
       {"     ",           {currp_stack, 10}},
       {"     ",           {currp_stack, 11}}
      ]}
    ].

run_queues_header(normal) ->
    "Run Queues";
run_queues_header(DirtyX) ->
    "Run Queues (common for all '" ++ atom_to_list(DirtyX) ++ "' schedulers)".