Changeset 25
- Timestamp:
- Dec 25, 2004, 6:43:07 PM (19 years ago)
- Location:
- trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MacFaceFloat/MainForm.cs
r22 r25 31 31 private FaceDef _currentFaceDef; 32 32 private Configuration _config; 33 34 int prevUsage;35 int prevMarkers;36 PerformanceCounter cpuCount; 37 PerformanceCounter pageoutCount;38 PerformanceCounter pageinCount;33 34 private int prevPattern; 35 private int prevMarkers; 36 37 private CPUUsageCounter cpuCounter; 38 private MemoryUsageCounter memoryCounter; 39 39 40 40 // RXgN^ … … 45 45 this.MoveAtFormDrag = true; 46 46 47 prev Usage= -1;47 prevPattern = -1; 48 48 prevMarkers = -1; 49 49 50 cpuCount = new PerformanceCounter(); 51 cpuCount.CategoryName = "Processor"; 52 cpuCount.CounterName = "% Processor Time"; 53 cpuCount.InstanceName = "_Total"; 54 55 pageoutCount = new PerformanceCounter(); 56 pageoutCount.CategoryName = "Memory"; 57 pageoutCount.CounterName = "Pages Output/sec"; 58 59 pageinCount = new PerformanceCounter(); 60 pageinCount.CategoryName = "Memory"; 61 pageinCount.CounterName = "Pages Input/sec"; 50 cpuCounter = new CPUUsageCounter(); 51 memoryCounter = new MemoryUsageCounter(); 62 52 63 53 _updateTimer = new System.Windows.Forms.Timer(); … … 203 193 _facePath = _currentFaceDef.Path; 204 194 notifyIcon.Text = "MacFace - " + _currentFaceDef.Title; 205 prev Usage= -1;195 prevPattern = -1; 206 196 prevMarkers = -1; 207 197 … … 214 204 public void CountProcessorUsage(object sender, EventArgs e) 215 205 { 216 int usage = (int)cpuCount.NextValue(); 217 int pagein = (int)pageinCount.NextValue(); 218 int pageout = (int)pageoutCount.NextValue(); 219 220 usage /= 10; 221 if (usage > 10) { 222 usage = 10; 223 } else if (usage < 0) { 224 usage = 0; 206 CPUUsage cpuUsage = cpuCounter.CurrentUsage(); 207 MemoryUsage memUsage = memoryCounter.CurrentUsage(); 208 209 int pattern = cpuUsage.Active / 10; 210 if (pattern > 10) 211 { 212 pattern = 10; 213 } 214 else if (pattern < 0) 215 { 216 pattern = 0; 225 217 } 226 218 227 219 int markers = FaceDef.MarkerNone; 220 int pagein = memUsage.Pagein; 221 int pageout = memUsage.Pageout; 228 222 if (pagein > 0) markers += FaceDef.MarkerPageIn; 229 223 if (pageout > 0) markers += FaceDef.MarkerPageOut; 230 224 231 if (prev Usage != usage|| prevMarkers != markers)225 if (prevPattern != pattern || prevMarkers != markers) 232 226 { 233 227 Graphics g = this.Graphics; 234 228 g.Clear(Color.FromArgb(0, 0, 0, 0)); 235 _currentFaceDef.DrawPatternImage(g, FaceDef.PatternSuite.Normal, usage, markers);229 _currentFaceDef.DrawPatternImage(g, FaceDef.PatternSuite.Normal, pattern, markers); 236 230 this.Update(); 237 231 } 238 232 239 prev Usage = usage;233 prevPattern = pattern; 240 234 prevMarkers = markers; 241 235 } -
trunk/MacFaceLibrary/CPUUsage.cs
r24 r25 11 11 public class CPUUsage 12 12 { 13 public CPUUsage() 13 private int user; 14 private int system; 15 private int idle; 16 17 public CPUUsage(int user, int system, int idle) 14 18 { 15 // 16 // TODO: RXgN^ WbNð±±ÉÇÁµÄ¾³¢B 17 // 19 this.user = user; 20 this.system = system; 21 this.idle = idle; 22 } 23 24 public int User 25 { 26 get { return user; } 27 } 28 29 public int System 30 { 31 get { return user; } 32 } 33 34 public int Active 35 { 36 get { return user + system; } 37 } 38 39 public int Idle 40 { 41 get { return idle; } 18 42 } 19 43 } -
trunk/MacFaceLibrary/CPUUsageCounter.cs
r24 r25 3 3 */ 4 4 using System; 5 using System.Diagnostics; 5 6 6 7 namespace MacFace … … 9 10 /// HostStatistics ÌTvÌà¾Å·B 10 11 /// </summary> 11 public class HostStatistics12 public class CPUUsageCounter 12 13 { 13 public HostStatistics() 14 private PerformanceCounter userCounter; 15 private PerformanceCounter systemCounter; 16 private PerformanceCounter idleCounter; 17 18 public CPUUsageCounter() 14 19 { 15 // 16 // TODO: RXgN^ WbNð±±ÉÇÁµÄ¾³¢B 17 // 20 userCounter = new PerformanceCounter(); 21 userCounter.CategoryName = "Processor"; 22 userCounter.CounterName = "% User Time"; 23 userCounter.InstanceName = "_Total"; 24 25 systemCounter = new PerformanceCounter(); 26 systemCounter.CategoryName = "Processor"; 27 systemCounter.CounterName = "% Privileged Time"; 28 systemCounter.InstanceName = "_Total"; 29 30 idleCounter = new PerformanceCounter(); 31 idleCounter.CategoryName = "Processor"; 32 idleCounter.CounterName = "% Idle Time"; 33 idleCounter.InstanceName = "_Total"; 18 34 } 35 36 public CPUUsage CurrentUsage() 37 { 38 int user = (int)userCounter.NextValue(); 39 int system = (int)systemCounter.NextValue(); 40 int idle = (int)idleCounter.NextValue(); 41 42 return new CPUUsage(user, system, idle); 43 } 44 19 45 } 20 46 } 21 22 /*23 24 typedef struct {25 int freePages;26 int activePages;27 int inactivePages;28 int wirePages;29 int faults;30 int pageins;31 int pageouts;32 unsigned long userTicks;33 unsigned long systemTicks;34 unsigned long idleTicks;35 unsigned long niceTicks;36 } HostStatData;37 38 typedef struct {39 int incount;40 int outcount;41 } Pageio;42 43 typedef struct {44 float user;45 float system;46 float idle;47 float nice;48 } CPUUsage;49 50 typedef struct {51 HostStatData stat;52 Pageio pageio;53 CPUUsage usage;54 } StatisticsRecord;55 56 @interface HostStatistics : NSObject57 {58 StatisticsRecord *ringBuffer;59 int bufMaxLen;60 int bufHead;61 int bufTail;62 int bufLen;63 int totalPages;64 int minUsedPages;65 int maxUsedPages;66 }67 68 + (unsigned int)vmPageSize;69 + (NSString*)kernelVersion;70 + (void)getStatistics:(HostStatData*)data;71 72 - (id)initWithCapacity:(unsigned)capacity;73 - (void)update;74 - (int)totalPages;75 - (int)minUsedPages;76 - (int)maxUsedPages;77 - (int)length;78 - (const StatisticsRecord*)indexAt:(unsigned)index;79 - (const StatisticsRecord*)head;80 - (const StatisticsRecord*)tail;81 @end82 83 #import <mach/mach.h>84 #import <mach/mach_types.h>85 #import "HostStatistics.h"86 87 //88 //89 static void hostStatistics(HostStatData *data)90 {91 vm_statistics_data_t vm_stat;92 mach_msg_type_number_t vm_count = HOST_VM_INFO_COUNT;93 host_cpu_load_info_data_t load_info;94 mach_msg_type_number_t load_info_count = HOST_CPU_LOAD_INFO_COUNT;95 host_t host = mach_host_self();96 97 host_statistics(host,HOST_VM_INFO,(host_info_t)&vm_stat, &vm_count);98 host_statistics(host,HOST_CPU_LOAD_INFO,(host_info_t)&load_info, &load_info_count);99 100 data->freePages = vm_stat.free_count;101 data->activePages = vm_stat.active_count;102 data->inactivePages = vm_stat.inactive_count;103 data->wirePages = vm_stat.wire_count;104 data->faults = vm_stat.faults;105 data->pageins = vm_stat.pageins;106 data->pageouts = vm_stat.pageouts;107 108 data->userTicks = load_info.cpu_ticks[CPU_STATE_USER];109 data->systemTicks = load_info.cpu_ticks[CPU_STATE_SYSTEM];110 data->idleTicks = load_info.cpu_ticks[CPU_STATE_IDLE];111 data->niceTicks = load_info.cpu_ticks[CPU_STATE_NICE];112 }113 114 @implementation HostStatistics115 116 //117 // ¼zL¯Ìy[WTCYðÔ·118 //119 + (unsigned int)vmPageSize120 {121 vm_size_t page_size;122 host_page_size(mach_host_self(),&page_size);123 return page_size;124 }125 126 //127 // J[lÌo[W¶ñðÔ·128 //129 + (NSString*)kernelVersion130 {131 kernel_version_t kver;132 host_kernel_version(mach_host_self(),kver);133 return [NSString stringWithUTF8String:kver];134 }135 136 //137 // »ÝÌvîñðÝè·é138 //139 + (void)getStatistics:(HostStatData*)data140 {141 hostStatistics(data);142 }143 144 //145 // ú»146 // capacity: Oobt@ÌeÊ147 //148 - (id)initWithCapacity:(unsigned)capacity149 {150 StatisticsRecord *rec;151 152 ringBuffer = calloc(sizeof(StatisticsRecord),capacity);153 rec = &ringBuffer[0];154 hostStatistics(&rec->stat);155 rec->usage.user = 0;156 rec->usage.system = 0;157 rec->usage.idle = 100.0;158 rec->usage.nice = 0;159 160 bufMaxLen = capacity;161 bufHead = 0;162 bufTail = 0;163 bufLen = 1;164 165 totalPages = rec->stat.wirePages + rec->stat.activePages + rec->stat.inactivePages + rec->stat.freePages;166 minUsedPages = rec->stat.wirePages + rec->stat.activePages;167 maxUsedPages = minUsedPages;168 169 return self;170 }171 172 //173 // ãn174 //175 - (void)dealloc176 {177 free(ringBuffer);178 [super dealloc];179 }180 181 //182 // ðÌXV183 //184 - (void)update185 {186 StatisticsRecord *rec, *lastRec;187 int user,sys,idle,nice,total;188 int usedPages;189 190 lastRec = &ringBuffer[bufHead];191 if (bufLen < bufMaxLen) bufLen++;192 if (++bufHead >= bufLen) bufHead = 0;193 if (bufHead == bufTail)194 if (++bufTail >= bufLen) bufTail = 0;195 rec = &ringBuffer[bufHead];196 hostStatistics(&rec->stat);197 198 rec->pageio.incount = rec->stat.pageins - lastRec->stat.pageins;199 rec->pageio.outcount = rec->stat.pageouts - lastRec->stat.pageouts;200 201 user = rec->stat.userTicks - lastRec->stat.userTicks;202 sys = rec->stat.systemTicks - lastRec->stat.systemTicks;203 idle = rec->stat.idleTicks - lastRec->stat.idleTicks;204 nice = rec->stat.niceTicks - lastRec->stat.niceTicks;205 total = user + sys + idle + nice;206 207 if (total > 0) {208 rec->usage.user = user * 100.0 / total;209 rec->usage.system = sys * 100.0 / total;210 rec->usage.idle = idle * 100.0 / total;211 rec->usage.nice = nice * 100.0 / total;212 } else {213 rec->usage = lastRec->usage;214 }215 216 usedPages = rec->stat.wirePages + rec->stat.activePages;217 if( minUsedPages < usedPages) minUsedPages = usedPages;218 if( maxUsedPages > usedPages) maxUsedPages = usedPages;219 }220 221 - (int)totalPages { return totalPages; }222 - (int)minUsedPages { return minUsedPages; }223 - (int)maxUsedPages { return maxUsedPages; }224 - (int)length { return bufLen; }225 226 //227 // wèµ½ÊuÌvîñð¾é228 // index: Êu(ÅVª0)229 //230 - (const StatisticsRecord*)indexAt:(unsigned)index;231 {232 if (index >= bufLen) return nil;233 index = (index <= bufHead) ? bufHead - index : bufLen + bufHead - index;234 return &ringBuffer[index];235 }236 237 //238 // àÁÆàVµ¢vîñðÔ·239 //240 - (const StatisticsRecord*)head241 {242 return &ringBuffer[bufHead];243 }244 245 //246 // àÁÆàâvîñðÔ·247 //248 - (const StatisticsRecord*)tail;249 {250 return &ringBuffer[bufTail];251 }252 253 @end254 255 */ -
trunk/MacFaceLibrary/MemoryUsage.cs
r24 r25 11 11 public class MemoryUsage 12 12 { 13 public MemoryUsage() 13 private int available; 14 private int committed; 15 private int pagein; 16 private int pageout; 17 18 public MemoryUsage(int available, int committed, int pagein, int pageout) 14 19 { 15 // 16 // TODO: RXgN^ WbNð±±ÉÇÁµÄ¾³¢B 17 // 20 this.available = available; 21 this.committed = committed; 22 this.pagein = pagein; 23 this.pageout = pageout; 24 } 25 26 public int Available 27 { 28 get { return available; } 29 } 30 31 public int Committed 32 { 33 get { return committed; } 34 } 35 36 public int Pagein 37 { 38 get { return pagein; } 39 } 40 41 public int Pageout 42 { 43 get { return pageout; } 18 44 } 19 45 } -
trunk/MacFaceLibrary/MemoryUsageCounter.cs
r24 r25 3 3 */ 4 4 using System; 5 using System.Diagnostics; 5 6 6 7 namespace MacFace … … 11 12 public class MemoryUsageCounter 12 13 { 14 private PerformanceCounter availableCounter; 15 private PerformanceCounter committedCounter; 16 private PerformanceCounter pageoutCounter; 17 private PerformanceCounter pageinCounter; 18 13 19 public MemoryUsageCounter() 14 20 { 15 // 16 // TODO: RXgN^ WbNð±±ÉÇÁµÄ¾³¢B 17 // 21 availableCounter = new PerformanceCounter(); 22 availableCounter.CategoryName = "Memory"; 23 availableCounter.CounterName = "Available Bytes"; 24 25 committedCounter = new PerformanceCounter(); 26 committedCounter.CategoryName = "Memory"; 27 committedCounter.CounterName = "Committed Bytes"; 28 29 pageoutCounter = new PerformanceCounter(); 30 pageoutCounter.CategoryName = "Memory"; 31 pageoutCounter.CounterName = "Pages Output/sec"; 32 33 pageinCounter = new PerformanceCounter(); 34 pageinCounter.CategoryName = "Memory"; 35 pageinCounter.CounterName = "Pages Input/sec"; 36 } 37 38 public MemoryUsage CurrentUsage() 39 { 40 int available = (int)availableCounter.NextValue(); 41 int committed = (int)committedCounter.NextValue(); 42 int pagein = (int)pageinCounter.NextValue(); 43 int pageout = (int)pageoutCounter.NextValue(); 44 45 return new MemoryUsage(available, committed, pagein, pageout); 18 46 } 19 47 }
Note: See TracChangeset
for help on using the changeset viewer.