se the graph to use a fixed number of entries (10) and to run in periodic mode. provi...
[AROS.git] / workbench / system / SysMon / main.c
blob81424722a70438afc5c5ac9ceddae250c04fbf4d
1 /*
2 Copyright 2010-2017, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #define DEBUG 0
7 #include <aros/debug.h>
9 #include <proto/alib.h>
10 #include <proto/muimaster.h>
12 #include <dos/dos.h>
14 #include <zune/graph.h>
16 #include "sysmon_intern.h"
18 #include "locale.h"
20 #define VERSION "$VER: SysMon 1.4 (23.01.2017) ©2011-2017 The AROS Development Team"
22 //#define NOTYET_USED
24 AROS_UFH3(VOID, tasklistrefreshfunction,
25 AROS_UFHA(struct Hook *, h, A0),
26 AROS_UFHA(Object *, object, A2),
27 AROS_UFHA(APTR, msg, A1))
29 AROS_USERFUNC_INIT
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);
43 AROS_USERFUNC_EXIT
46 #ifdef NOTYET_USED
47 AROS_UFH3(VOID, pageactivefunction,
48 AROS_UFHA(struct Hook *, h, A0),
49 AROS_UFHA(Object *, object, A2),
50 AROS_UFHA(APTR, msg, A1))
52 AROS_USERFUNC_INIT
54 IPTR thisPage = 0;
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.
65 AROS_USERFUNC_EXIT
67 #endif
69 BOOL CreateApplication(struct SysMonData * smdata)
71 Object * menuitemfast;
72 Object * menuitemnormal;
73 Object * menuitemslow;
75 Object * cpucolgroup;
76 Object * cpuusagegroup;
77 Object * cpufreqgroup;
79 IPTR i;
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;
92 #ifdef NOTYET_USED
93 smdata->pageactivehook.h_Entry = (APTR)pageactivefunction;
94 smdata->pageactivehook.h_Data = (APTR)smdata;
95 #endif
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),
113 SubWindow,
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),
127 End),
128 End),
129 End),
130 WindowContents,
131 smdata->pages = RegisterGroup(smdata->tabs),
132 Child, (VGroup,
133 Child, ListviewObject,
134 MUIA_Listview_List, (IPTR)smdata->tasklist,
135 End,
136 Child, VGroup,
137 Child, smdata->tasklistinfo = TextObject,
138 NoFrame,
139 MUIA_Font, MUIV_Font_Tiny,
140 MUIA_Text_PreParse, (IPTR)"\33r",
141 MUIA_Text_Contents, (IPTR)_(MSG_TASK_READY_WAIT_INIT),
142 End,
143 End,
144 End),
145 Child, (VGroup,
146 Child, cpuusagegroup = HGroup, GroupFrameT(_(MSG_USAGE)),
147 End,
148 Child, VGroup, GroupFrameT(_(MSG_FREQUENCY)),
149 Child, cpufreqgroup = ColGroup(3),
150 End,
151 End,
152 End),
153 Child, (VGroup,
154 Child, ColGroup(2),
155 Child, VGroup, GroupFrameT(_(MSG_MEMORY_SIZE)),
156 Child, ColGroup(2),
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",
160 End,
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)"",
164 End,
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)"",
168 End,
169 End,
170 End,
171 Child, VGroup, GroupFrameT(_(MSG_MEMORY_FREE)),
172 Child, ColGroup(2),
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",
176 End,
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)"",
180 End,
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)"",
184 End,
185 End,
186 End,
187 End,
188 Child, ColGroup(2),
189 Child, VGroup, GroupFrameT(_(MSG_VIDEO_SIZE)),
190 Child, ColGroup(2),
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)"",
194 End,
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)"",
198 End,
199 End,
200 End,
201 Child, VGroup, GroupFrameT(_(MSG_VIDEO_FREE)),
202 Child, ColGroup(2),
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)"",
206 End,
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)"",
210 End,
211 End,
212 End,
213 End,
214 Child, HVSpace,
215 End),
216 End,
217 End,
218 End;
220 if (!smdata->application)
221 return FALSE;
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);
236 #ifdef NOTYET_USED
237 DoMethod(smdata->pages, MUIM_Notify, MUIA_Group_ActivePage, MUIV_EveryTime,
238 smdata->pages, 2, MUIM_CallHook, (IPTR)&smdata->pageactivehook);
239 #endif
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);
246 #endif
247 #if !defined(PROCDISPLAY_SINGLEGRAPH)
248 smdata->cpuusagegauges = AllocVec(sizeof(Object *) * processorcount, MEMF_ANY | MEMF_CLEAR);
249 #endif
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,
259 End;
260 #endif
262 for (i = 0; i < processorcount; i++)
264 #if defined(PROCDISPLAY_USEGAUGE)
265 smdata->cpuusagegauges[i] = GaugeObject,
266 GaugeFrame,
267 MUIA_Gauge_InfoText, (IPTR) "CPU --\n--.- %",
268 MUIA_Gauge_Horiz, FALSE, MUIA_Gauge_Current, 0,
269 MUIA_Gauge_Max, 1000,
270 End;
271 #else
272 Object *procGuage;
273 APTR procDataSource;
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,
280 End;
281 procGuage = smdata->cpuusagegauges[i];
282 procDataSource = (APTR)DoMethod(procGuage, MUIM_Graph_GetSourceHandle, 0);
283 #else
284 procGuage = smdata->cpuusagegauge;
285 procDataSource = (APTR)DoMethod(procGuage, MUIM_Graph_GetSourceHandle, i);
286 #endif
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]);
291 #endif
292 #if !defined(PROCDISPLAY_SINGLEGRAPH)
293 DoMethod(cpucolgroup, OM_ADDMEMBER, smdata->cpuusagegauges[i]);
294 #endif
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);
318 return TRUE;
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)
334 LONG i;
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))
347 lastinitedmodule++;
348 else
350 DeInitModules(modules, smdata, lastinitedmodule);
351 return -1;
355 return lastinitedmodule;
358 int main()
360 ULONG signals = 0;
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)
367 return 1;
370 if (!CreateApplication(&smdata))
371 return 1;
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);
382 SignalMeAfter(250);
384 while (DoMethod(smdata.application, MUIM_Application_NewInput, &signals) != MUIV_Application_ReturnID_Quit)
386 if (signals)
388 signals = Wait(signals | SIGBREAKF_CTRL_C | GetSIG_TIMER());
389 if (signals & SIGBREAKF_CTRL_C)
390 break;
392 if (signals & GetSIG_TIMER())
394 IPTR currentPage = 0;
396 get(smdata.pages, MUIA_Group_ActivePage, &currentPage);
397 switch (currentPage)
399 case 1:
400 UpdateProcessorInformation(&smdata);
401 break;
402 case 2:
403 if ((itercounter % 8) == 0)
405 UpdateMemoryInformation(&smdata);
406 UpdateVideoInformation(&smdata);
408 break;
409 default:
410 break;
413 itercounter++;
415 SignalMeAfter(250);
420 set(smdata.mainwindow, MUIA_Window_Open, FALSE);
422 DisposeApplication(&smdata);
424 DeInitModules(modules, &smdata, lastinitedmodule);
426 return 0;