Changeset 124


Ignore:
Timestamp:
May 26, 2009, 3:31:47 AM (15 years ago)
Author:
rryu
Message:
Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/MacFaceFloat/MacFaceApp.cs

    r119 r124  
    4848                public static void Main(string[] args)
    4949                {
     50            //NtKernel.SYSTEM_BASIC_INFORMATION info = NtKernel.QuerySystemBasicInformation();
     51            //NtKernel.SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION[] list =
     52            //    NtKernel.QuerySystemProcessorPerformanceInfomation((int)info.ActiveProcessors);
     53            //MachineStatus status = MachineStatus.LocalMachineStatus();
     54            //int c = status.ProcessorCount;
     55            //NtKernel.SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION[] list = status.ProcessorPerformances();
     56
    5057            Application.EnableVisualStyles();
    5158            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
     
    5461                }
    5562
    56                 /// <summary>
    57                 /// Windows 2000 ‚̓pƒtƒH[ƒ}ƒ“ƒXƒ‚ƒjƒ^‚ªƒ_ƒ‚È‚ç‚»‚ꂼ‚êAPI‚Å‚ª‚ñ‚΂é
    58                 /// </summary>
    59                 public void SetupStatisticsForWindows2000()
    60                 {
    61 //                      cpuStats = new CPUStatistics(81);
    62 //                      memStats = new MemoryStatistics(81);
    63 //
    64 //                      try
    65 //                      {
    66 //                              // ŽŽ‚µ‚ɃJƒEƒ“ƒ^‚ðŽÀs‚µ‚Ä‚Ý‚é
    67 //                              cpuStats.Update();
    68 //                              memStats.Update();
    69 //                      }
    70 //                      catch (System.ComponentModel.Win32Exception)
    71 //                      {
    72 //                              // ƒ_ƒ‚¾‚Á‚½‚̂ŃpƒtƒH[ƒ}ƒ“ƒXƒJƒEƒ“ƒ^‚ðŽg‚í‚È‚¢•û–@‚Ö
    73 //                              cpuStats = new CPUStatisticsNtQuerySystemInformation(61);
    74 //                              memStats = new MemoryStatisticsGlobalMemoryStatusEx(61);
    75 //                      }
    76 //                      catch (System.InvalidOperationException)
    77 //                      {
    78 //                              // ƒ_ƒ‚¾‚Á‚½‚̂ŃpƒtƒH[ƒ}ƒ“ƒXƒJƒEƒ“ƒ^‚ðŽg‚í‚È‚¢•û–@‚Ö
    79 //                              cpuStats = new CPUStatisticsNtQuerySystemInformation(61);
    80 //                              memStats = new MemoryStatisticsGlobalMemoryStatusEx(61);
    81 //                      }
    82 
    83                         cpuStats = new CPUStatisticsNtQuerySystemInformation(61);
    84                         memStats = new MemoryStatisticsNtQuerySystemInformation(61);
    85                 }
    86 
    87                 public void SetupStatisticsForWindowsXP()
    88                 {
    89 //                      cpuStats = new CPUStatistics(81);
    90 //                      memStats = new MemoryStatistics(81);
    91 //                      try
    92 //                      {
    93 //                              // ŽŽ‚µ‚ɃJƒEƒ“ƒ^‚ðŽÀs‚µ‚Ä‚Ý‚é
    94 //                              cpuStats.Update();
    95 //                              memStats.Update();
    96 //                      }
    97 //                      catch (System.ComponentModel.Win32Exception)
    98 //                      {
    99 //                              // ƒ_ƒ‚¾‚Á‚½‚̂ŃpƒtƒH[ƒ}ƒ“ƒXƒJƒEƒ“ƒ^‚ðŽg‚í‚È‚¢•û–@‚Ö
    100 //                              cpuStats = new CPUStatisticsGetSystemTime(61);
    101 //                              memStats = new MemoryStatisticsNtQuerySystemInformation(61);
    102 //                      }
    103 //                      catch (System.InvalidOperationException)
    104 //                      {
    105 //                              // ƒ_ƒ‚¾‚Á‚½‚̂ŃpƒtƒH[ƒ}ƒ“ƒXƒJƒEƒ“ƒ^‚ðŽg‚í‚È‚¢•û–@‚Ö
    106 //                              cpuStats = new CPUStatisticsGetSystemTime(61);
    107 //                              memStats = new MemoryStatisticsPSAPI(61);
    108 //                      }
    109 
    110                         cpuStats = new CPUStatisticsGetSystemTime(61);
    111                         memStats = new MemoryStatisticsNtQuerySystemInformation(61);
    112                 }
    11363
    11464                public MacFaceApp()
     
    11969                        pageio_count = 0;
    12070
    121                         // OS ‚²‚ƂɎ擾‚·‚é•û–@‚ð•ÏX‚·‚é
    122                         if (Environment.OSVersion.Version.Major == 5 && Environment.OSVersion.Version.Minor == 0)
    123                         {
    124                                 SetupStatisticsForWindows2000();
    125                         }
    126                         else
    127                         {
    128                                 // XP / 2003 / Vista
    129                                 SetupStatisticsForWindowsXP();
    130                         }
     71            cpuStats = new CPUStatisticsNtQuerySystemInformation(61);
     72            memStats = new MemoryStatisticsNtQuerySystemInformation(61);
     73
     74            patternWindow = null;
     75            statusWindow = null;
     76
     77            InitializeComponent();
     78
     79            // x64 ŠÂ‹«‚Å 32bit ‚È OptimusMini.dll ‚ð“ǂݍž‚à‚¤‚Æ‚·‚é‚Æ“–‘RƒGƒ‰[‚Æ‚È‚é‚̂ʼn½‚à‚µ‚È‚¢ƒNƒ‰ƒX‚É‚µ‚Ä‚¨‚­
     80                    optimusMini = (IntPtr.Size == 4 ? (IOptimusMini)new OptimusMini() : new OptimusMiniMock());
     81            optimusMini.DisplayOn();
    13182
    13283            //OptimusMini.OnKeyDownCallbackDelegate oKD = new OptimusMini.OnKeyDownCallbackDelegate(OnKeyDownCallbackHandler);
    13384            //OptimusMini.OnDeviceStateChangedCallbackDelegate oDSC = new OptimusMini.OnDeviceStateChangedCallbackDelegate(OnDeviceStateChangedCallbackHandler);
    13485            //OptimusMini.RegisterEventHandler(oKD, oDSC);
    135 
    136             patternWindow = null;
    137             statusWindow = null;
    138 
    139             InitializeComponent();
    140 
    141             // x64 ŠÂ‹«‚Å 32bit ‚È OptimusMini.dll ‚ð“ǂݍž‚à‚¤‚Æ‚·‚é‚Æ“–‘RƒGƒ‰[‚Æ‚È‚é‚̂ʼn½‚à‚µ‚È‚¢ƒNƒ‰ƒX‚É‚µ‚Ä‚¨‚­
    142                     optimusMini = (IntPtr.Size == 4 ? (IOptimusMini)new OptimusMini() : new OptimusMiniMock());
    143             optimusMini.DisplayOn();
    14486
    14587            CountProcessorUsage(null, null);
  • trunk/MacFaceLibrary/CPUStatisticsNtQuerySystemInformation.cs

    r121 r124  
     1// $Id$
    12using System;
    23using System.Diagnostics;
     
    1112        {
    1213                       
    13                 UInt64 idleTimePrev = 0;
    14                 UInt64 kernelTimePrev = 0;
    15                 UInt64 userTimePrev = 0;
     14                Int64 idleTimePrev = 0;
     15                Int64 kernelTimePrev = 0;
     16                Int64 userTimePrev = 0;
    1617
    1718                public CPUStatisticsNtQuerySystemInformation(int historySize) : base(historySize)
     
    2223                protected override CPUUsage NextValue()
    2324                {
    24                         UInt64 idleTime;
    25                         UInt64 kernelTime;
    26                         UInt64 userTime;
     25                        Int64 idleTime;
     26                        Int64 kernelTime;
     27                        Int64 userTime;
    2728
    28                         NtKernel.SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION sysProcessorPerfInfo = NtKernel.QuerySystemProcessorPerformanceInfomation();
     29                        NtKernel.SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION sysProcessorPerfInfo = NtKernel.QuerySystemProcessorPerformanceInfomation(1)[0];
    2930                       
    30                         idleTime = (UInt64)sysProcessorPerfInfo.IdleTime;
    31                         kernelTime = (UInt64)sysProcessorPerfInfo.KernelTime;
    32                         userTime = (UInt64)sysProcessorPerfInfo.UserTime;
     31                        idleTime = sysProcessorPerfInfo.IdleTime;
     32                        kernelTime = sysProcessorPerfInfo.KernelTime - idleTime;
     33                        userTime = sysProcessorPerfInfo.UserTime;
    3334                               
    34                         Int32 idleTimeDiff = (Int32)(idleTime - idleTimePrev);
    35                         Int32 userTimeDiff = (Int32)(userTime - userTimePrev);
    36                         Int32 kernelTimeDiff = (Int32)(kernelTime - kernelTimePrev);
    37                         Int32 systemTimeDiff = (Int32)(userTimeDiff + kernelTimeDiff);
     35                        Int64 idleTimeDiff = idleTime - idleTimePrev;
     36            Int64 userTimeDiff = userTime - userTimePrev;
     37            Int64 kernelTimeDiff = kernelTime - kernelTimePrev;
     38            Int64 totalTimeDiff = idleTimeDiff + userTimeDiff + kernelTimeDiff;
    3839
    3940                        idleTimePrev = idleTime;
     
    4243
    4344                        return new CPUUsage(
    44                                 (Int32)(100 - ((Double)idleTimeDiff / userTimePrev) * 100),
    45                                 (Int32)(100 - ((Double)idleTimeDiff / kernelTimePrev) * 100),
    46                                 (Int32)(((Double)idleTimeDiff / (systemTimeDiff)) * 100)
     45                                (Int32)(((Double)userTimeDiff / totalTimeDiff) * 100),
     46                                (Int32)(((Double)kernelTimeDiff / totalTimeDiff) * 100),
     47                                (Int32)(((Double)idleTimeDiff / totalTimeDiff) * 100)
    4748                        );
    4849                }
  • trunk/MacFaceLibrary/MachineStatus.cs

    • Property svn:keywords set to Id
    r122 r124  
    1 using System;
     1// $Id$
     2using System;
    23using System.Collections.Generic;
    34using System.Text;
     
    56namespace MacFace
    67{
    7     class MachineStatus
     8    public class MachineStatus
    89    {
    910        protected static MachineStatus sharedMachineStatus;
    1011
    11         protected Byte numberProcessors;
     12        protected Byte processorCount;
    1213
    1314        public static MachineStatus LocalMachineStatus()
     
    2324        {
    2425            NtKernel.SYSTEM_BASIC_INFORMATION info = NtKernel.QuerySystemBasicInformation();
    25             numberProcessors = info.NumberProcessors;
     26            processorCount = info.NumberProcessors;
    2627        }
    2728
    28         public int NumberProcessors
     29        public int ProcessorCount
    2930        {
    3031            get
    3132            {
    32                 return numberProcessors;
     33                return processorCount;
    3334            }
    3435        }
    3536
     37        public NtKernel.SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION[] ProcessorPerformances()
     38        {
     39            return NtKernel.QuerySystemProcessorPerformanceInfomation(processorCount);
     40        }
    3641    }
    3742}
  • trunk/MacFaceLibrary/NtKernel.cs

    • Property svn:keywords set to Id
    r121 r124  
    1 using System;
     1// $Id$
     2using System;
    23using System.Runtime.InteropServices;
    34
    4 class NtKernel {
     5public class NtKernel {
    56
    6     unsafe public static SYSTEM_BASIC_INFORMATION QuerySystemBasicInformation()
     7    public static SYSTEM_BASIC_INFORMATION QuerySystemBasicInformation()
    78    {
    8         SYSTEM_BASIC_INFORMATION info = new SYSTEM_BASIC_INFORMATION();
    9         UInt32 len = (UInt32)Marshal.SizeOf(typeof(SYSTEM_BASIC_INFORMATION));
     9        int len = Marshal.SizeOf(typeof(SYSTEM_BASIC_INFORMATION));
     10        IntPtr ptr = Marshal.AllocCoTaskMem(len);
    1011        UInt32 outLen;
    1112
    1213        NtQuerySystemInformation(
    13             SYSTEM_INFORMATION_CLASS.SystemBasicInformation, &info, len, out outLen
     14            SYSTEM_INFORMATION_CLASS.SystemBasicInformation, ptr, (UInt32)len, out outLen
    1415        );
    15         return info;
     16
     17        return (SYSTEM_BASIC_INFORMATION)Marshal.PtrToStructure(ptr, typeof(SYSTEM_BASIC_INFORMATION));
    1618    }
    1719
    18     unsafe public static SYSTEM_PERFORMANCE_INFORMATION QuerySystemPerformanceInformation()
     20    public static SYSTEM_PERFORMANCE_INFORMATION QuerySystemPerformanceInformation()
    1921    {
    20         SYSTEM_PERFORMANCE_INFORMATION info = new SYSTEM_PERFORMANCE_INFORMATION();
    21         UInt32 len = (UInt32)Marshal.SizeOf(typeof(SYSTEM_PERFORMANCE_INFORMATION));
     22        int len = Marshal.SizeOf(typeof(SYSTEM_PERFORMANCE_INFORMATION));
     23        IntPtr ptr = Marshal.AllocCoTaskMem(len);
    2224        UInt32 outLen;
    2325
    2426        NtQuerySystemInformation(
    25             SYSTEM_INFORMATION_CLASS.SystemPerformanceInformation, &info, len, out outLen
     27            SYSTEM_INFORMATION_CLASS.SystemPerformanceInformation, ptr, (UInt32)len, out outLen
    2628        );
    27         return info;
     29
     30        return (SYSTEM_PERFORMANCE_INFORMATION)Marshal.PtrToStructure(ptr, typeof(SYSTEM_PERFORMANCE_INFORMATION));
    2831    }
    2932
    30     unsafe public static SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION QuerySystemProcessorPerformanceInfomation()
     33    public static SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION[] QuerySystemProcessorPerformanceInfomation(int processorCount)
    3134    {
    32         SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION info = new SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION();
    33         UInt32 len = (UInt32)(Marshal.SizeOf(typeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION)));
     35        int len = Marshal.SizeOf(typeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION)) * processorCount;
     36        IntPtr ptr = Marshal.AllocCoTaskMem(len);
    3437        UInt32 outLen;
     38
    3539        NtQuerySystemInformation(
    36             SYSTEM_INFORMATION_CLASS.SystemProcessorPerformanceInformation, &info, len, out outLen
     40            SYSTEM_INFORMATION_CLASS.SystemProcessorPerformanceInformation, ptr, (UInt32)len, out outLen
    3741        );
    38         return info;
     42
     43        SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION[] list = new SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION[processorCount];
     44        for (int i = 0; i < processorCount; i++) {
     45            IntPtr p = new IntPtr(ptr.ToInt32() + Marshal.SizeOf(typeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION)) * i);
     46            list[i] = (SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION)Marshal.PtrToStructure(p, typeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION));
     47        }
     48   
     49        return list;
    3950    }
    4051
    4152    [DllImport("ntdll.dll")]
    42     unsafe protected extern static UInt32 NtQuerySystemInformation(
     53    protected extern static UInt32 NtQuerySystemInformation(
    4354        SYSTEM_INFORMATION_CLASS SystemInformationClass,
    44         void* SystemInformation,
     55        IntPtr SystemInformation,
    4556        UInt32 SystemInformationLength,
    4657        out UInt32 ReturnLength
     
    6374    public struct SYSTEM_BASIC_INFORMATION
    6475    {
    65         public UInt64 Unknown;
    66         public UInt64 MaximumIncrement;
    67         public UInt64 PhysicalPageSize;
    68         public UInt64 NumberOfPhysicalPages;
    69         public UInt64 LowestPhysicalPage;
    70         public UInt64 HighestPhysicalPage;
    71         public UInt64 AllocationGranularity;
    72         public UInt64 LowestUserAddress;
    73         public UInt64 HighestUserAddress;
    74         public UInt64 ActiveProcessors;
     76        public UInt32 Unknown;
     77        public UInt32 MaximumIncrement;
     78        public UInt32 PhysicalPageSize;
     79        public UInt32 NumberOfPhysicalPages;
     80        public UInt32 LowestPhysicalPage;
     81        public UInt32 HighestPhysicalPage;
     82        public UInt32 AllocationGranularity;
     83        public UInt32 LowestUserAddress;
     84        public UInt32 HighestUserAddress;
     85        public UInt32 ActiveProcessors;
    7586        public Byte NumberProcessors;
    7687    }
Note: See TracChangeset for help on using the changeset viewer.