Changeset 61


Ignore:
Timestamp:
Sep 9, 2005, 2:13:57 AM (19 years ago)
Author:
rryu
Message:

CPU利用統計、メモリ利用統計の処理をアプリケーションクラスから専用のクラスに移した。
それに伴い不要になった*Counter系クラスを削除した。

Location:
trunk
Files:
2 added
2 deleted
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/MacFaceFloat/MacFaceApp.cs

    r60 r61  
    2929               
    3030                private System.Windows.Forms.Timer updateTimer;
    31                 private CPUUsageCounter cpuCounter;
    32                 private MemoryUsageCounter memoryCounter;
    3331
    3432                private StatusWindow statusWindow;
     
    3634                private Bitmap memoryGraph;
    3735
    38                 private CPUUsage[] cpuHistory;
    39                 private int cpuHistoryHead;
    40                 private int cpuHistoryCount;
    41 
    42                 private MemoryUsage[] memHistory;
    43                 private int memHistoryHead;
    44                 private int memHistoryCount;
     36                private CPUStatistics cpuStats;
     37                private MemoryStatistics memStats;
    4538
    4639                [STAThread]
     
    5649                        config.Load();
    5750
    58                         cpuHistory = new CPUUsage[61];
    59                         cpuHistoryCount = 0;
    60                         cpuHistoryHead = 0;
    61 
    62                         memHistory = new MemoryUsage[61];
    63                         memHistoryCount = 0;
    64                         memHistoryHead = 0;
    65 
    66                         cpuCounter = new CPUUsageCounter();
    67                         memoryCounter = new MemoryUsageCounter();
     51                        cpuStats = new CPUStatistics(61);
     52                        memStats = new MemoryStatistics(61);
    6853
    6954                        updateTimer = new System.Windows.Forms.Timer();
     
    204189                public void CountProcessorUsage(object sender, EventArgs e)
    205190                {
    206                         CPUUsage cpuUsage = cpuCounter.CurrentUsage();
    207                         MemoryUsage memUsage = memoryCounter.CurrentUsage();
    208 
    209                         cpuHistory[cpuHistoryHead++] = cpuUsage;
    210                         if (cpuHistoryHead >= cpuHistory.Length) cpuHistoryHead = 0;
    211                         if (cpuHistoryCount < cpuHistory.Length) cpuHistoryCount++;
    212 
    213                         memHistory[memHistoryHead++] = memUsage;
    214                         if (memHistoryHead >= memHistory.Length) memHistoryHead = 0;
    215                         if (memHistoryCount < memHistory.Length) memHistoryCount++;
    216 
     191                        cpuStats.Update();
     192                        CPUUsage cpuUsage = cpuStats.Latest;
     193
     194                        memStats.Update();
     195                        MemoryUsage memUsage = memStats.Latest;
     196                       
    217197                        if (patternWindow != null)
    218198                        {
     
    220200
    221201                                int pattern = cpuUsage.Active / 10;
    222                                 int avilable = (int)MemoryUsageCounter.TotalVisibleMemorySize * 1024 - memUsage.Committed;
     202                                int avilable = (int)memStats.TotalVisibleMemorySize * 1024 - memUsage.Committed;
    223203                                if (avilable < (10 * 1024 *1024))
    224204                                {
     
    360340                        g.DrawLine(Pens.Gray, 0, 50, 300, 50);
    361341
    362                         if (cpuHistoryCount >= 2)
    363                         {
    364                                 Point[] userGraph = new Point[cpuHistoryCount+2];
    365                                 Point[] sysGraph = new Point[cpuHistoryCount+2];
    366 
    367                                 userGraph[cpuHistoryCount+0].X = 300 - (cpuHistoryCount-1) * 5;
    368                                 userGraph[cpuHistoryCount+0].Y = 100 - 0;
    369                                 userGraph[cpuHistoryCount+1].X = 300 - 0 * 5;
    370                                 userGraph[cpuHistoryCount+1].Y = 100 - 0;
    371 
    372                                 sysGraph[cpuHistoryCount+0].X = 300 - (cpuHistoryCount-1) * 5;
    373                                 sysGraph[cpuHistoryCount+0].Y = 100 - 0;
    374                                 sysGraph[cpuHistoryCount+1].X = 300 - 0 * 5;
    375                                 sysGraph[cpuHistoryCount+1].Y = 100 - 0;
    376 
    377                                 int pos = cpuHistoryHead - 1;
    378                                 for (int i = 0; i < cpuHistoryCount; i++)
     342                        int count = cpuStats.Count;
     343
     344                        if (count >= 2)
     345                        {
     346                                Point[] userGraph = new Point[count+2];
     347                                Point[] sysGraph = new Point[count+2];
     348
     349                                userGraph[count+0].X = 300 - (count-1) * 5;
     350                                userGraph[count+0].Y = 100 - 0;
     351                                userGraph[count+1].X = 300 - 0 * 5;
     352                                userGraph[count+1].Y = 100 - 0;
     353
     354                                sysGraph[count+0].X = 300 - (count-1) * 5;
     355                                sysGraph[count+0].Y = 100 - 0;
     356                                sysGraph[count+1].X = 300 - 0 * 5;
     357                                sysGraph[count+1].Y = 100 - 0;
     358
     359                                for (int i = 0; i < count; i++)
    379360                                {
    380                                         if (pos < 0) pos = cpuHistory.Length - 1;
    381                                         CPUUsage usage = cpuHistory[pos];
     361                                        CPUUsage usage = cpuStats[i];
    382362                                        userGraph[i].X = sysGraph[i].X = 300 - i * 5;
    383363                                        userGraph[i].Y = 100 - usage.Active;
    384364                                        sysGraph[i].Y = 100 - usage.System;
    385                                         pos--;
    386365                                }
    387366
     
    398377                        Graphics g = Graphics.FromImage(memoryGraph);
    399378
    400                         int totalMemory = (int)MemoryUsageCounter.TotalVisibleMemorySize * 1024;
    401                         double rate = 100.0 / MemoryUsageCounter.CommitLimit;
     379                        int totalMemory = (int)memStats.TotalVisibleMemorySize * 1024;
     380                        double rate = 100.0 / memStats.CommitLimit;
    402381                        int border = (int)(totalMemory * rate);
    403382
     
    417396                        Brush spaceBrush = new SolidBrush(Color.FromArgb(100, 100, 100, 255));
    418397
    419                         int pos = memHistoryHead - 1;
    420                         for (int i = 0; i < memHistoryCount; i++)
    421                         {
    422                                 if (pos < 0) pos = memHistory.Length - 1;
    423                                 MemoryUsage usage = memHistory[pos];
     398                        int count = memStats.Count;
     399
     400                        for (int i = 0; i < count; i++)
     401                        {
     402                                MemoryUsage usage = memStats[i];
    424403
    425404                                int x = 300 - i * 5 - 5;
     
    461440                                y = 100 - h;
    462441                                g.FillRectangle(Brushes.Black, x, y, w, h);
    463 
    464                                 pos--;
    465442                        }
    466443                        Pen borderPen = new Pen(Color.Blue);
  • trunk/MacFaceLibrary/MacFaceLibrary.csproj

    r27 r61  
    100100                />
    101101                <File
    102                     RelPath = "CPUUsage.cs"
     102                    RelPath = "CPUStatistics.cs"
    103103                    SubType = "Code"
    104104                    BuildAction = "Compile"
    105105                />
    106106                <File
    107                     RelPath = "CPUUsageCounter.cs"
     107                    RelPath = "CPUUsage.cs"
    108108                    SubType = "Code"
    109109                    BuildAction = "Compile"
     
    120120                />
    121121                <File
    122                     RelPath = "MemoryUsage.cs"
     122                    RelPath = "MemoryStatistics.cs"
    123123                    SubType = "Code"
    124124                    BuildAction = "Compile"
    125125                />
    126126                <File
    127                     RelPath = "MemoryUsageCounter.cs"
     127                    RelPath = "MemoryUsage.cs"
    128128                    SubType = "Code"
    129129                    BuildAction = "Compile"
Note: See TracChangeset for help on using the changeset viewer.