2 Copyright 2010-2017, The AROS Development Team. All rights reserved.
7 #include <aros/debug.h>
9 #include <proto/alib.h>
10 #include <proto/muimaster.h>
14 #include <zune/graph.h>
16 #include "sysmon_intern.h"
20 #define VERSION "$VER: SysMon 1.4 (23.01.2017) ©2011-2017 The AROS Development Team"
24 AROS_UFH3(VOID
, tasklistrefreshfunction
,
25 AROS_UFHA(struct Hook
*, h
, A0
),
26 AROS_UFHA(Object
*, object
, A2
),
27 AROS_UFHA(APTR
, msg
, A1
))
31 struct SysMonData
* smdata
= h
->h_Data
;
32 IPTR taskReady
= 0, taskWait
= 0;
34 D(bug("[SysMon] %s(0x%p)\n", __func__
, object
));
36 GET(smdata
->tasklist
, MUIA_Tasklist_ReadyCount
, &taskReady
);
37 GET(smdata
->tasklist
, MUIA_Tasklist_WaitingCount
, &taskWait
);
39 __sprintf(smdata
->tasklistinfobuf
, smdata
->msg_taskreadywait
, taskReady
, taskWait
);
41 set(smdata
->tasklistinfo
, MUIA_Text_Contents
, smdata
->tasklistinfobuf
);
47 AROS_UFH3(VOID
, pageactivefunction
,
48 AROS_UFHA(struct Hook
*, h
, A0
),
49 AROS_UFHA(Object
*, object
, A2
),
50 AROS_UFHA(APTR
, msg
, A1
))
56 D(bug("[SysMon] %s(0x%p)\n", __func__
, object
));
58 // get the selected page
59 get(object
, MUIA_Group_ActivePage
, &thisPage
);
61 D(bug("[SysMon] page #%d\n", thisPage
));
63 // TODO: change the menu for the active page.
69 BOOL
CreateApplication(struct SysMonData
* smdata
)
71 Object
* menuitemfast
;
72 Object
* menuitemnormal
;
73 Object
* menuitemslow
;
76 Object
* cpuusagegroup
;
77 Object
* cpufreqgroup
;
81 LONG processorcount
= GetProcessorCount();
83 smdata
->tabs
[0] = _(MSG_TAB_TASKS
);
84 smdata
->tabs
[1] = _(MSG_TAB_CPU
);
85 smdata
->tabs
[2] = _(MSG_TAB_SYSTEM
);
86 smdata
->tabs
[3] = NULL
;
88 smdata
->tasklistinfobuf
= AllocVec(30, MEMF_PUBLIC
);
89 smdata
->tasklistrefreshhook
.h_Entry
= (APTR
)tasklistrefreshfunction
;
90 smdata
->tasklistrefreshhook
.h_Data
= (APTR
)smdata
;
93 smdata
->pageactivehook
.h_Entry
= (APTR
)pageactivefunction
;
94 smdata
->pageactivehook
.h_Data
= (APTR
)smdata
;
97 smdata
->msg_taskreadywait
= (STRPTR
)_(MSG_TASK_READY_WAIT
);
98 smdata
->msg_project
= (STRPTR
)_(MSG_PROJECT
);
99 smdata
->msg_refresh_speed
= (STRPTR
)_(MSG_REFRESH_SPEED
);
100 smdata
->msg_fast
= (STRPTR
)_(MSG_FAST
);
101 smdata
->msg_normal
= (STRPTR
)_(MSG_NORMAL
);
102 smdata
->msg_slow
= (STRPTR
)_(MSG_SLOW
);
104 smdata
->tasklist
= (Object
*)NewObject(Tasklist_CLASS
->mcc_Class
, NULL
, MUIA_Tasklist_RefreshMSecs
, MUIV_Tasklist_Refresh_Normal
, TAG_DONE
);
106 smdata
->application
= ApplicationObject
,
107 MUIA_Application_Title
, __(MSG_APP_NAME
),
108 MUIA_Application_Version
, (IPTR
) VERSION
,
109 MUIA_Application_Author
, (IPTR
) "Krzysztof Smiechowicz",
110 MUIA_Application_Copyright
, (IPTR
)"©2011-2017, The AROS Development Team",
111 MUIA_Application_Base
, (IPTR
)"SYSMON",
112 MUIA_Application_Description
, __(MSG_APP_TITLE
),
114 smdata
->mainwindow
= WindowObject
,
115 MUIA_Window_Title
, __(MSG_WINDOW_TITLE
),
116 MUIA_Window_ID
, MAKE_ID('S','Y','S','M'),
117 MUIA_Window_Height
, MUIV_Window_Height_Visible(45),
118 MUIA_Window_Width
, MUIV_Window_Width_Visible(35),
119 MUIA_Window_Menustrip
, (MenustripObject
,
120 MUIA_Family_Child
, (MenuObject
,
121 MUIA_Menu_Title
, (IPTR
)smdata
->msg_project
,
122 MUIA_Family_Child
, (MenuitemObject
,
123 MUIA_Menuitem_Title
, (IPTR
)smdata
->msg_refresh_speed
,
124 MUIA_Family_Child
, (menuitemfast
= MenuitemObject
, MUIA_Menuitem_Title
, (IPTR
)smdata
->msg_fast
, MUIA_Menuitem_Shortcut
, (IPTR
)"F",End
),
125 MUIA_Family_Child
, (menuitemnormal
= MenuitemObject
, MUIA_Menuitem_Title
, (IPTR
)smdata
->msg_normal
, MUIA_Menuitem_Shortcut
, (IPTR
)"N",End
),
126 MUIA_Family_Child
, (menuitemslow
= MenuitemObject
, MUIA_Menuitem_Title
, (IPTR
)smdata
->msg_slow
, MUIA_Menuitem_Shortcut
, (IPTR
)"S",End
),
131 smdata
->pages
= RegisterGroup(smdata
->tabs
),
133 Child
, ListviewObject
,
134 MUIA_Listview_List
, (IPTR
)smdata
->tasklist
,
137 Child
, smdata
->tasklistinfo
= TextObject
,
139 MUIA_Font
, MUIV_Font_Tiny
,
140 MUIA_Text_PreParse
, (IPTR
)"\33r",
141 MUIA_Text_Contents
, (IPTR
)_(MSG_TASK_READY_WAIT_INIT
),
146 Child
, cpuusagegroup
= HGroup
, GroupFrameT(_(MSG_USAGE
)),
148 Child
, VGroup
, GroupFrameT(_(MSG_FREQUENCY
)),
149 Child
, cpufreqgroup
= ColGroup(3),
155 Child
, VGroup
, GroupFrameT(_(MSG_MEMORY_SIZE
)),
157 Child
, Label(_(MSG_TOTAL_RAM
)),
158 Child
, smdata
->memorysize
[MEMORY_RAM
] = TextObject
, TextFrame
, MUIA_Background
, MUII_TextBack
,
159 MUIA_Text_PreParse
, (IPTR
)"\33r", MUIA_Text_Contents
, (IPTR
)"---- Kb",
161 Child
, Label(_(MSG_CHIP_RAM
)),
162 Child
, smdata
->memorysize
[MEMORY_CHIP
] = TextObject
, TextFrame
, MUIA_Background
, MUII_TextBack
,
163 MUIA_Text_PreParse
, (IPTR
)"\33r", MUIA_Text_Contents
, (IPTR
)"",
165 Child
, Label(_(MSG_FAST_RAM
)),
166 Child
, smdata
->memorysize
[MEMORY_FAST
] = TextObject
, TextFrame
, MUIA_Background
, MUII_TextBack
,
167 MUIA_Text_PreParse
, (IPTR
)"\33r", MUIA_Text_Contents
, (IPTR
)"",
171 Child
, VGroup
, GroupFrameT(_(MSG_MEMORY_FREE
)),
173 Child
, Label(_(MSG_TOTAL_RAM
)),
174 Child
, smdata
->memoryfree
[MEMORY_RAM
] = TextObject
, TextFrame
, MUIA_Background
, MUII_TextBack
,
175 MUIA_Text_PreParse
, (IPTR
)"\33r", MUIA_Text_Contents
, (IPTR
)"---- Kb",
177 Child
, Label(_(MSG_CHIP_RAM
)),
178 Child
, smdata
->memoryfree
[MEMORY_CHIP
] = TextObject
, TextFrame
, MUIA_Background
, MUII_TextBack
,
179 MUIA_Text_PreParse
, (IPTR
)"\33r", MUIA_Text_Contents
, (IPTR
)"",
181 Child
, Label(_(MSG_FAST_RAM
)),
182 Child
, smdata
->memoryfree
[MEMORY_FAST
] = TextObject
, TextFrame
, MUIA_Background
, MUII_TextBack
,
183 MUIA_Text_PreParse
, (IPTR
)"\33r", MUIA_Text_Contents
, (IPTR
)"",
189 Child
, VGroup
, GroupFrameT(_(MSG_VIDEO_SIZE
)),
191 Child
, Label(_(MSG_VIDEO_RAM
)),
192 Child
, smdata
->memorysize
[MEMORY_VRAM
] = TextObject
, TextFrame
, MUIA_Background
, MUII_TextBack
,
193 MUIA_Text_PreParse
, (IPTR
)"\33r", MUIA_Text_Contents
, (IPTR
)"",
195 Child
, Label(_(MSG_GART_APER
)),
196 Child
, smdata
->memorysize
[MEMORY_GART
] = TextObject
, TextFrame
, MUIA_Background
, MUII_TextBack
,
197 MUIA_Text_PreParse
, (IPTR
)"\33r", MUIA_Text_Contents
, (IPTR
)"",
201 Child
, VGroup
, GroupFrameT(_(MSG_VIDEO_FREE
)),
203 Child
, Label(_(MSG_VIDEO_RAM
)),
204 Child
, smdata
->memoryfree
[MEMORY_VRAM
] = TextObject
, TextFrame
, MUIA_Background
, MUII_TextBack
,
205 MUIA_Text_PreParse
, (IPTR
)"\33r", MUIA_Text_Contents
, (IPTR
)"",
207 Child
, Label(_(MSG_GART_APER
)),
208 Child
, smdata
->memoryfree
[MEMORY_GART
] = TextObject
, TextFrame
, MUIA_Background
, MUII_TextBack
,
209 MUIA_Text_PreParse
, (IPTR
)"\33r", MUIA_Text_Contents
, (IPTR
)"",
220 if (!smdata
->application
)
223 DoMethod(smdata
->mainwindow
, MUIM_Notify
, MUIA_Window_CloseRequest
, TRUE
,
224 smdata
->application
, 2, MUIM_Application_ReturnID
, MUIV_Application_ReturnID_Quit
);
226 DoMethod(menuitemfast
, MUIM_Notify
, MUIA_Menuitem_Trigger
, MUIV_EveryTime
,
227 smdata
->tasklist
, 3, MUIM_Set
, MUIA_Tasklist_RefreshMSecs
, MUIV_Tasklist_Refresh_Fast
);
228 DoMethod(menuitemnormal
, MUIM_Notify
, MUIA_Menuitem_Trigger
, MUIV_EveryTime
,
229 smdata
->tasklist
, 3, MUIM_Set
, MUIA_Tasklist_RefreshMSecs
, MUIV_Tasklist_Refresh_Normal
);
230 DoMethod(menuitemslow
, MUIM_Notify
, MUIA_Menuitem_Trigger
, MUIV_EveryTime
,
231 smdata
->tasklist
, 3, MUIM_Set
, MUIA_Tasklist_RefreshMSecs
, MUIV_Tasklist_Refresh_Slow
);
233 DoMethod(smdata
->tasklist
, MUIM_Notify
, MUIA_Tasklist_Refreshed
, TRUE
,
234 smdata
->application
, 2, MUIM_CallHook
, (IPTR
)&smdata
->tasklistrefreshhook
);
237 DoMethod(smdata
->pages
, MUIM_Notify
, MUIA_Group_ActivePage
, MUIV_EveryTime
,
238 smdata
->pages
, 2, MUIM_CallHook
, (IPTR
)&smdata
->pageactivehook
);
241 /* Adding cpu usage gauges */
242 cpucolgroup
= ColGroup(processorcount
+ 2), End
;
244 #if !defined(PROCDISPLAY_USEGAUGE)
245 smdata
->cpureadhooks
= AllocVec(sizeof(struct Hook
) * processorcount
, MEMF_ANY
| MEMF_CLEAR
);
247 #if !defined(PROCDISPLAY_SINGLEGRAPH)
248 smdata
->cpuusagegauges
= AllocVec(sizeof(Object
*) * processorcount
, MEMF_ANY
| MEMF_CLEAR
);
251 DoMethod(cpucolgroup
, OM_ADDMEMBER
, (IPTR
)HVSpace
);
253 #if defined(PROCDISPLAY_SINGLEGRAPH)
254 smdata
->cpuusagegauge
= GraphObject
,
255 MUIA_Graph_InfoText
, (IPTR
) "CPU --\n--.- %",
256 MUIA_Graph_EntryCount
, 10,
257 MUIA_Graph_Max
, 1000,
258 MUIA_Graph_UpdateInterval
, 1000,
262 for (i
= 0; i
< processorcount
; i
++)
264 #if defined(PROCDISPLAY_USEGAUGE)
265 smdata
->cpuusagegauges
[i
] = GaugeObject
,
267 MUIA_Gauge_InfoText
, (IPTR
) "CPU --\n--.- %",
268 MUIA_Gauge_Horiz
, FALSE
, MUIA_Gauge_Current
, 0,
269 MUIA_Gauge_Max
, 1000,
274 #if !defined(PROCDISPLAY_SINGLEGRAPH)
275 smdata
->cpuusagegauges
[i
] = GraphObject
,
276 MUIA_Graph_InfoText
, (IPTR
) "CPU --\n--.- %",
277 MUIA_Graph_EntryCount
, 10,
278 MUIA_Graph_Max
, 1000,
279 MUIA_Graph_UpdateInterval
, 1000,
281 procGuage
= smdata
->cpuusagegauges
[i
];
282 procDataSource
= (APTR
)DoMethod(procGuage
, MUIM_Graph_GetSourceHandle
, 0);
284 procGuage
= smdata
->cpuusagegauge
;
285 procDataSource
= (APTR
)DoMethod(procGuage
, MUIM_Graph_GetSourceHandle
, i
);
287 smdata
->cpureadhooks
[i
].h_Entry
= (APTR
)GraphReadProcessorValueFunc
;
288 smdata
->cpureadhooks
[i
].h_Data
= (APTR
)i
;
290 DoMethod(procGuage
, MUIM_Graph_SetSourceAttrib
, procDataSource
, MUIV_Graph_Source_ReadHook
, &smdata
->cpureadhooks
[i
]);
292 #if !defined(PROCDISPLAY_SINGLEGRAPH)
293 DoMethod(cpucolgroup
, OM_ADDMEMBER
, smdata
->cpuusagegauges
[i
]);
297 DoMethod(cpucolgroup
, OM_ADDMEMBER
, (IPTR
)HVSpace
);
299 DoMethod(cpuusagegroup
, OM_ADDMEMBER
, cpucolgroup
);
301 /* Adding cpu frequency labels */
302 smdata
->cpufreqlabels
= AllocVec(sizeof(Object
*) * processorcount
, MEMF_ANY
| MEMF_CLEAR
);
303 smdata
->cpufreqvalues
= AllocVec(sizeof(Object
*) * processorcount
, MEMF_ANY
| MEMF_CLEAR
);
305 for (i
= 0; i
< processorcount
; i
++)
307 smdata
->cpufreqlabels
[i
] = TextObject
, MUIA_Text_PreParse
, "\33l",
308 MUIA_Text_Contents
, (IPTR
)"", End
;
309 smdata
->cpufreqvalues
[i
] = TextObject
, TextFrame
, MUIA_Background
, MUII_TextBack
,
310 MUIA_Text_PreParse
, (IPTR
)"\33l",
311 MUIA_Text_Contents
, (IPTR
)"", End
;
313 DoMethod(cpufreqgroup
, OM_ADDMEMBER
, smdata
->cpufreqlabels
[i
]);
314 DoMethod(cpufreqgroup
, OM_ADDMEMBER
, smdata
->cpufreqvalues
[i
]);
315 DoMethod(cpufreqgroup
, OM_ADDMEMBER
, (IPTR
)HVSpace
);
321 VOID
DisposeApplication(struct SysMonData
* smdata
)
323 MUI_DisposeObject(smdata
->application
);
325 FreeVec(smdata
->tasklistinfobuf
);
327 FreeVec(smdata
->cpuusagegauges
);
328 FreeVec(smdata
->cpufreqlabels
);
329 FreeVec(smdata
->cpufreqvalues
);
332 VOID
DeInitModules(struct SysMonModule
** modules
, struct SysMonData
*smdata
, LONG lastinitedmodule
)
336 for (i
= lastinitedmodule
; i
>= 0; i
--)
337 modules
[i
]->DeInit(smdata
);
340 LONG
InitModules(struct SysMonModule
** modules
, struct SysMonData
*smdata
)
342 LONG lastinitedmodule
= -1;
344 while(modules
[lastinitedmodule
+ 1] != NULL
)
346 if (modules
[lastinitedmodule
+ 1]->Init(smdata
))
350 DeInitModules(modules
, smdata
, lastinitedmodule
);
355 return lastinitedmodule
;
361 ULONG itercounter
= 0;
362 struct SysMonData smdata
;
363 struct SysMonModule
* modules
[] = {&memorymodule
, &videomodule
, &processormodule
, &timermodule
, NULL
};
364 LONG lastinitedmodule
= -1;
366 if ((lastinitedmodule
= InitModules(modules
, &smdata
)) == -1)
370 if (!CreateApplication(&smdata
))
373 UpdateProcessorStaticInformation(&smdata
);
374 UpdateProcessorInformation(&smdata
);
375 UpdateMemoryStaticInformation(&smdata
);
376 UpdateMemoryInformation(&smdata
);
377 UpdateVideoStaticInformation(&smdata
);
378 UpdateVideoInformation(&smdata
);
380 set(smdata
.mainwindow
, MUIA_Window_Open
, TRUE
);
381 set(smdata
.pages
, MUIA_Group_ActivePage
, 0);
384 while (DoMethod(smdata
.application
, MUIM_Application_NewInput
, &signals
) != MUIV_Application_ReturnID_Quit
)
388 signals
= Wait(signals
| SIGBREAKF_CTRL_C
| GetSIG_TIMER());
389 if (signals
& SIGBREAKF_CTRL_C
)
392 if (signals
& GetSIG_TIMER())
394 IPTR currentPage
= 0;
396 get(smdata
.pages
, MUIA_Group_ActivePage
, ¤tPage
);
400 UpdateProcessorInformation(&smdata
);
403 if ((itercounter
% 8) == 0)
405 UpdateMemoryInformation(&smdata
);
406 UpdateVideoInformation(&smdata
);
420 set(smdata
.mainwindow
, MUIA_Window_Open
, FALSE
);
422 DisposeApplication(&smdata
);
424 DeInitModules(modules
, &smdata
, lastinitedmodule
);