Exemplo n.º 1
0
        public static void Show()
        {
            SystemInfo systemInfo = new SystemInfo();

            Console.WriteLine("操作系统:" + systemInfo.GetOperationSystemInName() + "<br>");
            Console.WriteLine("CPU编号:" + systemInfo.GetCpuId() + "<br>");
            Console.WriteLine("硬盘编号:" + systemInfo.GetMainHardDiskId() + "<br>");
            Console.WriteLine("Windows目录所在位置:" + systemInfo.GetSysDirectory() + "<br>");
            Console.WriteLine("系统目录所在位置:" + systemInfo.GetWinDirectory() + "<br>");
            MemoryInfo memoryInfo = systemInfo.GetMemoryInfo();
            CpuInfo    cpuInfo    = systemInfo.GetCpuInfo();

            Console.WriteLine("dwActiveProcessorMask" + cpuInfo.dwActiveProcessorMask + "<br>");
            Console.WriteLine("dwAllocationGranularity" + cpuInfo.dwAllocationGranularity + "<br>");
            Console.WriteLine("CPU个数:" + cpuInfo.dwNumberOfProcessors + "<br>");
            Console.WriteLine("OEM ID:" + cpuInfo.dwOemId + "<br>");
            Console.WriteLine("页面大小" + cpuInfo.dwPageSize + "<br>");
            Console.WriteLine("CPU等级" + cpuInfo.dwProcessorLevel + "<br>");
            Console.WriteLine("dwProcessorRevision" + cpuInfo.dwProcessorRevision + "<br>");
            Console.WriteLine("CPU类型" + cpuInfo.dwProcessorType + "<br>");
            Console.WriteLine("lpMaximumApplicationAddress" + cpuInfo.lpMaximumApplicationAddress + "<br>");
            Console.WriteLine("lpMinimumApplicationAddress" + cpuInfo.lpMinimumApplicationAddress + "<br>");
            Console.WriteLine("CPU类型:" + cpuInfo.dwProcessorType + "<br>");
            Console.WriteLine("可用交换文件大小:" + memoryInfo.dwAvailPageFile + "<br>");
            Console.WriteLine("可用物理内存大小:" + memoryInfo.dwAvailPhys + "<br>");
            Console.WriteLine("可用虚拟内存大小" + memoryInfo.dwAvailVirtual + "<br>");
            Console.WriteLine("操作系统位数:" + memoryInfo.dwLength + "<br>");
            Console.WriteLine("已经使用内存大小:" + memoryInfo.dwMemoryLoad + "<br>");
            Console.WriteLine("交换文件总大小:" + memoryInfo.dwTotalPageFile + "<br>");
            Console.WriteLine("总物理内存大小:" + memoryInfo.dwTotalPhys + "<br>");
            Console.WriteLine("总虚拟内存大小:" + memoryInfo.dwTotalVirtual + "<br>");
        }
Exemplo n.º 2
0
 public async Task <IHttpActionResult> Get()
 {
     try
     {
         #region token
         var header = Request.Headers;
         if (header.Authorization == null)
         {
             return(StatusCode(HttpStatusCode.Unauthorized));
         }
         var      token = header.Authorization.Parameter;
         Employee employee;
         if (string.IsNullOrWhiteSpace(token) || !TokenManager.ValidateToken(token, out employee))
         {
             return(StatusCode(HttpStatusCode.Unauthorized));
         }
         #endregion
         var lstData = MemoryInfo.GetAllServicePackFee();
         if (lstData != null)
         {
             lstData = lstData.Where(x => x.IsDeleted != null && x.IsDeleted != 1).ToList();
         }
         var res = new RequestErrorCode(true, null, null);
         res.ListDataResult.AddRange(lstData);
         return(Ok(res));
     }
     catch (Exception ex)
     {
         Logger.Write(ex.ToString());
     }
     return(BadRequest("Unknow"));
 }
Exemplo n.º 3
0
        /// <summary>
        /// 获取系统内存信息
        /// </summary>
        /// <returns></returns>
        public MemoryInfo GetMemoryInfo()
        {
            MemoryInfo memoryInfo = new MemoryInfo();

            GlobalMemoryStatus(ref memoryInfo);
            return(memoryInfo);
        }
Exemplo n.º 4
0
    /// <summary>
    /// 用于监控内存
    /// </summary>
    /// <param name="tag"></param>
    static void MonitorMemorySize()
    {
        if (ApplicationManager.AppMode != AppMode.Release)
        {
            totalReservedMemory  = ByteToM(Profiler.GetTotalReservedMemoryLong());
            totalAllocatedMemory = ByteToM(Profiler.GetTotalAllocatedMemoryLong());
        }

        if (tempTime <= 0)
        {
            tempTime = UpdateMemoryTime;
            if (MemoryInfo.GetMemoryInfo())
            {
                freeMemory = MemoryInfo.minf.memfree / 1024f / 1024f;
                allMemory  = MemoryInfo.minf.memtotal / 1024f / 1024f;
                usedMemory = MemoryInfo.minf.memused / 1024f / 1024f;
            }
        }
        else
        {
            tempTime -= Time.deltaTime;
        }

        AssetsUnloadHandler.LateUpdate();

        if (NeedReleaseMemory() && OpenAutoMemoryClean)
        {
            AssetsUnloadHandler.UnloadOne();
        }
    }
 public async Task <IHttpActionResult> Get()
 {
     try
     {
         var lstData = MemoryInfo.GetAllDevice();
         if (lstData != null)
         {
             lstData = lstData.Where(x => x.IsDeleted != null && x.IsDeleted != 1).ToList();
         }
         List <DeviceRes> lstResult = new List <DeviceRes>();
         foreach (var item in lstData)
         {
             var       manufacturer = MemoryInfo.GetManufacturer(item.IdManufacturer);
             DeviceRes temp         = new DeviceRes(item, manufacturer);
             lstResult.Add(temp);
         }
         var res = new RequestErrorCode(true, null, null);
         res.ListDataResult.AddRange(lstResult);
         return(Ok(res));
     }
     catch (Exception ex)
     {
         Logger.Write(ex.ToString());
     }
     return(BadRequest("Unknow"));
 }
        public async Task <IHttpActionResult> Get(int id)
        {
            try
            {
                var data = MemoryInfo.GetDevice(id);
                if (data != null && data.IsDeleted == 1)
                {
                    data = null;
                }
                var res = new RequestErrorCode(true, null, null);
                if (data != null && data.IsDeleted == 1)
                {
                    res.DataResult = null;
                    return(Ok(res));
                }

                if (data != null)
                {
                    var       manufacturer = MemoryInfo.GetManufacturer(data.IdManufacturer);
                    DeviceRes result       = new DeviceRes(data, manufacturer);
                    res.DataResult = result;
                    return(Ok(res));
                }
                res.DataResult = data;
                return(Ok(res));
            }
            catch (Exception ex)
            {
                Logger.Write(ex.ToString());
            }
            return(BadRequest("Unknow"));
        }
 public async Task <IHttpActionResult> Get()
 {
     try
     {
         var lstData = MemoryInfo.GetAllPayment();
         if (lstData != null)
         {
             lstData = lstData.Where(x => x.IsDeleted != null && x.IsDeleted != 1).ToList();
         }
         List <PaymentRes> lstResult = new List <PaymentRes>();
         foreach (var payment in lstData)
         {
             if (payment.IsDeleted != 1)
             {
                 var lstPaymentFees = MemoryInfo.GetListPaymentFeeByField(payment.Id.ToString(),
                                                                          PaymentFee.PaymentFeeFields.IdPayment);
                 PaymentRes itemRes = new PaymentRes(payment, lstPaymentFees);
                 lstResult.Add(itemRes);
             }
         }
         var res = new RequestErrorCode(true, null, null);
         res.ListDataResult.AddRange(lstResult);
         return(Ok(res));
     }
     catch (Exception ex)
     {
         Logger.Write(ex.ToString());
     }
     return(BadRequest("Unknow"));
 }
 public async Task <IHttpActionResult> Get(int id)
 {
     try
     {
         var             data    = MemoryInfo.GetServicePack(id);
         ServicesPackRes itemRes = null;
         if (data != null)
         {
             if (data.IsDeleted != 1)
             {
                 string cnTypeName  = "";
                 var    connectType = MemoryInfo.GetConnectionType(data.IdConnectionType);
                 if (connectType != null)
                 {
                     cnTypeName = connectType.Name;
                 }
                 var lstSvPackFee = MemoryInfo.GetListServicePackFeeByField(data.Id.ToString(),
                                                                            ServicePackFee.ServicePackFeeFields.IdServicePack);
                 itemRes = new ServicesPackRes(data, cnTypeName, lstSvPackFee);
             }
         }
         var res = new RequestErrorCode(true, null, null);
         res.DataResult = itemRes;
         return(Ok(res));
     }
     catch (Exception ex)
     {
         Logger.Write(ex.ToString());
     }
     return(BadRequest("Unknow"));
 }
Exemplo n.º 9
0
        public async Task <IHttpActionResult> Get(string contractId)
        {
            try
            {
                var lstSearch = MemoryInfo.GetListContractByField(contractId, Contract.ContractFields.ContractId);
                var data      = lstSearch[0];
                if (data != null && data.IsDeleted == 1)
                {
                    data = null;
                }
                var res = new RequestErrorCode(true, null, null);
                if (data != null && data.IsDeleted == 1)
                {
                    res.DataResult = null;
                    return(Ok(res));
                }

                if (data != null)
                {
                    var lstPayment =
                        MemoryInfo.GetListPaymentByField(data.Id.ToString(), Payment.PaymentFields.IdContract);
                    var         customer = MemoryInfo.GetCustomer(data.IdCustomer);
                    ContractRes result   = new ContractRes(data, customer, lstPayment);
                    res.DataResult = result;
                    return(Ok(res));
                }
                res.DataResult = data;
                return(Ok(res));
            }
            catch (Exception ex)
            {
                Logger.Write(ex.ToString());
            }
            return(BadRequest("Unknow"));
        }
Exemplo n.º 10
0
        public static IEnumerable <MemoryInfo> EnumerateMemoryRegions(IntPtr handle, long maxSize = int.MaxValue)
        {
            long address = 0;
            bool x64     = Is64BitProcess(handle);

            do
            {
                int        result;
                MemoryInfo m;
                if (x64)
                {
                    result = Native.VirtualQueryEx64(handle, (IntPtr)address, out Native.MemoryBasicInformation64 m64, (uint)Marshal.SizeOf(typeof(Native.MemoryBasicInformation64)));
                    m      = new MemoryInfo(m64);
                }
                else
                {
                    result = Native.VirtualQueryEx32(handle, (IntPtr)address, out Native.MemoryBasicInformation32 m32, (uint)Marshal.SizeOf(typeof(Native.MemoryBasicInformation32)));
                    m      = new MemoryInfo(m32);
                }
                yield return(m);

                if (address == (long)m.BaseAddress + (long)m.RegionSize)
                {
                    break;
                }
                address = (long)m.BaseAddress + (long)m.RegionSize;
            } while (address <= maxSize);
        }
Exemplo n.º 11
0
        public PerformanceInfo()
        {
            MemoryInfo memory = GetMemoryInfo();

            CpuUsagePercent     = ComputerDatas.CpuUsage;
            FreePhysicalMemory  = memory.AvailablePhysical;
            TotalPhysicalMemory = memory.TotalPhysical;
            FreePageFile        = memory.AvailablePageFile;
            TotalPageFile       = memory.TotalPageFile;
            DriveInfo drive = DriveInfo.GetDrives().FirstOrDefault(p => p.Name == "C:\\");

            if (drive != null)
            {
                try
                {
                    MainDiskPartitionFreeSize  = drive.AvailableFreeSpace;
                    MainDiskPartitionTotalSize = drive.TotalSize;
                }
                catch
                {
                    MainDiskPartitionFreeSize  = -1;
                    MainDiskPartitionTotalSize = -1;
                }
            }
        }
Exemplo n.º 12
0
        public void SerializeTest()
        {
            SystemInfo info = new SystemInfo();

            info.groupKey  = "f31fc79434df8e4b7f9fd1f5bebe5b111baf8571";
            info.machineId = null;

            // quad-core
            CpuInfo cpu = new CpuInfo();

            cpu.unit.Add(15.5f);
            cpu.unit.Add(0.0f);
            cpu.unit.Add(0.0f);
            cpu.unit.Add(0.0f);

            cpu.total     = (float)(15.5 * 0.25);
            info.cpuUsage = cpu;

            MemoryInfo memoy = new MemoryInfo();

            memoy.max     = 8589934592; // 8 * 1024 * 1024 * 1024;
            memoy.current = 6442450944; // 6 * 1024 * 1024 * 1024;

            info.memoryUsage = memoy;

            string json = JsonConvert.SerializeObject(info);

            Trace.WriteLine(json);
        }
Exemplo n.º 13
0
        /// <summary>
        ///     获取 系统的内存信息
        /// </summary>
        /// <returns></returns>
        public static Task <MemoryInfo> GetWindowsMemoryStatus()
        {
            using var wmiObject = new ManagementObjectSearcher("select * from Win32_OperatingSystem");

            var memoryValue = wmiObject.Get().Cast <ManagementObject>().Select(mo => new
            {
                Free  = double.Parse(mo["FreePhysicalMemory"].ToString()) / 1024,
                Total = double.Parse(mo["TotalVisibleMemorySize"].ToString()) / 1024
            }).FirstOrDefault();

            if (memoryValue == default)
            {
                return(Task.FromResult(new MemoryInfo()));
            }

            var percent = (memoryValue.Total - memoryValue.Free) / memoryValue.Total;
            var result  = new MemoryInfo
            {
                Free       = memoryValue.Free,
                Percentage = percent,
                Total      = memoryValue.Total,
                Used       = memoryValue.Total - memoryValue.Free
            };

            return(Task.FromResult(result));
        }
Exemplo n.º 14
0
            public static MemoryInfo GetMemoryInfo()
            {
                MemoryInfo result;

                lock (MemoryInfQueue)
                {
                    if (MemoryInfQueue.Count < 1)
                    {
                        for (int i = 0; i < 10; i++)
                        {
                            byte[]     array  = new byte[BufferSize];
                            GCHandle   handle = GCHandle.Alloc(array, GCHandleType.Pinned);
                            MemoryInfo item   = new MemoryInfo
                            {
                                Buffer       = array,
                                Handle       = handle,
                                AddrOfBuffer = handle.AddrOfPinnedObject()
                            };
                            MemoryInfQueue.Enqueue(item);
                        }
                    }
                    result = MemoryInfQueue.Dequeue();
                }
                return(result);
            }
Exemplo n.º 15
0
        public static MemoryInfo GetMemoryInfo()
        {
            var memoryInfo = new MemoryInfo();

            try
            {
                memoryInfo.TotalSize = Convert.ToUInt64(Get_TotalPhysicalMemory());

                //memoryInfo.totalSizestr = CsharpLazycode.Module.HardDisk.size.Util.GetString(Convert.ToInt64(memoryInfo.totalSize));

                memoryInfo.TotalSizestr = Get_PhysicalMemoryStrGBvalue() + " GB";

                memoryInfo.Percent = (Convert.ToDecimal(Get_utilization_rate())).ToString("0.00") + "%";
            }
            catch (Exception ex)
            {
                memoryInfo.TotalSize    = 0;
                memoryInfo.TotalSizestr = "异常";
                memoryInfo.Percent      = "异常" + "%";

                var exErr = string.Format("异常[{0}]:{1}", System.Reflection.MethodBase.GetCurrentMethod().Name, ex.Message);
                Console.WriteLine(exErr);
            }

            return(memoryInfo);
        }
Exemplo n.º 16
0
 public async Task <IHttpActionResult> Get(int id)
 {
     try
     {
         #region token
         var header = Request.Headers;
         if (header.Authorization == null)
         {
             return(StatusCode(HttpStatusCode.Unauthorized));
         }
         var      token = header.Authorization.Parameter;
         Employee employee;
         if (string.IsNullOrWhiteSpace(token) || !TokenManager.ValidateToken(token, out employee))
         {
             return(StatusCode(HttpStatusCode.Unauthorized));
         }
         #endregion
         var data = MemoryInfo.GetProvider(id);
         if (data != null && data.IsDeleted == 1)
         {
             data = null;
         }
         var res = new RequestErrorCode(true, null, null);
         res.DataResult = data;
         return(Ok(res));
     }
     catch (Exception ex)
     {
         Logger.Write(ex.ToString());
     }
     return(BadRequest("Unknow"));
 }
Exemplo n.º 17
0
 public MemoryResult(MemoryInfo info)
 {
     Free     = info.FreeMemory;
     Occupied = info.TotalMemory - Free;
     Total    = info.TotalMemory;
     Usage    = info.UsedMemoryPercent;
 }
Exemplo n.º 18
0
 public async Task <IHttpActionResult> Get()
 {
     try
     {
         var lstData = MemoryInfo.GetAllContract();
         List <ContractRes> lstResult = new List <ContractRes>();
         if (lstData != null)
         {
             lstData = lstData.Where(x => x.IsDeleted != null && x.IsDeleted != 1).ToList();
         }
         var lstPayment = MemoryInfo.GetAllPayment();
         foreach (var item in lstData)
         {
             List <Payment> payments = new List <Payment>();
             payments = lstPayment.Where(x => x.IdContract == item.Id).ToList();
             var         customer = MemoryInfo.GetCustomer(item.IdCustomer);
             ContractRes temp     = new ContractRes(item, customer, payments);
             lstResult.Add(temp);
         }
         var res = new RequestErrorCode(true, null, null);
         res.ListDataResult.AddRange(lstResult);
         return(Ok(res));
     }
     catch (Exception ex)
     {
         Logger.Write(ex.ToString());
     }
     return(BadRequest("Unknow"));
 }
Exemplo n.º 19
0
        private void AddMemoryInfo(Contexts contexts)
        {
#if NETCOREAPP3_0_OR_GREATER
            var memory         = GC.GetGCMemoryInfo();
            var allocatedBytes = GC.GetTotalAllocatedBytes();
#if NET5_0_OR_GREATER
            contexts[MemoryInfoKey] = new MemoryInfo(
                allocatedBytes,
                memory.FragmentedBytes,
                memory.HeapSizeBytes,
                memory.HighMemoryLoadThresholdBytes,
                memory.TotalAvailableMemoryBytes,
                memory.MemoryLoadBytes,
                memory.TotalCommittedBytes,
                memory.PromotedBytes,
                memory.PinnedObjectsCount,
                memory.PauseTimePercentage,
                memory.Index,
                memory.Generation,
                memory.FinalizationPendingCount,
                memory.Compacted,
                memory.Concurrent,
                memory.PauseDurations.ToArray());
#else
            contexts[MemoryInfoKey] = new MemoryInfo(
                allocatedBytes,
                memory.FragmentedBytes,
                memory.HeapSizeBytes,
                memory.HighMemoryLoadThresholdBytes,
                memory.TotalAvailableMemoryBytes,
                memory.MemoryLoadBytes);
#endif
#endif
        }
        public async Task <IHttpActionResult> Get()
        {
            try
            {
                List <ServicesPackRes> lstResult = new List <ServicesPackRes>();
                var lstData = MemoryInfo.GetAllServicePack();
                foreach (var servicePack in lstData)
                {
                    if (servicePack.IsDeleted != 1)
                    {
                        string cnTypeName  = "";
                        var    connectType = MemoryInfo.GetConnectionType(servicePack.IdConnectionType);
                        if (connectType != null)
                        {
                            cnTypeName = connectType.Name;
                        }

                        var lstSvPackFee = MemoryInfo.GetListServicePackFeeByField(servicePack.Id.ToString(),
                                                                                   ServicePackFee.ServicePackFeeFields.IdServicePack);
                        ServicesPackRes itemRes = new ServicesPackRes(servicePack, cnTypeName, lstSvPackFee);
                        lstResult.Add(itemRes);
                    }
                }
                var res = new RequestErrorCode(true, null, null);
                res.ListDataResult.AddRange(lstResult);
                return(Ok(res));
            }
            catch (Exception ex)
            {
                Logger.Write(ex.ToString());
            }
            return(BadRequest("Unknow"));
        }
Exemplo n.º 21
0
        public async Task <IHttpActionResult> Delete(int id)
        {
            try
            {
                string errorMessage = "UnknowError";
                string errorCode    = ErrorCodeEnum.UnknownError.ToString();
                #region token
                var header = Request.Headers;
                if (header.Authorization == null)
                {
                    return(StatusCode(HttpStatusCode.Unauthorized));
                }
                var      token = header.Authorization.Parameter;
                Employee employee;
                if (string.IsNullOrWhiteSpace(token) || !TokenManager.ValidateToken(token, out employee))
                {
                    return(StatusCode(HttpStatusCode.Unauthorized));
                }
                #endregion

                #region Check exist
                var obj = MemoryInfo.GetEmployee(id);
                if (obj == null)
                {
                    return(Ok(new RequestErrorCode(false, ErrorCodeEnum.DataNotExist.ToString(), "Khong ton tai")));
                }
                #endregion

                bool isHasDeleteProperties = obj.GetType().GetProperty("IsDeleted") != null;
                if (!isHasDeleteProperties)
                {
                    return(Ok(new RequestErrorCode(false, ErrorCodeEnum.DataNotExist.ToString(), "Khong ton tai")));
                }
                obj.IsDeleted = 1;

                #region Process
                UpdateEntitySql updateEntitySql = new UpdateEntitySql();
                var             lstCommand      = new List <EntityCommand>();
                lstCommand.Add(new EntityCommand {
                    BaseEntity = new Entity.Entity(obj), EntityAction = EntityAction.Update
                });
                bool isOkDone = updateEntitySql.UpdateDefault(lstCommand);
                if (!isOkDone)
                {
                    return(Ok(new RequestErrorCode(false, errorCode, errorMessage)));
                }
                #endregion
                // update memory
                MemorySet.UpdateAndInsertEntity(obj);
                var result = new RequestErrorCode(true);
                result.DataResult = obj;
                return(Ok(result));
            }
            catch (Exception ex)
            {
                Logger.Write(ex.ToString());
            }
            return(BadRequest("Unknow"));
        }
Exemplo n.º 22
0
        public static int GetMemoryUsageRate()
        {
            // cif = new ComputerInfo();
            var memInfo = new MemoryInfo();

            GlobalMemoryStatus(ref memInfo);
            return((int)memInfo.dwMemoryLoad);
        }
Exemplo n.º 23
0
 public SystemMonitorService()
 {
     Info      = new SysInfo();
     Battery   = new BatteryInfo();
     Processor = new ProcessorInfo();
     Memory    = new MemoryInfo();
     Network   = new NetworkInfo();
 }
 /// <summary>
 /// 展示系统信息到标准输出流
 /// </summary>
 public static void Display()
 {
     Console.WriteLine("---- SystemInfo ----");
     Console.WriteLine($"Platform: {Platform}");
     Console.WriteLine($"IsContainer: {IsContainer}");
     Console.WriteLine("---- Memory ----");
     MemoryInfo.Display();
 }
Exemplo n.º 25
0
        /// <summary>
        /// 读取内存
        /// </summary>
        /// <returns></returns>
        private static MemoryInfo GetMemoryStatus()
        {
            MemoryInfo MemInfo;

            MemInfo = new MemoryInfo();
            GlobalMemoryStatus(ref MemInfo);
            return(MemInfo);
        }
Exemplo n.º 26
0
        public void ConstructMissing()
        {
            allValues.Clear();
            var        server = InfoTestsHelper.Create("Memory", allValues);
            MemoryInfo info   = new MemoryInfo(server);

            Assert.IsNull(info.UsedMemory);
            Assert.IsNull(info.MemoryFragmentation);
        }
 private void WriteMemoryTraffic(string name, MemoryInfo allocatedMemory, MemoryInfo collectedMemory)
 {
     _output.WriteLine("{4}: Allocated: {0} objects ({1} bytes). Collected: {2} objects ({3} bytes)",
                       allocatedMemory.ObjectsCount,
                       allocatedMemory.SizeInBytes,
                       collectedMemory.ObjectsCount,
                       collectedMemory.SizeInBytes,
                       name);
 }
Exemplo n.º 28
0
            public static MemoryInfo GetMemoryInfo(Context context)
            {
                var retVal = new MemoryInfo();

                retVal.MaxMemory   = Java.Lang.Runtime.GetRuntime().MaxMemory();
                retVal.FreeMemory  = Java.Lang.Runtime.GetRuntime().FreeMemory();
                retVal.TotalMemory = Java.Lang.Runtime.GetRuntime().TotalMemory();
                return(retVal);
            }
Exemplo n.º 29
0
        private void MemoryViewer_Load(object sender, EventArgs e)
        {
            for (int i = 0; i < 10; i++)
            {
                data[i] = new MemoryInfo(i, (byte)(10 - i));
            }

            dataGridView1.DataSource = data;
        }
Exemplo n.º 30
0
        private void btnStop_Click(object sender, EventArgs e)
        {
            stop_at = DateTime.Now;
            timer1.Stop();
            timerMemUsage.Stop();
            SetEnabled();

            SaveMemoryUsage();

            var processes2 = QueryProcessInfo(false);
            var join       = from p2 in processes2
                             from p1 in processes.Where(a => a.Id == p2.Id).DefaultIfEmpty()
                             let Meaning = (p1 == null) ? GetMeaning(GetCommandLine(p2.Id)) : p1.Meaning
                                           let TotalProcessorTime1 = (p1 == null) ? new TimeSpan() : p1.TotalProcessorTime
                                                                     orderby p2.ProcessName, Meaning, p2.Id
                select new
            {
                p2.Id,
                p2.ProcessName,
                Meaning,
                TotalMilliseconds = (p2.TotalProcessorTime - TotalProcessorTime1).TotalMilliseconds,
            };

            var    sb                     = new StringBuilder();
            var    delta_time             = (stop_at - start_at).TotalMilliseconds;
            string prev_line_process_name = "";
            double total_process_ms       = 0.0;

            foreach (var p in join)
            {
                if (prev_line_process_name != "" &&
                    prev_line_process_name != p.ProcessName)
                {
                    sb.AppendFormat("Total [{0}] {1} мс", prev_line_process_name, (Int64)total_process_ms);
                    sb.AppendLine();
                    sb.AppendLine();
                    total_process_ms = 0;
                }
                prev_line_process_name = p.ProcessName;
                total_process_ms      += p.TotalMilliseconds;
                MemoryInfo memoryInfo     = GetMemoryUsage(p.Id);
                string     memUsageString = GetMemoryString(memoryInfo);
                sb.AppendFormat(
                    "{2} {0} ({1}) {3} мс, {4:0.0}%, {5} ",
                    p.ProcessName,
                    p.Meaning,
                    p.Id,
                    (Int64)p.TotalMilliseconds,
                    100 * p.TotalMilliseconds / delta_time,
                    memUsageString
                    );
                sb.AppendLine();
            }
            sb.AppendFormat("Total [{0}] {1} мс", prev_line_process_name, (Int64)total_process_ms);
            textOutput.Text = sb.ToString();
        }
Exemplo n.º 31
0
 public RedisInfo()
 {
     Replication = new ReplicationInfo();
     Clients = new ClientInfo();
     Server = new ServerInfo();
     Memory = new MemoryInfo();
     Persistence = new PersistenceInfo();
     Stats = new StatsInfo();
     CPU = new CPUInfo();
     Keyspace = new KeyspaceInfo();
 }
Exemplo n.º 32
0
        public MemoryInfo GetMemoryInfoFromOperatingSystemClass()
        {
            var memoryInfo = new MemoryInfo();
            var query = new SelectQuery("Win32_OperatingSystem");
            var search = new ManagementObjectSearcher(query);
            foreach (ManagementObject info in search.Get())
            {
                memoryInfo.TotalPageFileSpace     = info["SizeStoredInPagingFiles"].ToString();
                memoryInfo.TotalPhysicalMemory    = info["TotalVisibleMemorySize"].ToString();
                memoryInfo.TotalVirtualMemory     = info["TotalVirtualMemorySize"].ToString();
                memoryInfo.AvailableVirtualMemory = info["FreeVirtualMemory"].ToString();
            }

            return memoryInfo;
        }
Exemplo n.º 33
0
        internal MemoryInfo GetMemoryInfoFromLogicalMemoryConfigurationClass()
        {
            var memoryInfo = new MemoryInfo();
            var query = new SelectQuery("Win32_LogicalMemoryConfiguration");
            var search = new ManagementObjectSearcher(query);

            foreach (ManagementObject info in search.Get())
            {
                memoryInfo.TotalPageFileSpace     = info["TotalPageFileSpace"].ToString();
                memoryInfo.TotalPhysicalMemory    = info["TotalPhysicalMemory"].ToString();
                memoryInfo.TotalVirtualMemory     = info["TotalVirtualMemory"].ToString();
                memoryInfo.AvailableVirtualMemory = info["AvailableVirtualMemory"].ToString();
            }

            return memoryInfo;
        }
        public static void GetBytesFromStringValueByType(string valueInString, string valueTypeInString, bool isUnicode, out byte[] valueInBytes, out MemoryInfo.ValueType valueType)
        {
            valueInBytes = null;
            valueType = MemoryInfo.ValueType.ArrayOfBytes;

            switch (valueTypeInString)
            {
                case "ArrayOfBytes":
                    {
                        valueType = MemoryInfo.ValueType.ArrayOfBytes;
                        var bytes = valueInString.Split(' ');
                        valueInBytes = new byte[bytes.Length];
                        for (int byteIndex = 0; byteIndex < bytes.Length; byteIndex++)
                        {
                            var value = byte.Parse(bytes[byteIndex]);
                            valueInBytes[byteIndex] = value;
                        }
                        break;
                    }
                case "Short":
                    {
                        valueType = MemoryInfo.ValueType.Short;
                        var value = short.Parse(valueInString);
                        valueInBytes = BitConverter.GetBytes(value);
                        break;
                    }
                case "Integer":
                    {
                        valueType = MemoryInfo.ValueType.Integer;
                        var value = int.Parse(valueInString);
                        valueInBytes = BitConverter.GetBytes(value);
                        break;
                    }
                case "Long":
                    {
                        valueType = MemoryInfo.ValueType.Long;
                        var value = long.Parse(valueInString);
                        valueInBytes = BitConverter.GetBytes(value);
                        break;
                    }
                case "Float":
                    {
                        valueType = MemoryInfo.ValueType.Float;
                        var value = float.Parse(valueInString);
                        valueInBytes = BitConverter.GetBytes(value);
                        break;
                    }
                case "Double":
                    {
                        valueType = MemoryInfo.ValueType.Double;
                        var value = double.Parse(valueInString);
                        valueInBytes = BitConverter.GetBytes(value);
                        break;
                    }
                case "String":
                    {
                        valueType = MemoryInfo.ValueType.String;
                        if (isUnicode)
                            valueInBytes = Encoding.Unicode.GetBytes(valueInString);
                        else
                            valueInBytes = Encoding.Default.GetBytes(valueInString);
                        break;
                    }
            }
        }
         /**/
         /// <summary>
         /// 查询CPU编号
         /// </summary>
         /// <returns></returns>
         public string GetCpuId()
         {
             ManagementClass mClass = new ManagementClass("Win32_Processor");
             ManagementObjectCollection moc = mClass.GetInstances();
             string cpuId=null;
             foreach (ManagementObject mo in moc)
             {
                 cpuId = mo.Properties["ProcessorId"].Value.ToString();
                 break;
             }
             return cpuId;
         }

        //获取计算机CPU的当前时钟频率
        public string GetCpuCurrentClockSpeed ()
        {
            ManagementClass mClass = new ManagementClass ( "Win32_Processor" );
            ManagementObjectCollection moc = mClass.GetInstances ();
            string strCurrentClockSpeed = null;
            foreach ( ManagementObject mo in moc )
            {
                float fHZ = ( ( float )Convert.ToInt16 ( mo.Properties [ "CurrentClockSpeed" ].Value ) ) / 1000 ;
                strCurrentClockSpeed = fHZ.ToString () + "GHz";
                break;
            }
            return strCurrentClockSpeed;
        }

        //获取计算机CPU的最大时钟频率
        public string GetCpuMaxClockSpeed ()
        {
            ManagementClass mClass = new ManagementClass ( "Win32_Processor" );
            ManagementObjectCollection moc = mClass.GetInstances ();
            string strMaxClockSpeed = null;
            foreach ( ManagementObject mo in moc )
            {
                float fHZ = ( ( float ) Convert.ToInt16 ( mo.Properties [ "MaxClockSpeed" ].Value ) ) / 1000;
                strMaxClockSpeed = fHZ.ToString () + "GHz";
                break;
            }
            return strMaxClockSpeed;
        }

        //获取计算机CPU的占用率
        public string GetCpuLoadPercentage ()
        {
            ManagementClass mClass = new ManagementClass ( "Win32_Processor" );
            ManagementObjectCollection moc = mClass.GetInstances ();
            string strLoadPercentage = null;
            foreach ( ManagementObject mo in moc )
            {
                strLoadPercentage = mo.Properties [ "LoadPercentage" ].Value.ToString () + "%";
                break;
            }
            return strLoadPercentage;
        }

        //获取计算机CPU的版本; eg:型号4 步进9
        public string GetCpuVersion ()
        {
            ManagementClass mClass = new ManagementClass ( "Win32_Processor" );
            ManagementObjectCollection moc = mClass.GetInstances ();
            string strVersion = null;
            foreach ( ManagementObject mo in moc )
            {
                strVersion = mo.Properties [ "Version" ].Value.ToString () ;
                break;
            }
            return strVersion;
        }

        //获取计算机CPU的产品名称 ; eg:"Intel(R) Pentium(R) 4 CPU 2.80GHz"
        public string GetCpuName ()
        {
            ManagementClass mClass = new ManagementClass ( "Win32_Processor" );
            ManagementObjectCollection moc = mClass.GetInstances ();
            string strName = null;
            foreach ( ManagementObject mo in moc )
            {
                strName = mo.Properties [ "Name" ].Value.ToString ();
                break;
            }
            return strName.Trim ();
        }

        //获取计算机CPU的制造商 
        public string GetCpuManufacturer ()
        {
            ManagementClass mClass = new ManagementClass ( "Win32_Processor" );
            ManagementObjectCollection moc = mClass.GetInstances ();
            string strManufacturer = null;
            foreach ( ManagementObject mo in moc )
            {
                strManufacturer = mo.Properties [ "Manufacturer" ].Value.ToString ();
                break;
            }
            return strManufacturer;
        }

        //获取计算机CPU的当前电压 
        public string GetCpuCurrentVoltage ()
        {
            ManagementClass mClass = new ManagementClass ( "Win32_Processor" );
            ManagementObjectCollection moc = mClass.GetInstances ();
            string strCurrentVoltage = null;
            foreach ( ManagementObject mo in moc )
            {
                strCurrentVoltage = mo.Properties [ "CurrentVoltage" ].Value.ToString ();
                break;
            }
            return strCurrentVoltage;
        }

        #endregion

         #region Memo

        /**/
        /// <summary>
        /// 获取系统内存信息
        /// </summary>
        /// <returns></returns>
        public MemoryInfo GetMemoryInfo ()
        {
            MemoryInfo memoryInfo = new MemoryInfo ();
            GlobalMemoryStatus ( ref memoryInfo );
            return memoryInfo;
        }
Exemplo n.º 36
0
 internal static extern void GlobalMemoryStatus(ref MemoryInfo meminfo);
 private static extern void GlobalMemoryStatus(ref MemoryInfo memInfo);