2 Copyright © 2017, The AROS Development Team. All rights reserved.
7 #include <aros/debug.h>
9 #include <proto/utility.h>
10 #include <proto/intuition.h>
11 #include <proto/muimaster.h>
12 #include <proto/processor.h>
14 #include <clib/alib_protos.h>
16 #include <resources/processor.h>
17 #include <zune/graph.h>
19 #include "sysmon_intern.h"
21 #include "processor.h"
23 struct ProcessorGraph_DATA
28 struct Hook
*pg_GraphReadHooks
;
37 #define PROCESSORPEN_COUNT 8
38 struct cpuPen processorPens
[PROCESSORPEN_COUNT
] =
40 { 0x9B9B9B9B, 0xDEDEDEDE, 0xC0C0C0C0 },
41 { 0x9E9E9E9E, 0x9B9B9B9B, 0xDEDEDEDE },
42 { 0xDEDEDEDE, 0x9B9B9B9B, 0xBABABABA },
43 { 0xDEDEDEDE, 0xB5B5B5B5, 0x9B9B9B9B },
44 { 0xDEDEDEDE, 0x9B9B9B9B, 0x9E9E9E9E },
45 { 0xA6A6A6A6, 0xDEDEDEDE, 0x9B9B9B9B },
46 { 0x9B9B9B9B, 0xB2B2B2B2, 0xDEDEDEDE },
47 { 0xE4E4E4E4, 0xEBEBEBEB, 0x2A2A2A2A }
50 #define PROCGF_SINGLE (1 << 1)
52 #define SETUP_PROCGRAPH_INST_DATA struct ProcessorGraph_DATA *data = INST_DATA(CLASS, self)
54 AROS_UFH3(IPTR
, GraphReadProcessorValueFunc
,
55 AROS_UFHA(struct Hook
*, procHook
, A0
),
56 AROS_UFHA(IPTR
*, storage
, A2
),
57 AROS_UFHA(IPTR
, cpuNo
, A1
))
61 struct TagItem tags
[] =
63 { GCIT_SelectedProcessor
, cpuNo
},
64 { GCIT_ProcessorLoad
, (IPTR
)storage
},
65 { TAG_DONE
, TAG_DONE
}
68 D(bug("[SysMon:ProcGraph] %s(%d)\n", __func__
, cpuNo
);)
74 *storage
= ((*storage
>> 16) * 1000) >> 16;
76 D(bug("[SysMon:ProcGraph] %s: 0x%p = %d\n", __func__
, storage
, *storage
);)
83 ULONG
cpusperrow(ULONG x
)
85 register unsigned long op
= x
, res
= 0, one
;
104 Object
*ProcessorGraph__GraphObject()
107 MUIA_Graph_InfoText
, (IPTR
) CPU_DEFSTR
,
108 MUIA_Graph_ValueCeiling
, 1000,
109 MUIA_Graph_ValueStep
, 100,
110 MUIA_Graph_PeriodCeiling
, 100000,
111 MUIA_Graph_PeriodStep
, 10000,
112 MUIA_Graph_PeriodInterval
, 1000,
116 Object
*ProcessorGraph__OM_NEW(Class
*CLASS
, Object
*self
, struct opSet
*message
)
118 BOOL singlemode
= (BOOL
)GetTagData(MUIA_ProcessorGrp_SingleMode
, TRUE
, message
->ops_AttrList
);
119 ULONG processorcount
= (ULONG
)GetTagData(MUIA_ProcessorGrp_CPUCount
, 1, message
->ops_AttrList
);
120 Object
*procGuage
= NULL
;
123 D(bug("[SysMon:ProcGraph] %s()\n", __func__
));
125 if ((singlemode
) || (processorcount
== 1))
127 self
= (Object
*) DoSuperNewTags(CLASS
, self
, NULL
,
128 Child
, (IPTR
)(procGuage
= ProcessorGraph__GraphObject()),
129 TAG_MORE
, (IPTR
) message
->ops_AttrList
134 if (processorcount
<= 4)
135 cpupr
= processorcount
;
136 else if ((cpupr
= cpusperrow(processorcount
)) < 4)
138 if (processorcount
<= 4)
139 cpupr
= processorcount
;
144 self
= (Object
*) DoSuperNewTags(CLASS
, self
, NULL
,
145 MUIA_Group_Columns
, cpupr
,
146 TAG_MORE
, (IPTR
) message
->ops_AttrList
155 SETUP_PROCGRAPH_INST_DATA
;
158 data
->pg_CPUCount
= processorcount
;
159 data
->pg_GraphReadHooks
= AllocVec(sizeof(struct Hook
) * processorcount
, MEMF_ANY
| MEMF_CLEAR
);
161 if ((!singlemode
) && (processorcount
> 1))
162 data
->pg_Graphs
= AllocVec(sizeof(Object
*) * processorcount
, MEMF_ANY
| MEMF_CLEAR
);
165 data
->pg_Graphs
= (Object
**)procGuage
;
166 data
->pg_Flags
|= PROCGF_SINGLE
;
169 for (i
= 0; i
< processorcount
; i
++)
171 if (!(data
->pg_Flags
& PROCGF_SINGLE
))
173 data
->pg_Graphs
[i
] = GraphObject
,
174 MUIA_Graph_InfoText
, (IPTR
) CPU_DEFSTR
,
175 MUIA_Graph_ValueCeiling
, 1000,
176 MUIA_Graph_ValueStep
, 100,
177 MUIA_Graph_PeriodCeiling
, 100000,
178 MUIA_Graph_PeriodStep
, 10000,
179 MUIA_Graph_PeriodInterval
, 1000,
183 procGuage
= data
->pg_Graphs
[i
];
184 procDataSource
= (APTR
)DoMethod(procGuage
, MUIM_Graph_GetSourceHandle
, 0);
186 DoMethod(self
, OM_ADDMEMBER
, procGuage
);
190 procDataSource
= (APTR
)DoMethod(procGuage
, MUIM_Graph_GetSourceHandle
, i
);
191 DoMethod(procGuage
, MUIM_Graph_SetSourceAttrib
, procDataSource
, MUIV_Graph_Source_PenSrc
, &processorPens
[i
% PROCESSORPEN_COUNT
]);
194 data
->pg_GraphReadHooks
[i
].h_Entry
= (APTR
)GraphReadProcessorValueFunc
;
195 data
->pg_GraphReadHooks
[i
].h_Data
= (APTR
)i
;
197 DoMethod(procGuage
, MUIM_Graph_SetSourceAttrib
, procDataSource
, MUIV_Graph_Source_ReadHook
, &data
->pg_GraphReadHooks
[i
]);
199 for (i
%= cpupr
; (i
> 0) && (i
< cpupr
); i
++)
201 DoMethod(self
, OM_ADDMEMBER
, (IPTR
)HVSpace
);
208 IPTR
ProcessorGraph__OM_DISPOSE(Class
*CLASS
, Object
*self
, Msg message
)
210 SETUP_PROCGRAPH_INST_DATA
;
211 BOOL singlemode
= (BOOL
)(data
->pg_Flags
& PROCGF_SINGLE
);
214 D(bug("[SysMon:ProcGraph] %s()\n", __func__
));
216 retVal
= DoSuperMethodA(CLASS
, self
, message
);
218 FreeVec(data
->pg_GraphReadHooks
);
220 FreeVec(data
->pg_Graphs
);
225 IPTR
ProcessorGraph__OM_SET(Class
*CLASS
, Object
*self
, struct opSet
*message
)
227 // SETUP_PROCGRAPH_INST_DATA;
228 struct TagItem
*tstate
= message
->ops_AttrList
, *tag
;
230 D(bug("[SysMon:ProcGraph] %s()\n", __func__
));
232 while ((tag
= NextTagItem((struct TagItem
**)&tstate
)) != NULL
)
238 return DoSuperMethodA(CLASS
, self
, (Msg
) message
);
241 IPTR
ProcessorGraph__OM_GET(Class
*CLASS
, Object
*self
, struct opGet
*message
)
243 SETUP_PROCGRAPH_INST_DATA
;
244 IPTR
*store
= message
->opg_Storage
;
247 D(bug("[SysMon:ProcGraph] %s()\n", __func__
));
249 switch (message
->opg_AttrID
)
251 case MUIA_ProcessorGrp_CPUCount
:
252 *store
= (IPTR
)data
->pg_CPUCount
;
256 case MUIA_ProcessorGrp_SingleMode
:
257 *store
= (IPTR
)((BOOL
)(data
->pg_Flags
& PROCGF_SINGLE
));
263 retval
= DoSuperMethodA(CLASS
, self
, (Msg
) message
);
268 IPTR
ProcessorGraph__MUIM_ProcessorGrp_Update(Class
*CLASS
, Object
*self
, Msg message
)
270 SETUP_PROCGRAPH_INST_DATA
;
275 D(bug("[SysMon:ProcGraph] %s()\n", __func__
));
277 for (i
= 0; i
< data
->pg_CPUCount
; i
++)
280 struct TagItem tags
[] =
282 { GCIT_SelectedProcessor
, (IPTR
)i
},
283 { GCIT_ProcessorLoad
, (IPTR
)&usage
},
284 { TAG_DONE
, TAG_DONE
}
288 usage
= ((usage
>> 16) * 1000) >> 16;
290 if (!(data
->pg_Flags
& PROCGF_SINGLE
))
292 __sprintf(buffer
, "CPU %d\n%d.%d %%", i
, usage
/ 10, usage
% 10);
293 SET(data
->pg_Graphs
[i
], MUIA_Graph_InfoText
, (IPTR
)buffer
);
299 if (data
->pg_Flags
& PROCGF_SINGLE
)
301 totaluse
/= data
->pg_CPUCount
;
302 __sprintf(buffer
, "%d CPU's\n%d.%d %%", data
->pg_CPUCount
, totaluse
/ 10, totaluse
% 10);
303 SET((Object
*)data
->pg_Graphs
, MUIA_Graph_InfoText
, (IPTR
)buffer
);
308 /*** Setup ******************************************************************/
309 PROCESSORGRP_CUSTOMCLASS
311 ProcessorGraph
, NULL
, MUIC_Group
, NULL
,
312 OM_NEW
, struct opSet
*,
314 OM_SET
, struct opSet
*,
315 OM_GET
, struct opGet
*,
316 MUIM_ProcessorGrp_Update
, Msg