wip commit.
[AROS.git] / workbench / system / SysMon / processor_gauge.c
bloba8a36415b12e77185785bfdfea908c16d3974a40
1 /*
2 Copyright © 2017, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #define DEBUG 0
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>
18 #include "sysmon_intern.h"
20 #include "processor.h"
22 struct ProcessorGauge_DATA
24 IPTR pg_CPUCount;
25 Object **pg_Gauges;
28 #define SETUP_PROCGAUGE_INST_DATA struct ProcessorGauge_DATA *data = INST_DATA(CLASS, self)
30 Object *ProcessorGauge__OM_NEW(Class *CLASS, Object *self, struct opSet *message)
32 ULONG processorcount = (ULONG)GetTagData(MUIA_ProcessorGrp_CPUCount, 1, message->ops_AttrList);
34 D(bug("[SysMon:ProcGauge] %s()\n", __func__));
36 self = (Object *) DoSuperNewTags(CLASS, self, NULL,
37 MUIA_Group_Columns, processorcount + 2,
38 TAG_MORE, (IPTR) message->ops_AttrList
41 if (self != NULL)
43 int i;
45 SETUP_PROCGAUGE_INST_DATA;
47 data->pg_CPUCount = processorcount;
48 data->pg_Gauges = AllocMem(sizeof(Object *) * processorcount, MEMF_ANY | MEMF_CLEAR);
50 DoMethod(self, OM_ADDMEMBER, (IPTR)HVSpace);
52 for (i = 0; i < processorcount; i++)
54 data->pg_Gauges[i] = GaugeObject,
55 GaugeFrame,
56 MUIA_Gauge_InfoText, (IPTR) CPU_DEFSTR,
57 MUIA_Gauge_Horiz, FALSE, MUIA_Gauge_Current, 0,
58 MUIA_Gauge_Max, 1000,
59 MUIA_UserData, i,
60 End;
62 DoMethod(self, OM_ADDMEMBER, data->pg_Gauges[i]);
65 DoMethod(self, OM_ADDMEMBER, (IPTR)HVSpace);
68 return self;
71 IPTR ProcessorGauge__OM_DISPOSE(Class *CLASS, Object *self, Msg message)
73 D(bug("[SysMon:ProcGauge] %s()\n", __func__));
75 return DoSuperMethodA(CLASS, self, message);
78 IPTR ProcessorGauge__OM_SET(Class *CLASS, Object *self, struct opSet *message)
80 // SETUP_PROCGAUGE_INST_DATA;
81 struct TagItem *tstate = message->ops_AttrList, *tag;
83 D(bug("[SysMon:ProcGauge] %s()\n", __func__));
85 while ((tag = NextTagItem((struct TagItem **)&tstate)) != NULL)
87 switch (tag->ti_Tag)
91 return DoSuperMethodA(CLASS, self, (Msg) message);
94 IPTR ProcessorGauge__OM_GET(Class *CLASS, Object *self, struct opGet *message)
96 SETUP_PROCGAUGE_INST_DATA;
97 IPTR *store = message->opg_Storage;
98 IPTR retval = 0;
100 D(bug("[SysMon:ProcGauge] %s()\n", __func__));
102 switch (message->opg_AttrID)
104 case MUIA_ProcessorGrp_CPUCount:
105 *store = (IPTR)data->pg_CPUCount;
106 break;
108 case MUIA_ProcessorGrp_SingleMode:
109 *store = (IPTR)FALSE;
110 break;
113 if (!retval)
114 retval = DoSuperMethodA(CLASS, self, (Msg) message);
116 return retval;
119 IPTR ProcessorGauge__MUIM_ProcessorGrp_Update(Class *CLASS, Object *self, Msg message)
121 SETUP_PROCGAUGE_INST_DATA;
122 TEXT buffer[128];
123 ULONG i, usage;
125 D(bug("[SysMon:ProcGauge] %s()\n", __func__));
127 for (i = 0; i < data->pg_CPUCount; i++)
129 #if SIMULATE_USAGE_FREQ
130 struct DateStamp ds;
131 DateStamp(&ds);
132 usage = (ds.ds_Tick * (i + 1)) % 100;
133 #else
134 struct TagItem tags [] =
136 { GCIT_SelectedProcessor, (IPTR)i },
137 { GCIT_ProcessorLoad, (IPTR)&usage },
138 { TAG_DONE, TAG_DONE }
141 usage = 0;
142 GetCPUInfo(tags);
143 usage = ((usage >> 16) * 1000) >> 16;
144 #endif
145 __sprintf(buffer, "CPU %d\n%d.%d %%", i, usage / 10, usage % 10);
146 set(data->pg_Gauges[i], MUIA_Gauge_Current, usage);
147 set(data->pg_Gauges[i], MUIA_Gauge_InfoText, (IPTR)buffer);
149 return 0;
152 /*** Setup ******************************************************************/
153 PROCESSORGRP_CUSTOMCLASS
155 ProcessorGauge, NULL, MUIC_Group, NULL,
156 OM_NEW, struct opSet *,
157 OM_DISPOSE, Msg,
158 OM_SET, struct opSet *,
159 OM_GET, struct opGet *,
160 MUIM_ProcessorGrp_Update, Msg