WPF使用DynamicDataDisplay.dll显示CPU及内存使用曲线
原文:WPF使用DynamicDataDisplay.dll显示CPU及内存使用曲线
DynamicDataDisplay.dll是一个添加动态数据到您的Silverlight或WPF应用程序交互的可视化控件。它允许创建线图,气泡图,热图和其他复杂的二维图,这是非常常见的科学软件。
DynamicDataDisplay sample charts:
下载地址如下:
http://dynamicdatadisplay.codeplex.com/
首先创建一个WPF工程,在引用上右键选择“添加引用”,找到下载好的DynamicDataDisplay.dll;
其次在.cs文件中加入引用集:
using Microsoft.Research.DynamicDataDisplay;
using Microsoft.Research.DynamicDataDisplay.DataSources;
private ObservableDataSource dataSource = new ObservableDataSource(); // 动态存储图表坐标点
private PerformanceCounter cpuPerformance = new PerformanceCounter(); //表示Windows NT的性能组件
private DispatcherTimer timer = new DispatcherTimer();//创建一个定时器
定义一个函数用于获取CPU和内存的数据:
private void AnimatedPlot(object sender, EventArgs e)
{
cpuPerformance.CategoryName = "Processor";
cpuPerformance.CounterName = "% Processor Time";
cpuPerformance.InstanceName = "_Total";
double
x = i;
//调试的时候,无法调用NextValue()函数,需要把y赋一个固定的值
double y = cpuPerformance.NextValue();
if (maxCpu < y)
{
maxCpu = y;
}
//double y = 12;
double MemoryUse = Process.GetCurrentProcess().PrivateMemorySize64 / 1024.0 / 1024.0;
//获取使用内存
Point point = new Point(x, y);
dataSource.AppendAsync(base.Dispatcher, point);
cpuUsageText.Text
= String.Format("{0:0}%", y); //cpuUsageText为TextBlock控件,显示CPU使用率
cpuMaxText.Text = String.Format("{0:0}%", maxCpu);//cpuMaxText为TextBlock控件,显示CPU最大使用率
memoryUsageText.Text = MemoryUse.ToString("F02");//memoryUsageText为TextBlock控件,显示占用内存大小
i++;
}
注意:在VS调试代码的过程中,NextValue()函数会报错!!需要将y赋值为常数。
接下来就是显示图像了:
public void StartCpuShow()
{
plotter.AddLineGraph(dataSource, Colors.Green, 2, "Percentage"); //设置图像中线的相关信息
timer.Interval = TimeSpan.FromSeconds(1);
timer.Tick += new EventHandler(AnimatedPlot);
timer.IsEnabled = true; plotter.Viewport.FitToView();
}
在xaml文件中添加命名空间:
xmlns:d3="http://research.microsoft.com/DynamicDataDisplay/1.0"
通过<d3:ChartPlotter> 创建一个图表框架;
在其中添加两条整型坐标轴:
X轴:<d3:HorizontalIntegerAxis>
Y轴:<d3:VerticalIntegerAxis>
<d3:Header> 用来设置图表名称
<d3:VerticalAxisTitle> 用来设置Y轴名称。
<d3:ChartPlotter
x:Name="plotter" Margin="10,10,33,10" Grid.Row="1" Background="Transparent" Foreground="#FF00DBE7">
<d3:ChartPlotter.VerticalAxis>
<d3:VerticalIntegerAxis
Foreground="#FF00DBE7"/>
</d3:ChartPlotter.VerticalAxis>
<d3:ChartPlotter.HorizontalAxis
>
<d3:HorizontalIntegerAxis
Foreground="#FF00DBE7"/>
</d3:ChartPlotter.HorizontalAxis>
<d3:Header
Content="CPU Performance History" Foreground="#FF00DBE7"/>
</d3:ChartPlotter>
最后需要注意的是,很多系统无法运行该程序。注意是需要重建性能计数器才可以使用查看CPU等功能
重建方法如下:
运行cmd 命令行
输入 lodctr/R
等待重建性能计数器
最后上效果图:
如有疑问 wangshubo1989@126.com
WPF使用DynamicDataDisplay.dll显示CPU及内存使用曲线的更多相关文章
- lunix脚本进程挂掉时显示cpu和内存信息及挂掉的时间
#!/bin/shwhile [ true ]; do #查询是否有8899正在运行的进程netstat -an|grep 8899if [ $? -ne 0 ]thennowtime=$(date ...
- Ubuntu 16.04 标题栏实时显示上下行网速、CPU及内存使用率--indicator-sysmonitor
---------------------------------------------------------------------------- 原文地址:http://blog.csdn.N ...
- Ubuntu 16.04 标题栏实时显示上下行网速、CPU及内存使用率
有时感觉网络失去响应,就通过Ubuntu 14.04自带的系统监视器程序来查看当前网速,但是这样很不方便,遂打算让网速显示在标题栏,那样就随时可直观的看到.一番搜索尝试后,成功实现!同时也实现了CPU ...
- 用户登陆显示cpu、负载、内存信息
#用户登陆显示cpu.负载.内存信息 #!/bin/bash # hostip=`ifconfig eth0 |awk -F" +|:" '/Bcast/{print $4}'` ...
- iOS开发 - 在状态栏显示FPS,CPU和内存信息
原理 FPS的计算 CoreAnimation有一个很好用的类CADisplayLink,这个类会在每一帧绘制之前调用,并且可以获取时间戳.于是,我们只要统计出,在1s内的帧数即可. - (void) ...
- CPU与内存的那些事
下面是网上看到的一些关于内存和CPU方面的一些很不错的文章. 整理如下: 转: CPU的等待有多久? 原文标题:What Your Computer Does While You Wait 原文地址: ...
- 转:CPU与内存的那些事
下面是网上看到的一些关于内存和CPU方面的一些很不错的文章. 整理如下: 转: CPU的等待有多久? 原文标题:What Your Computer Does While You Wait 原文地址: ...
- CPU与内存(经典问答)
原文:http://www.cnblogs.com/xkfz007/archive/2012/10/08/2715163.html 下面是网上看到的一些关于内存和CPU方面的一些很不错的文章. 整理如 ...
- 【转】CPU与内存的那些事
下面是网上看到的一些关于内存和CPU方面的一些很不错的文章. 整理如下: 转: CPU的等待有多久? 原文标题:What Your Computer Does While You Wait 原文地址: ...
随机推荐
- [Angular2 Form] Create custom form component using Control Value Accessor
//switch-control component import { Component } from '@angular/core'; import { ControlValueAccessor, ...
- [Node.js] Use nodejs-dashboard event loop delay with hrtime()
In this lesson, you will learn how to use the Formidable nodejs-dashboard event loop delay to identi ...
- ios开发网络学习二:URL转码以及字典转模型框架MJExtension的使用
一:url转码,当url中涉及到中文的时候,要考虑转码,用UTF8对中文的url进行转码 #import "ViewController.h" @interface ViewCon ...
- MySQL搜索:WHERE
MySQL指定搜索条件进行搜索能够使用where条件. 在SELECT语句中.数据依据WHERE子语句中指定的条件进行过滤,WHERE子语句在表名之后给出. product表例如以下: a 查找价格等 ...
- php实现 密码验证合格程序(复杂问题分类,超简单的)(分类+规范编码)
php实现 密码验证合格程序(复杂问题分类,超简单的)(分类+规范编码) 一.总结 一句话总结:复杂问题分类,超简单的.分类+规范编码. 1.写的时候判断 不能有相同长度超2的子串重复 的时候,子 ...
- [Angular] NgRx/effect, why to use it?
See the current implementaion of code, we have a smart component, and inside the smart component we ...
- js字符串转换为数字的三种方法。(转换函数)(强制类型转换)(利用js变量弱类型转换)
js字符串转换为数字的三种方法.(转换函数)(强制类型转换)(利用js变量弱类型转换) 一.总结 js字符串转换为数字的三种方法(parseInt("1234blue"))(Num ...
- PHP接口类interface使用方法
PHP同大多数的面向对象语言一样,并不支持多重继承.少数支持多重继承的语言中最著名的就是C++和Smalltalk.如果需要实现多重继承功能,在PHP中,可以通过接口,它是PHP解决多重继承问题的方法 ...
- [NPM] Use package.json variables in npm scripts
In this lesson we will show that you can leverage values that you already have provided in your pack ...
- 真机测试时出现 could not find developer disk image问题
解决Xcode在ipad/iphone 系统真机测试时出现could not find developer disk image问题 原因:手机系统版本比xcode版本高,sdk不支持 方法:更新Xc ...