Changeset 49


Ignore:
Timestamp:
Mar 24, 2005, 10:36:47 PM (19 years ago)
Author:
altba\rryu
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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();
     
    87105                        // ƒpƒ^[ƒ“ƒEƒCƒ“ƒhƒE
    88106                        this.patternWindow = new PatternWindow();
     107
     108                        // ƒXƒe[ƒ^ƒXƒEƒCƒ“ƒhƒE         
     109                        statusWindow = new Form();
     110                        statusWindow.ClientSize = new System.Drawing.Size(300, 211);
     111                        statusWindow.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
     112                        statusWindow.ControlBox = false;
     113                        statusWindow.Icon = new Icon(asm.GetManifestResourceStream("MacFace.FloatApp.App.ico"));
     114                        statusWindow.Text = "Status";
     115                        statusWindow.Paint +=new PaintEventHandler(statusWindow_Paint);
    89116                }
    90117
     
    106133                                }
    107134                        }
     135
     136                        statusWindow.Show();
    108137
    109138                        patternWindow.Location = config.Location;
     
    213242                        MemoryUsage memUsage = memoryCounter.CurrentUsage();
    214243
     244                        cpuHistory[cpuHistoryHead++] = cpuUsage;
     245                        if (cpuHistoryHead >= cpuHistory.Length) cpuHistoryHead = 0;
     246                        if (cpuHistoryCount < cpuHistory.Length) cpuHistoryCount++;
     247
     248                        memHistory[memHistoryHead++] = memUsage;
     249                        if (memHistoryHead >= memHistory.Length) memHistoryHead = 0;
     250                        if (memHistoryCount < memHistory.Length) memHistoryCount++;
     251
    215252                        int pattern = cpuUsage.Active / 10;
    216253
     
    232269
    233270                        patternWindow.UpdatePattern(suite, pattern, markers);
     271
     272                        statusWindow.Refresh();
    234273                }
    235274
     
    274313                        patternWindow.Refresh();
    275314                }
     315
     316                private void statusWindow_Paint(object sender, PaintEventArgs e)
     317                {
     318                        Graphics g = e.Graphics;
     319                        g.SmoothingMode = SmoothingMode.AntiAlias;
     320
     321                        g.FillRectangle(new SolidBrush(Color.White), 0, 0, 300, 100);
     322                        for (int y = 0; y < 100; y += 10)
     323                        {
     324                                g.DrawLine(Pens.FloralWhite, 0, y, 300, y);
     325                        }
     326
     327                        g.FillRectangle(new SolidBrush(Color.White), 0, 110, 300, 100);
     328                        for (int y = 110; y < 210; y += 10)
     329                        {
     330                                g.DrawLine(Pens.FloralWhite, 0, y, 300, y);
     331                        }
     332
     333
     334                        if (cpuHistoryCount >= 2)
     335                        {
     336                                Point[] userGraph = new Point[cpuHistoryCount];
     337                                Point[] sysGraph = new Point[cpuHistoryCount];
     338
     339                                int pos = cpuHistoryHead - 1;
     340                                for (int i = 0; i < cpuHistoryCount; i++)
     341                                {
     342                                        if (pos < 0) pos = cpuHistory.Length - 1;
     343                                        CPUUsage usage = cpuHistory[pos];
     344                                        userGraph[i].X = sysGraph[i].X = 300 - i * 5;
     345                                        userGraph[i].Y = 100 - usage.Active;
     346                                        sysGraph[i].Y = 100 - usage.System;
     347                                        //Console.WriteLine("" + pos + ": " + points[i]);
     348                                        pos--;
     349                                }
     350
     351                                g.DrawLines(Pens.Red, sysGraph);
     352                                g.DrawLines(Pens.Blue, userGraph);
     353                        }
     354
     355                        double rate = 70.0 / (MemoryUsageCounter.TotalVisibleMemorySize * 1024);
     356
     357                        int posu = memHistoryHead - 1;
     358                        for (int i = 0; i < memHistoryCount; i++)
     359                        {
     360                                if (posu < 0) posu = memHistory.Length - 1;
     361                                MemoryUsage usage = memHistory[posu];
     362
     363                                int x, y, w, h;
     364
     365                                x = 300 - i * 5;
     366                                w = 5;
     367                                h = (int)(usage.Committed * rate);
     368                                y = 210 - h;
     369                                g.FillRectangle(Brushes.Blue, x, y, w, h);
     370
     371                                x = 300 - i * 5;
     372                                w = 2;
     373                                h = (int)(usage.Pagein);
     374                                y = 210 - h;
     375                                g.FillRectangle(Brushes.LightGray, x, y, w, h);
     376
     377                                x = 303 - i * 5;
     378                                w = 2;
     379                                h = (int)(usage.Pageout);
     380                                y = 210 - h;
     381                                g.FillRectangle(Brushes.Black, x, y, w, h);
     382
     383                                posu--;
     384                        }
     385                        g.DrawLine(Pens.Red, 0, 210-70, 300, 210-70);
     386                }
    276387        }
    277388}
Note: See TracChangeset for help on using the changeset viewer.