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.9 (26.02.2017) ©2011-2017 The AROS Development Team"
22 CONST_STRPTR CPU_DEFSTR
= "CPU --\n--.- %";
26 AROS_UFH3(VOID
, tasklistrefreshfunction
,
27 AROS_UFHA(struct Hook
*, h
, A0
),
28 AROS_UFHA(Object
*, object
, A2
),
29 AROS_UFHA(APTR
, msg
, A1
))
33 struct SysMonData
* smdata
= h
->h_Data
;
34 IPTR taskReady
= 0, taskWait
= 0;
36 D(bug("[SysMon] %s(0x%p)\n", __func__
, object
));
38 GET(smdata
->tasklist
, MUIA_Tasklist_ReadyCount
, &taskReady
);
39 GET(smdata
->tasklist
, MUIA_Tasklist_WaitingCount
, &taskWait
);
41 __sprintf(smdata
->tasklistinfobuf
, smdata
->msg_taskreadywait
, taskReady
, taskWait
);
43 set(smdata
->tasklistinfo
, MUIA_Text_Contents
, smdata
->tasklistinfobuf
);
49 AROS_UFH3(VOID
, pageactivefunction
,
50 AROS_UFHA(struct Hook
*, h
, A0
),
51 AROS_UFHA(Object
*, object
, A2
),
52 AROS_UFHA(APTR
, msg
, A1
))
58 D(bug("[SysMon] %s(0x%p)\n", __func__
, object
));
60 // get the selected page
61 get(object
, MUIA_Group_ActivePage
, &thisPage
);
63 D(bug("[SysMon] page #%d\n", thisPage
));
65 // TODO: change the menu for the active page.
71 BOOL
CreateApplication(struct SysMonData
* smdata
)
73 Object
* menuitemfast
,
78 * cmenucpugraphpcpu
= NULL
;
80 Object
* cpufreqgroup
,
86 processorcount
= GetProcessorCount();
88 smdata
->tabs
[0] = _(MSG_TAB_TASKS
);
89 smdata
->tabs
[1] = _(MSG_TAB_CPU
);
90 smdata
->tabs
[2] = _(MSG_TAB_SYSTEM
);
91 smdata
->tabs
[3] = NULL
;
93 smdata
->tasklistinfobuf
= AllocVec(30, MEMF_PUBLIC
);
94 smdata
->tasklistrefreshhook
.h_Entry
= (APTR
)tasklistrefreshfunction
;
95 smdata
->tasklistrefreshhook
.h_Data
= (APTR
)smdata
;
98 smdata
->pageactivehook
.h_Entry
= (APTR
)pageactivefunction
;
99 smdata
->pageactivehook
.h_Data
= (APTR
)smdata
;
102 smdata
->msg_taskreadywait
= (STRPTR
)_(MSG_TASK_READY_WAIT
);
103 smdata
->msg_project
= (STRPTR
)_(MSG_PROJECT
);
104 smdata
->msg_refresh_speed
= (STRPTR
)_(MSG_REFRESH_SPEED
);
105 smdata
->msg_fast
= (STRPTR
)_(MSG_FAST
);
106 smdata
->msg_normal
= (STRPTR
)_(MSG_NORMAL
);
107 smdata
->msg_slow
= (STRPTR
)_(MSG_SLOW
);
109 smdata
->tasklist
= (Object
*)NewObject(Tasklist_CLASS
->mcc_Class
, NULL
, MUIA_Tasklist_RefreshMSecs
, MUIV_Tasklist_Refresh_Normal
, TAG_DONE
);
111 /* prepare the cpu frequency group */
112 cpufreqgroup
= ColGroup(4),
115 /* If we have more than 3 processors,
117 if (processorcount
<= 4)
119 cpufreqcntnr
= GroupObject
,
120 GroupFrameT(_(MSG_FREQUENCY
)),
126 cpufreqcntnr
= ScrollgroupObject
,
127 GroupFrameT(_(MSG_FREQUENCY
)),
128 MUIA_Scrollgroup_FreeHoriz
, FALSE
,
129 MUIA_Scrollgroup_Contents
, VirtgroupObject
,
135 smdata
->application
= ApplicationObject
,
136 MUIA_Application_Title
, __(MSG_APP_NAME
),
137 MUIA_Application_Version
, (IPTR
) VERSION
,
138 MUIA_Application_Author
, (IPTR
) "Krzysztof Smiechowicz",
139 MUIA_Application_Copyright
, (IPTR
)"©2011-2017, The AROS Development Team",
140 MUIA_Application_Base
, (IPTR
)"SYSMON",
141 MUIA_Application_Description
, __(MSG_APP_TITLE
),
143 smdata
->mainwindow
= WindowObject
,
144 MUIA_Window_Title
, __(MSG_WINDOW_TITLE
),
145 MUIA_Window_ID
, MAKE_ID('S','Y','S','M'),
146 MUIA_Window_Height
, MUIV_Window_Height_Visible(45),
147 MUIA_Window_Width
, MUIV_Window_Width_Visible(35),
148 MUIA_Window_Menustrip
, (MenustripObject
,
149 MUIA_Family_Child
, (MenuObject
,
150 MUIA_Menu_Title
, (IPTR
)smdata
->msg_project
,
151 MUIA_Family_Child
, (MenuitemObject
,
152 MUIA_Menuitem_Title
, (IPTR
)smdata
->msg_refresh_speed
,
153 MUIA_Family_Child
, (menuitemfast
= MenuitemObject
, MUIA_Menuitem_Title
, (IPTR
)smdata
->msg_fast
, MUIA_Menuitem_Shortcut
, (IPTR
)"F",End
),
154 MUIA_Family_Child
, (menuitemnormal
= MenuitemObject
, MUIA_Menuitem_Title
, (IPTR
)smdata
->msg_normal
, MUIA_Menuitem_Shortcut
, (IPTR
)"N",End
),
155 MUIA_Family_Child
, (menuitemslow
= MenuitemObject
, MUIA_Menuitem_Title
, (IPTR
)smdata
->msg_slow
, MUIA_Menuitem_Shortcut
, (IPTR
)"S",End
),
160 smdata
->pages
= RegisterGroup(smdata
->tabs
),
162 Child
, ListviewObject
,
163 MUIA_Listview_List
, (IPTR
)smdata
->tasklist
,
166 Child
, smdata
->tasklistinfo
= TextObject
,
168 MUIA_Font
, MUIV_Font_Tiny
,
169 MUIA_Text_PreParse
, (IPTR
)"\33r",
170 MUIA_Text_Contents
, (IPTR
)_(MSG_TASK_READY_WAIT_INIT
),
175 Child
, (smdata
->cpuusagegroup
= HGroup
,
176 GroupFrameT(_(MSG_USAGE
)),
177 MUIA_ContextMenu
, (MenustripObject
,
178 MUIA_Family_Child
, (MenuObject
,
179 MUIA_Menu_Title
, (IPTR
)"Processor Load",
180 MUIA_Family_Child
, (MenuitemObject
,
181 MUIA_Menuitem_Title
, (IPTR
)"Display Mode",
182 MUIA_Family_Child
, (cmenucpugauge
= MenuitemObject
, MUIA_Menuitem_Title
, (IPTR
)"Gauge", MUIA_Menuitem_Shortcut
, (IPTR
)"G",End
),
183 MUIA_Family_Child
, (cmenucpugraph
= MenuitemObject
, MUIA_Menuitem_Title
, (IPTR
)"Graph", MUIA_Menuitem_Shortcut
, (IPTR
)"S",End
),
184 (processorcount
> 1) ? MUIA_Family_Child
: TAG_IGNORE
,
185 (cmenucpugraphpcpu
= MenuitemObject
, MUIA_Menuitem_Title
, (IPTR
)"Graph Per Processor", MUIA_Menuitem_Shortcut
, (IPTR
)"P",End
),
189 Child
, (IPTR
)(smdata
->cpuusageobj
= ProcessorGroupObject(smdata
, processorcount
)),
191 Child
, BalanceObject
, End
,
196 Child
, VGroup
, GroupFrameT(_(MSG_MEMORY_SIZE
)),
198 Child
, Label(_(MSG_TOTAL_RAM
)),
199 Child
, smdata
->memorysize
[MEMORY_RAM
] = TextObject
, TextFrame
, MUIA_Background
, MUII_TextBack
,
200 MUIA_Text_PreParse
, (IPTR
)"\33r", MUIA_Text_Contents
, (IPTR
)"---- Kb",
202 Child
, Label(_(MSG_CHIP_RAM
)),
203 Child
, smdata
->memorysize
[MEMORY_CHIP
] = TextObject
, TextFrame
, MUIA_Background
, MUII_TextBack
,
204 MUIA_Text_PreParse
, (IPTR
)"\33r", MUIA_Text_Contents
, (IPTR
)"",
206 Child
, Label(_(MSG_FAST_RAM
)),
207 Child
, smdata
->memorysize
[MEMORY_FAST
] = TextObject
, TextFrame
, MUIA_Background
, MUII_TextBack
,
208 MUIA_Text_PreParse
, (IPTR
)"\33r", MUIA_Text_Contents
, (IPTR
)"",
212 Child
, VGroup
, GroupFrameT(_(MSG_MEMORY_FREE
)),
214 Child
, Label(_(MSG_TOTAL_RAM
)),
215 Child
, smdata
->memoryfree
[MEMORY_RAM
] = TextObject
, TextFrame
, MUIA_Background
, MUII_TextBack
,
216 MUIA_Text_PreParse
, (IPTR
)"\33r", MUIA_Text_Contents
, (IPTR
)"---- Kb",
218 Child
, Label(_(MSG_CHIP_RAM
)),
219 Child
, smdata
->memoryfree
[MEMORY_CHIP
] = TextObject
, TextFrame
, MUIA_Background
, MUII_TextBack
,
220 MUIA_Text_PreParse
, (IPTR
)"\33r", MUIA_Text_Contents
, (IPTR
)"",
222 Child
, Label(_(MSG_FAST_RAM
)),
223 Child
, smdata
->memoryfree
[MEMORY_FAST
] = TextObject
, TextFrame
, MUIA_Background
, MUII_TextBack
,
224 MUIA_Text_PreParse
, (IPTR
)"\33r", MUIA_Text_Contents
, (IPTR
)"",
230 Child
, VGroup
, GroupFrameT(_(MSG_VIDEO_SIZE
)),
232 Child
, Label(_(MSG_VIDEO_RAM
)),
233 Child
, smdata
->memorysize
[MEMORY_VRAM
] = TextObject
, TextFrame
, MUIA_Background
, MUII_TextBack
,
234 MUIA_Text_PreParse
, (IPTR
)"\33r", MUIA_Text_Contents
, (IPTR
)"",
236 Child
, Label(_(MSG_GART_APER
)),
237 Child
, smdata
->memorysize
[MEMORY_GART
] = TextObject
, TextFrame
, MUIA_Background
, MUII_TextBack
,
238 MUIA_Text_PreParse
, (IPTR
)"\33r", MUIA_Text_Contents
, (IPTR
)"",
242 Child
, VGroup
, GroupFrameT(_(MSG_VIDEO_FREE
)),
244 Child
, Label(_(MSG_VIDEO_RAM
)),
245 Child
, smdata
->memoryfree
[MEMORY_VRAM
] = TextObject
, TextFrame
, MUIA_Background
, MUII_TextBack
,
246 MUIA_Text_PreParse
, (IPTR
)"\33r", MUIA_Text_Contents
, (IPTR
)"",
248 Child
, Label(_(MSG_GART_APER
)),
249 Child
, smdata
->memoryfree
[MEMORY_GART
] = TextObject
, TextFrame
, MUIA_Background
, MUII_TextBack
,
250 MUIA_Text_PreParse
, (IPTR
)"\33r", MUIA_Text_Contents
, (IPTR
)"",
261 if (!smdata
->application
)
264 DoMethod(smdata
->mainwindow
, MUIM_Notify
, MUIA_Window_CloseRequest
, TRUE
,
265 smdata
->application
, 2, MUIM_Application_ReturnID
, MUIV_Application_ReturnID_Quit
);
267 DoMethod(menuitemfast
, MUIM_Notify
, MUIA_Menuitem_Trigger
, MUIV_EveryTime
,
268 smdata
->tasklist
, 3, MUIM_Set
, MUIA_Tasklist_RefreshMSecs
, MUIV_Tasklist_Refresh_Fast
);
269 DoMethod(menuitemnormal
, MUIM_Notify
, MUIA_Menuitem_Trigger
, MUIV_EveryTime
,
270 smdata
->tasklist
, 3, MUIM_Set
, MUIA_Tasklist_RefreshMSecs
, MUIV_Tasklist_Refresh_Normal
);
271 DoMethod(menuitemslow
, MUIM_Notify
, MUIA_Menuitem_Trigger
, MUIV_EveryTime
,
272 smdata
->tasklist
, 3, MUIM_Set
, MUIA_Tasklist_RefreshMSecs
, MUIV_Tasklist_Refresh_Slow
);
274 DoMethod(smdata
->tasklist
, MUIM_Notify
, MUIA_Tasklist_Refreshed
, TRUE
,
275 smdata
->application
, 2, MUIM_CallHook
, (IPTR
)&smdata
->tasklistrefreshhook
);
278 DoMethod(smdata
->pages
, MUIM_Notify
, MUIA_Group_ActivePage
, MUIV_EveryTime
,
279 smdata
->pages
, 2, MUIM_CallHook
, (IPTR
)&smdata
->pageactivehook
);
282 smdata
->cpuusagecmhooks
[0].h_Entry
= (APTR
)processorgaugehookfunc
;
283 smdata
->cpuusagecmhooks
[0].h_Data
= (APTR
)smdata
;
284 smdata
->cpuusagecmhooks
[1].h_Entry
= (APTR
)processorgraphhookfunc
;
285 smdata
->cpuusagecmhooks
[1].h_Data
= (APTR
)smdata
;
287 DoMethod(cmenucpugauge
, MUIM_Notify
, MUIA_Menuitem_Trigger
, MUIV_EveryTime
,
288 smdata
->application
, 5, MUIM_Application_PushMethod
,
289 smdata
->application
, 2, MUIM_CallHook
, (IPTR
)&smdata
->cpuusagecmhooks
[0]);
290 DoMethod(cmenucpugraph
, MUIM_Notify
, MUIA_Menuitem_Trigger
, MUIV_EveryTime
,
291 smdata
->application
, 5, MUIM_Application_PushMethod
,
292 smdata
->application
, 2, MUIM_CallHook
, (IPTR
)&smdata
->cpuusagecmhooks
[1]);
293 if (cmenucpugraphpcpu
)
295 smdata
->cpuusagecmhooks
[2].h_Entry
= (APTR
)processorgraphpercpuhookfunc
;
296 smdata
->cpuusagecmhooks
[2].h_Data
= (APTR
)smdata
;
298 DoMethod(cmenucpugraphpcpu
, MUIM_Notify
, MUIA_Menuitem_Trigger
, MUIV_EveryTime
,
299 smdata
->application
, 5, MUIM_Application_PushMethod
,
300 smdata
->application
, 2, MUIM_CallHook
, (IPTR
)&smdata
->cpuusagecmhooks
[2]);
303 /* Adding cpu frequency labels */
304 smdata
->cpufreqlabels
= AllocVec(sizeof(Object
*) * processorcount
, MEMF_ANY
| MEMF_CLEAR
);
305 smdata
->cpufreqvalues
= AllocVec(sizeof(Object
*) * processorcount
, MEMF_ANY
| MEMF_CLEAR
);
307 for (i
= 0; i
< processorcount
; i
++)
309 smdata
->cpufreqlabels
[i
] = TextObject
, MUIA_Text_PreParse
, "\33l",
310 MUIA_Text_Contents
, (IPTR
)"", End
;
311 smdata
->cpufreqvalues
[i
] = TextObject
, TextFrame
, MUIA_Background
, MUII_TextBack
,
312 MUIA_Text_PreParse
, (IPTR
)"\33l",
313 MUIA_Text_Contents
, (IPTR
)"", End
;
315 DoMethod(cpufreqgroup
, OM_ADDMEMBER
, (IPTR
)HVSpace
);
316 DoMethod(cpufreqgroup
, OM_ADDMEMBER
, smdata
->cpufreqlabels
[i
]);
317 DoMethod(cpufreqgroup
, OM_ADDMEMBER
, smdata
->cpufreqvalues
[i
]);
318 DoMethod(cpufreqgroup
, OM_ADDMEMBER
, (IPTR
)HVSpace
);
320 DoMethod(cpufreqgroup
, OM_ADDMEMBER
, (IPTR
)HVSpace
);
321 DoMethod(cpufreqgroup
, OM_ADDMEMBER
, (IPTR
)HVSpace
);
322 DoMethod(cpufreqgroup
, OM_ADDMEMBER
, (IPTR
)HVSpace
);
323 DoMethod(cpufreqgroup
, OM_ADDMEMBER
, (IPTR
)HVSpace
);
328 VOID
DisposeApplication(struct SysMonData
* smdata
)
330 MUI_DisposeObject(smdata
->application
);
332 FreeVec(smdata
->tasklistinfobuf
);
333 FreeVec(smdata
->cpufreqlabels
);
334 FreeVec(smdata
->cpufreqvalues
);
337 VOID
DeInitModules(struct SysMonModule
** modules
, struct SysMonData
*smdata
, LONG lastinitedmodule
)
341 for (i
= lastinitedmodule
; i
>= 0; i
--)
342 modules
[i
]->DeInit(smdata
);
345 LONG
InitModules(struct SysMonModule
** modules
, struct SysMonData
*smdata
)
347 LONG lastinitedmodule
= -1;
349 /* Make sure we initialize values ..*/
350 smdata
->cpuusageclass
= NULL
;
352 while(modules
[lastinitedmodule
+ 1] != NULL
)
354 if (modules
[lastinitedmodule
+ 1]->Init(smdata
))
358 DeInitModules(modules
, smdata
, lastinitedmodule
);
363 return lastinitedmodule
;
369 ULONG itercounter
= 0;
370 struct SysMonData smdata
;
371 struct SysMonModule
* modules
[] = {&memorymodule
, &videomodule
, &processormodule
, &timermodule
, NULL
};
372 LONG lastinitedmodule
= -1;
374 if ((lastinitedmodule
= InitModules(modules
, &smdata
)) == -1)
377 if (!CreateApplication(&smdata
))
380 /* Increase our priority! */
381 SetTaskPri(FindTask(NULL
), 19);
383 UpdateProcessorStaticInformation(&smdata
);
384 UpdateProcessorInformation(&smdata
);
385 UpdateMemoryStaticInformation(&smdata
);
386 UpdateMemoryInformation(&smdata
);
387 UpdateVideoStaticInformation(&smdata
);
388 UpdateVideoInformation(&smdata
);
390 set(smdata
.mainwindow
, MUIA_Window_Open
, TRUE
);
391 set(smdata
.pages
, MUIA_Group_ActivePage
, 0);
394 while (DoMethod(smdata
.application
, MUIM_Application_NewInput
, &signals
) != MUIV_Application_ReturnID_Quit
)
398 signals
= Wait(signals
| SIGBREAKF_CTRL_C
| GetSIG_TIMER());
399 if (signals
& SIGBREAKF_CTRL_C
)
402 if (signals
& GetSIG_TIMER())
404 IPTR currentPage
= 0;
406 get(smdata
.pages
, MUIA_Group_ActivePage
, ¤tPage
);
410 UpdateProcessorInformation(&smdata
);
413 if ((itercounter
% 8) == 0)
415 UpdateMemoryInformation(&smdata
);
416 UpdateVideoInformation(&smdata
);
430 set(smdata
.mainwindow
, MUIA_Window_Open
, FALSE
);
432 DisposeApplication(&smdata
);
434 DeInitModules(modules
, &smdata
, lastinitedmodule
);