提高cpu和内存利用率

CPU

*Linux 64 bit OS下载方式

wget https://cdn.pmylund.com/files/tools/cpuburn/linux/cpuburn-1.0-amd64.tar.gz
  • Linux 32 bit OS 下载地址
https://cdn.pmylund.com/files/tools/cpuburn/linux/cpuburn-1.0-i386.tar.gz

解压:

tar -xzvf cpuburn-1.0-amd64.tar.gz
cd cpuburn

运行:

./cpuburn -n 2 -u 5             #-n 2 表示运行在cpu的其中两个核心上   -u 5表示没5秒更新一次

后台运行

 nohup ./cpuburn -n 6 -u 5 &

查看进程

ps -ef | grep cpuburn

在这里插入图片描述

关闭进程

kill 22541

make

Centos中无法使用make命令

内存

在Linux系统的服务器上使用Memtester进行内存压力测试

nohup memtester 10G  &

查看进程

ps  -ef |grep memtester

在这里插入图片描述

根据网友提供代码,逆向画出来的。包含CPU使用率、内存使用率、虚拟内存使用率、内存总量等。数据比较符合靠谱。 ***************************************************************************** using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Diagnostics; using System.Threading; using System.Runtime.InteropServices; using System.Management; namespace Cpu_Test { public partial class Form1 : Form { public Form1() { InitializeComponent(); } Process[] MyProcesses; Thread td; private void myUser() { ManagementObjectSearcher searcher = new ManagementObjectSearcher("select * from Win32_Processor"); foreach (ManagementObject myobject in searcher.Get()) { tssluse.Text = myobject["LoadPercentage"].ToString() + " %"; lblCPU.Text = myobject["LoadPercentage"].ToString() + " %"; mheight = Convert.ToInt32(myobject["LoadPercentage"].ToString()); if (mheight == 100) panel3.Height = 100; CreateImage(); Memory(); } } private void Memory() { Microsoft.VisualBasic.Devices.Computer myInfo = new Microsoft.VisualBasic.Devices.Computer(); //获取物理内存总量 pbMemorySum.Maximum = Convert.ToInt32(myInfo.Info.TotalPhysicalMemory / 1024 / 1024); pbMemorySum.Value = Convert.ToInt32(myInfo.Info.TotalPhysicalMemory / 1024 / 1024); lblSum.Text = (myInfo.Info.TotalPhysicalMemory / 1024).ToString(); //获取可用物理内存总量 pbMemoryUse.Maximum = Convert.ToInt32(myInfo.Info.TotalPhysicalMemory / 1024 / 1024); pbMemoryUse.Value = Convert.ToInt32(myInfo.Info.AvailablePhysicalMemory / 1024 / 1024); lblMuse.Text = (myInfo.Info.AvailablePhysicalMemory / 1024).ToString(); //获取虚拟内存总量 pbVmemorysum.Maximum = Convert.ToInt32(myInfo.Info.TotalVirtualMemory / 1024 / 1024); pbVmemorysum.Value = Convert.ToInt32(myInfo.Info.TotalVirtualMemory / 1024 / 1024); lblVinfo.Text = (myInfo.Info.TotalVirtualMemory / 1024).ToString(); //获取可用虚拟内存总量 pbVmemoryuse.Maximum = Convert.ToInt32(myInfo.Info.TotalVirtualMemory / 1024 / 1024); pbVmemoryuse.Value = Convert.ToInt32(myInfo.Info.AvailableVirtualMemory / 1024 / 1024); lblVuse.Text = (myInfo.Info.AvailableVirtualMemory / 1024).ToString(); } private void Form1_Load(object sender, EventArgs e) { CheckForIllegalCrossThreadCalls = false; MyProcesses = Process.GetProcesses(); //tsslNum.Text = "进程数: "; tsslNum.Text = "进程数: "+ MyProcesses.Length.ToString()+ " CPU使用: "; myUser(); } private void timer1_Tick(object sender, EventArgs e) { Control.CheckForIllegalCrossThreadCalls = false; MyProcesses = Process.GetProcesses(); tsslNum.Text = "进程数: " + MyProcesses.Length.ToString() + " | CPU使用:"; td = new Thread(new ThreadStart(myUser)); td.Start(); } private void Form1_FormClosed(object sender, FormClosedEventArgs e) { if (td != null) { td.Abort(); } } int mheight = 0; private void CreateImage() { int i = panel3.Height / 100; Bitmap image = new Bitmap(panel3.Width, panel3.Height); Graphics g = Graphics.FromImage(image); g.Clear(Color.Green); SolidBrush mybrush = new SolidBrush(Color.Lime); g.FillRectangle(mybrush, 0, panel3.Height - mheight * i, 26, mheight * i); panel3.BackgroundImage = image; } } }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值