~clint-fewbar/ubuntu/precise/erlang/merge-15b

« back to all changes in this revision

Viewing changes to lib/observer/src/observer_sys_wx.erl

  • Committer: Package Import Robot
  • Author(s): Sergei Golovan
  • Date: 2011-12-15 19:20:10 UTC
  • mfrom: (1.1.18) (3.5.15 sid)
  • mto: (3.5.16 sid)
  • mto: This revision was merged to the branch mainline in revision 33.
  • Revision ID: package-import@ubuntu.com-20111215192010-jnxcfe3tbrpp0big
Tags: 1:15.b-dfsg-1
* New upstream release.
* Upload to experimental because this release breaks external drivers
  API along with ABI, so several applications are to be fixed.
* Removed SSL patch because the old SSL implementation is removed from
  the upstream distribution.
* Removed never used patch which added native code to erlang beam files.
* Removed the erlang-docbuilder binary package because the docbuilder
  application was dropped by upstream.
* Documented dropping ${erlang-docbuilder:Depends} substvar in
  erlang-depends(1) manpage.
* Made erlang-base and erlang-base-hipe provide virtual package
  erlang-abi-15.b (the number means the first erlang version, which
  provides current ABI).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
%%
 
2
%% %CopyrightBegin%
 
3
%%
 
4
%% Copyright Ericsson AB 2011. All Rights Reserved.
 
5
%%
 
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/.
 
11
%%
 
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
 
15
%% under the License.
 
16
%%
 
17
%% %CopyrightEnd%
 
18
-module(observer_sys_wx).
 
19
 
 
20
-behaviour(wx_object).
 
21
 
 
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]).
 
26
 
 
27
-include_lib("wx/include/wx.hrl").
 
28
-include("observer_defs.hrl").
 
29
 
 
30
-define(ID_REFRESH, 101).
 
31
-define(ID_REFRESH_INTERVAL, 102).
 
32
 
 
33
%% Records
 
34
-record(sys_wx_state,
 
35
        {parent,
 
36
         node,
 
37
         parent_notebook,
 
38
         panel, sizer,
 
39
         menubar,
 
40
         fields,
 
41
         timer}).
 
42
 
 
43
start_link(Notebook, Parent) ->
 
44
    wx_object:start_link(?MODULE, [Notebook, Parent], []).
 
45
 
 
46
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
47
 
 
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}}.
 
67
 
 
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]).
 
72
 
 
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).
 
79
 
 
80
info_fields() ->
 
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}
 
90
             ]},
 
91
            {"CPU's and Threads",
 
92
             [{"System Logical CPU's", logical_processors},
 
93
              {"Erlang Logical CPU's", logical_processors_online},
 
94
              {"Used Logical CPU's", logical_processors_available}
 
95
             ]}
 
96
           ],
 
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}}
 
104
             ]},
 
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}}
 
112
             ]}
 
113
           ],
 
114
    {Info, Stat}.
 
115
 
 
116
%%%%%%%%%%%%%%%%%%%%%%% Callbacks %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
117
 
 
118
handle_info(refresh_interval, #sys_wx_state{panel = Panel,
 
119
                                            node = Node} = State) ->
 
120
    try
 
121
        update_syspage(State)
 
122
    catch error:{badrpc, _} ->
 
123
            observer_wx:return_to_localnode(Panel, Node)
 
124
    end,
 
125
    {noreply, State};
 
126
 
 
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),
 
131
    try
 
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),
 
136
            {noreply, State}
 
137
    end;
 
138
 
 
139
handle_info(not_active, #sys_wx_state{timer = Timer} = State) ->
 
140
    {noreply, State#sys_wx_state{timer = observer_lib:stop_timer(Timer)}};
 
141
 
 
142
handle_info(Info, State) ->
 
143
    io:format("~p:~p: Unhandled info: ~p~n", [?MODULE, ?LINE, Info]),
 
144
    {noreply, State}.
 
145
 
 
146
terminate(_Reason, _State) ->
 
147
    ok.
 
148
 
 
149
code_change(_, _, State) ->
 
150
    {stop, not_yet_implemented, State}.
 
151
 
 
152
handle_call(Msg, _From, State) ->
 
153
    io:format("~p~p: Unhandled Call ~p~n",[?MODULE, ?LINE, Msg]),
 
154
    {reply, ok, State}.
 
155
 
 
156
handle_cast(Msg, State) ->
 
157
    io:format("~p~p: Unhandled cast ~p~n",[?MODULE, ?LINE, Msg]),
 
158
    {noreply, State}.
 
159
 
 
160
handle_event(#wx{id = ?ID_REFRESH, event = #wxCommand{type = command_menu_selected}},
 
161
             #sys_wx_state{node = Node, panel = Panel} = State) ->
 
162
    try
 
163
        update_syspage(State)
 
164
    catch error:{badrpc, _} ->
 
165
            observer_wx:return_to_localnode(Panel, Node)
 
166
    end,
 
167
    {noreply, State};
 
168
 
 
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}};
 
174
 
 
175
handle_event(Event, State) ->
 
176
    io:format("~p:~p: Unhandled event ~p\n", [?MODULE,?LINE,Event]),
 
177
    {noreply, State}.