4
%% Copyright Ericsson AB 2011. All Rights Reserved.
6
%% The contents of this file are subject to the Erlang Public License,
7
%% Version 1.1, (the "License"); you may not use this file except in
8
%% compliance with the License. You should have received a copy of the
9
%% Erlang Public License along with this software. If not, it can be
10
%% retrieved online at http://www.erlang.org/.
12
%% Software distributed under the License is distributed on an "AS IS"
13
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
14
%% the License for the specific language governing rights and limitations
18
-module(observer_sys_wx).
20
-behaviour(wx_object).
22
-export([start_link/2]).
23
%% wx_object callbacks
24
-export([init/1, handle_info/2, terminate/2, code_change/3, handle_call/3,
25
handle_event/2, handle_cast/2]).
27
-include_lib("wx/include/wx.hrl").
28
-include("observer_defs.hrl").
30
-define(ID_REFRESH, 101).
31
-define(ID_REFRESH_INTERVAL, 102).
43
start_link(Notebook, Parent) ->
44
wx_object:start_link(?MODULE, [Notebook, Parent], []).
46
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
48
init([Notebook, Parent]) ->
49
SysInfo = observer_backend:sys_info(),
50
{Info, Stat} = info_fields(),
51
Panel = wxPanel:new(Notebook),
52
Sizer = wxBoxSizer:new(?wxHORIZONTAL),
53
{FPanel0, _FSizer0, Fields0} =
54
observer_lib:display_info(Panel, observer_lib:fill_info(Info, SysInfo)),
55
{FPanel1, _FSizer1, Fields1} =
56
observer_lib:display_info(Panel, observer_lib:fill_info(Stat, SysInfo)),
57
wxSizer:add(Sizer, FPanel0, [{flag, ?wxEXPAND bor ?wxTOP bor ?wxBOTTOM bor ?wxLEFT},
58
{proportion, 1}, {border, 5}]),
59
wxSizer:add(Sizer, FPanel1, [{flag, ?wxEXPAND bor ?wxTOP bor ?wxBOTTOM bor ?wxRIGHT},
60
{proportion, 1}, {border, 5}]),
61
wxPanel:setSizer(Panel, Sizer),
62
Timer = observer_lib:start_timer(10),
63
{Panel, #sys_wx_state{parent=Parent,
64
parent_notebook=Notebook,
65
panel=Panel, sizer=Sizer,
66
timer=Timer, fields=Fields0 ++ Fields1}}.
68
create_sys_menu(Parent) ->
69
View = {"View", [#create_menu{id = ?ID_REFRESH, text = "Refresh\tCtrl-R"},
70
#create_menu{id = ?ID_REFRESH_INTERVAL, text = "Refresh interval"}]},
71
observer_wx:create_menus(Parent, [View]).
73
update_syspage(#sys_wx_state{node = Node, fields=Fields, sizer=Sizer}) ->
74
SysInfo = observer_wx:try_rpc(Node, observer_backend, sys_info, []),
75
{Info, Stat} = info_fields(),
76
observer_lib:update_info(Fields, observer_lib:fill_info(Info, SysInfo) ++
77
observer_lib:fill_info(Stat, SysInfo)),
78
wxSizer:layout(Sizer).
81
Info = [{"System and Architecture",
82
[{"System Version", otp_release},
83
{"Erts Version", version},
84
{"Compiled for", system_architecture},
85
{"Emulator Wordsize", wordsize_external},
86
{"Process Wordsize", wordsize_internal},
87
{"Smp Support", smp_support},
88
{"Thread Support", threads},
89
{"Async thread pool size", thread_pool_size}
92
[{"System Logical CPU's", logical_processors},
93
{"Erlang Logical CPU's", logical_processors_online},
94
{"Used Logical CPU's", logical_processors_available}
97
Stat = [{"Memory Usage", right,
98
[{"Total", {bytes, total}},
99
{"Processes", {bytes, processes}},
100
{"Atoms", {bytes, atom}},
101
{"Binaries", {bytes, binary}},
102
{"Code", {bytes, code}},
103
{"Ets", {bytes, ets}}
105
{"Statistics", right,
106
[{"Up time", {time_ms, uptime}},
107
{"Max Processes", process_limit},
108
{"Processes", process_count},
109
{"Run Queue", run_queue},
110
{"IO Input", {bytes, io_input}},
111
{"IO Output", {bytes, io_output}}
116
%%%%%%%%%%%%%%%%%%%%%%% Callbacks %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
118
handle_info(refresh_interval, #sys_wx_state{panel = Panel,
119
node = Node} = State) ->
121
update_syspage(State)
122
catch error:{badrpc, _} ->
123
observer_wx:return_to_localnode(Panel, Node)
127
handle_info({active, Node}, #sys_wx_state{parent = Parent, panel = Panel,
128
timer = Timer} = State) ->
129
UpdState = State#sys_wx_state{node = Node},
130
create_sys_menu(Parent),
132
update_syspage(UpdState),
133
{noreply, UpdState#sys_wx_state{timer=observer_lib:start_timer(Timer)}}
134
catch error:{badrpc, _} ->
135
observer_wx:return_to_localnode(Panel, Node),
139
handle_info(not_active, #sys_wx_state{timer = Timer} = State) ->
140
{noreply, State#sys_wx_state{timer = observer_lib:stop_timer(Timer)}};
142
handle_info(Info, State) ->
143
io:format("~p:~p: Unhandled info: ~p~n", [?MODULE, ?LINE, Info]),
146
terminate(_Reason, _State) ->
149
code_change(_, _, State) ->
150
{stop, not_yet_implemented, State}.
152
handle_call(Msg, _From, State) ->
153
io:format("~p~p: Unhandled Call ~p~n",[?MODULE, ?LINE, Msg]),
156
handle_cast(Msg, State) ->
157
io:format("~p~p: Unhandled cast ~p~n",[?MODULE, ?LINE, Msg]),
160
handle_event(#wx{id = ?ID_REFRESH, event = #wxCommand{type = command_menu_selected}},
161
#sys_wx_state{node = Node, panel = Panel} = State) ->
163
update_syspage(State)
164
catch error:{badrpc, _} ->
165
observer_wx:return_to_localnode(Panel, Node)
169
handle_event(#wx{id = ?ID_REFRESH_INTERVAL,
170
event = #wxCommand{type = command_menu_selected}},
171
#sys_wx_state{timer = Timer0, parent_notebook = Notebook} = State) ->
172
Timer = observer_lib:interval_dialog(Notebook, Timer0, 1, 5*60),
173
{noreply, State#sys_wx_state{timer=Timer}};
175
handle_event(Event, State) ->
176
io:format("~p:~p: Unhandled event ~p\n", [?MODULE,?LINE,Event]),