Changeset 49

Show
Ignore:
Timestamp:
03/24/05 22:36:47 (4 years ago)
Author:
altba\rryu
Message:

てきとーにグラフ表示ウインドウを付けてみた。
これでひとまずWindowsの挙動を観察。

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/MacFaceFloat/MacFaceApp.cs

    r47 r49  
    1010using System.Windows.Forms; 
    1111using System.Drawing; 
     12using System.Drawing.Drawing2D; 
    1213using System.Data; 
    1314using System.IO; 
     
    3132                private MemoryUsageCounter memoryCounter; 
    3233 
     34                private Form statusWindow; 
     35 
     36                private CPUUsage[] cpuHistory; 
     37                private int cpuHistoryHead; 
     38                private int cpuHistoryCount; 
     39 
     40                private MemoryUsage[] memHistory; 
     41                private int memHistoryHead; 
     42                private int memHistoryCount; 
    3343 
    3444                [STAThread] 
     
    4353                        config = Configuration.GetInstance(); 
    4454                        config.Load(); 
     55 
     56                        cpuHistory = new CPUUsage[60]; 
     57                        cpuHistoryCount = 0; 
     58                        cpuHistoryHead = 0; 
     59 
     60                        memHistory = new MemoryUsage[60]; 
     61                        memHistoryCount = 0; 
     62                        memHistoryHead = 0; 
    4563 
    4664                        cpuCounter = new CPUUsageCounter(); 
     
    86104                        // �p�^�[���E�C���h�E 
    87105                        this.patternWindow = new PatternWindow(); 
     106 
     107                        // �X�e�[�^�X�E�C���h�E          
     108                        statusWindow = new Form(); 
     109                        statusWindow.ClientSize = new System.Drawing.Size(300, 211); 
     110                        statusWindow.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow; 
     111                        statusWindow.ControlBox = false; 
     112                        statusWindow.Icon = new Icon(asm.GetManifestResourceStream("MacFace.FloatApp.App.ico")); 
     113                        statusWindow.Text = "Status"; 
     114                        statusWindow.Paint +=new PaintEventHandler(statusWindow_Paint); 
    88115                } 
    89116 
     
    105132                                } 
    106133                        } 
     134 
     135                        statusWindow.Show(); 
    107136 
    108137                        patternWindow.Location = config.Location; 
     
    211240                        MemoryUsage memUsage = memoryCounter.CurrentUsage(); 
    212241 
     242                        cpuHistory[cpuHistoryHead++] = cpuUsage; 
     243                        if (cpuHistoryHead >= cpuHistory.Length) cpuHistoryHead = 0; 
     244                        if (cpuHistoryCount < cpuHistory.Length) cpuHistoryCount++; 
     245 
     246                        memHistory[memHistoryHead++] = memUsage; 
     247                        if (memHistoryHead >= memHistory.Length) memHistoryHead = 0; 
     248                        if (memHistoryCount < memHistory.Length) memHistoryCount++; 
     249 
    213250                        int pattern = cpuUsage.Active / 10; 
    214251 
     
    230267 
    231268                        patternWindow.UpdatePattern(suite, pattern, markers); 
     269 
     270                        statusWindow.Refresh(); 
    232271                } 
    233272 
     
    271310                        patternWindow.Refresh(); 
    272311                } 
     312 
     313                private void statusWindow_Paint(object sender, PaintEventArgs e) 
     314                { 
     315                        Graphics g = e.Graphics; 
     316                        g.SmoothingMode = SmoothingMode.AntiAlias; 
     317 
     318                        g.FillRectangle(new SolidBrush(Color.White), 0, 0, 300, 100); 
     319                        for (int y = 0; y < 100; y += 10)  
     320                        { 
     321                                g.DrawLine(Pens.FloralWhite, 0, y, 300, y); 
     322                        } 
     323 
     324                        g.FillRectangle(new SolidBrush(Color.White), 0, 110, 300, 100); 
     325                        for (int y = 110; y < 210; y += 10)  
     326                        { 
     327                                g.DrawLine(Pens.FloralWhite, 0, y, 300, y); 
     328                        } 
     329 
     330 
     331                        if (cpuHistoryCount >= 2)  
     332                        { 
     333                                Point[] userGraph = new Point[cpuHistoryCount]; 
     334                                Point[] sysGraph = new Point[cpuHistoryCount]; 
     335 
     336                                int pos = cpuHistoryHead - 1; 
     337                                for (int i = 0; i < cpuHistoryCount; i++)  
     338                                { 
     339                                        if (pos < 0) pos = cpuHistory.Length - 1; 
     340                                        CPUUsage usage = cpuHistory[pos]; 
     341                                        userGraph[i].X = sysGraph[i].X = 300 - i * 5; 
     342                                        userGraph[i].Y = 100 - usage.Active; 
     343                                        sysGraph[i].Y = 100 - usage.System; 
     344                                        //Console.WriteLine("" + pos + ": " + points[i]); 
     345                                        pos--; 
     346                                } 
     347 
     348                                g.DrawLines(Pens.Red, sysGraph); 
     349                                g.DrawLines(Pens.Blue, userGraph); 
     350                        } 
     351 
     352                        double rate = 70.0 / (MemoryUsageCounter.TotalVisibleMemorySize * 1024); 
     353 
     354                        int posu = memHistoryHead - 1; 
     355                        for (int i = 0; i < memHistoryCount; i++)  
     356                        { 
     357                                if (posu < 0) posu = memHistory.Length - 1; 
     358                                MemoryUsage usage = memHistory[posu]; 
     359 
     360                                int x, y, w, h; 
     361 
     362                                x = 300 - i * 5; 
     363                                w = 5; 
     364                                h = (int)(usage.Committed * rate); 
     365                                y = 210 - h; 
     366                                g.FillRectangle(Brushes.Blue, x, y, w, h); 
     367 
     368                                x = 300 - i * 5; 
     369                                w = 2; 
     370                                h = (int)(usage.Pagein); 
     371                                y = 210 - h; 
     372                                g.FillRectangle(Brushes.LightGray, x, y, w, h); 
     373 
     374                                x = 303 - i * 5; 
     375                                w = 2; 
     376                                h = (int)(usage.Pageout); 
     377                                y = 210 - h; 
     378                                g.FillRectangle(Brushes.Black, x, y, w, h); 
     379 
     380                                posu--; 
     381                        } 
     382                        g.DrawLine(Pens.Red, 0, 210-70, 300, 210-70); 
     383                } 
    273384        } 
    274385}