JavaFx lineChart real-time Monitor   about memory

 public class EffectTest extends Application {

 StackPane root;
private static int MAX_DATA_POINTS = ;
private static int Y_DATA_RANGE = ;
private static int TICK_UNIT = ; private static int UPDATE_INTERVAL_MS = ;
private LineChart.Series<Number, Number> series1;
private LineChart<Number, Number> lineChart;
private NumberAxis xAxis = new NumberAxis();
private NumberAxis yAxis = new NumberAxis(); private SequentialTransition animation;
private Paint paintXticklabel;
private double nextX = ; Random rnd = new Random();
double currentMemBAK=;
public EffectTest() { Timeline timeline = new Timeline();
timeline.getKeyFrames().add(new KeyFrame(Duration.millis(UPDATE_INTERVAL_MS*), new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent actionEvent) { // update chart data
// note that we add one data point and remove one data point in this simple example.
// in a production environment you'd have to add multiple and remove multiple data points double currentMem= Runtime.getRuntime().totalMemory()-Runtime.getRuntime().freeMemory();
double drawy =(currentMem-currentMemBAK)/;
currentMemBAK=currentMem;
System.out.println("currentMem:"+currentMem);
// add new points
//series1.getData().add(new XYChart.Data<Number, Number>(nextX, Math.cos(Math.toRadians(nextX)) * Y_DATA_RANGE)); //mem
series1.getData().add(new XYChart.Data<Number, Number>(nextX, drawy+)); //cpu
//series1.getData().add(new XYChart.Data<Number, Number>(nextX, getCpuRatioForWindows())); // remove points that shouldn't be visible anymore
if (series1.getData().size() > MAX_DATA_POINTS) {
series1.getData().remove(); }
System.out.println("node size:"+series1.getData().size()); nextX += ; // update using series 1 as reference
// series 2 contains same amount of data; if it doesn't for your case,
// you need to adapt this here and calculate the proper range
List<Data<Number, Number>> data = series1.getData();
xAxis.setLowerBound(data.get().getXValue().doubleValue());
xAxis.setUpperBound(data.get(data.size() - ).getXValue().doubleValue()); ////////
lineChart.getXAxis().setTickLabelFill(paintXticklabel); // xAxis.setTickUnit(1);
root.setTranslateX(-); }
}));
timeline.setCycleCount(Animation.INDEFINITE); animation = new SequentialTransition();
animation.getChildren().addAll(timeline);
} public Parent createContent() { xAxis = new NumberAxis();
xAxis.setForceZeroInRange(false);
xAxis.setAutoRanging(false);
xAxis.setTickLabelsVisible(false);
xAxis.setTickMarkVisible(false);
xAxis.setMinorTickVisible(false);
xAxis=new NumberAxis(, Y_DATA_RANGE+, TICK_UNIT/); // set Axis property
// final NumberAxis yAxis = new NumberAxis(1, 21, 0.1);
// xAxis.setTickUnit(1);
// xAxis.setPrefWidth(35);
// xAxis.setMinorTickCount(10);
// xAxis.setSide(Side.RIGHT);
// xAxis.setTickLabelFormatter(new NumberAxis.DefaultFormatter(xAxis) {
// @Override
// public String toString(Number object) {
// String label;
// label = String.format("%7.2f", object.floatValue());
// return label;
// }
// }); //yAxis = new NumberAxis(-Y_DATA_RANGE, Y_DATA_RANGE, TICK_UNIT);
yAxis = new NumberAxis(, Y_DATA_RANGE+, TICK_UNIT/);
yAxis.setAutoRanging(false); lineChart = new LineChart<>(xAxis, yAxis);
lineChart.setAnimated(false);
lineChart.setLegendVisible(false); //set if dont want symbols on the point
lineChart.setCreateSymbols(false);
series1 = new LineChart.Series<>();
// series1.getData().add(new LineChart.Data<Number, Number>(0d, 0d));
lineChart.getData().add(series1); //save ticklabe
paintXticklabel=xAxis.getTickLabelFill();
return lineChart;
} public void play() {
animation.play();
} @Override
public void stop() {
animation.pause();
} @Override
public void start(Stage primaryStage) throws Exception { primaryStage.setTitle("Drawing Operations Test"); root = new StackPane();
root.getChildren().add(createContent()); Scene s= new Scene(root);
primaryStage.setScene(s);
primaryStage.show(); play();
} public static void main(String[] args) {
launch(args);
// getCpuRatioForWindows() ;
System.out.println(getCpuRatioForWindows()); } private static final int CPUTIME = ;
private static final int PERCENT = ; public static double getCpuRatioForWindows()
{
try
{
String procCmd =
System.getenv("windir")
+ "\\system32\\wbem\\wmic.exe process get Caption,CommandLine,KernelModeTime,ReadOperationCount,ThreadCount,UserModeTime,WriteOperationCount"; long[] c0 = readCpu(Runtime.getRuntime().exec(procCmd));
Thread.sleep(CPUTIME);
long[] c1 = readCpu(Runtime.getRuntime().exec(procCmd));
if (c0 != null && c1 != null)
{
long idletime = c1[] - c0[];
long busytime = c1[] - c0[];
return Double.valueOf(PERCENT * (busytime) * 1.0 / (busytime + idletime)).intValue() ;
}
else
{
return ;
}
}
catch (Exception ex)
{
ex.printStackTrace();
return ;
}
}
private static final int FAULTLENGTH = ;
private static long[] readCpu(final Process proc)
{
long[] retn = new long[];
try
{
proc.getOutputStream().close();
InputStreamReader ir = new InputStreamReader(proc.getInputStream());
LineNumberReader input = new LineNumberReader(ir);
String line = input.readLine();
if (line == null || line.length() < FAULTLENGTH)
{
return null;
}
int capidx = line.indexOf("Caption");
int cmdidx = line.indexOf("CommandLine");
int rocidx = line.indexOf("ReadOperationCount");
int umtidx = line.indexOf("UserModeTime");
int kmtidx = line.indexOf("KernelModeTime");
int wocidx = line.indexOf("WriteOperationCount");
long idletime = ;
long kneltime = ;
long usertime = ;
while ((line = input.readLine()) != null)
{
if (line.length() < wocidx)
{
continue;
}
//Caption,CommandLine,KernelModeTime,ReadOperationCount,
// ThreadCount,UserModeTime,WriteOperation
String caption = substring(line, capidx, cmdidx - ).trim();
String cmd = substring(line, cmdidx, kmtidx - ).trim();
if (cmd.indexOf("wmic.exe") >= )
{
continue;
}
String s1 = substring(line, kmtidx, rocidx - ).trim();
String s2 = substring(line, umtidx, wocidx - ).trim();
if (caption.equals("System Idle Process") || caption.equals("System"))
{
if (s1.length() > )
idletime += Long.valueOf(s1).longValue();
if (s2.length() > )
idletime += Long.valueOf(s2).longValue();
continue;
}
if (s1.length() > )
kneltime += Long.valueOf(s1).longValue();
if (s2.length() > )
usertime += Long.valueOf(s2).longValue();
}
retn[] = idletime;
retn[] = kneltime + usertime;
return retn;
}
catch (Exception ex)
{
ex.printStackTrace();
}
finally
{
try
{
proc.getInputStream().close();
}
catch (Exception e)
{
e.printStackTrace();
}
}
return null;
}
private static String substring(String src, int start_idx, int end_idx)
{
byte[] b = src.getBytes();
String tgt = "";
for (int i = start_idx; i <= end_idx; i++)
{
tgt += (char)b[i];
}
return tgt;
}
}

JavaFx lineChart real-time Monitor的更多相关文章

  1. nginx performance monitor

    nginx performance monitor Nginx中的stub_status模块主要用于查看Nginx的一些状态信息 示例 Active connections: 2 server acc ...

  2. JavaFx 中常见的包和类(javafx笔记 )

    JavaFx 中常见的包和类(javafx笔记 ) 更多详细内容请参考<Pro JavaFX 8>. javafx.stage 包包含以下类: Stage 类 ​ Stage 类是任何 J ...

  3. JavaFx 监听剪切板实现(Kotlin)

    原文地址: JavaFx 监听剪切板实现(Kotlin) | Stars-One的杂货小窝 软件有个需求,想要实现监听剪切板的内容,若内容符合预期,则进行相关的操作,就可以免去用户手动粘贴的操作,提供 ...

  4. C#各种同步方法 lock, Monitor,Mutex, Semaphore, Interlocked, ReaderWriterLock,AutoResetEvent, ManualResetEvent

    看下组织结构: System.Object System.MarshalByRefObject System.Threading.WaitHandle System.Threading.Mutex S ...

  5. API Monitor简介(API监控工具)

    API Monitor是一个免费软件,可以让你监视和控制应用程序和服务,取得了API调用. 它是一个强大的工具,看到的应用程序和服务是如何工作的,或跟踪,你在自己的应用程序的问题. 64位支持 API ...

  6. 创建 Monitor 并测试 - 每天5分钟玩转 OpenStack(124)

    前面我们创建了 Pool,VIP 并添加了 Member.今天将创建 Monitor,然后测试 LBaaS 是否能够正常工作. 创建 Monitor LBaaS 可以创建 monitor,用于监控 P ...

  7. MPAndroidChart 3.0——LineChart(折线图)

    显示效果 MPAndroidChart每一种图表的基本使用方式都基本相同 了解一种图表的实现 参考项目源码其他的图表也就差不多哩 在布局文件中定义 <com.github.mikephil.ch ...

  8. 11g新特性:Health Monitor Checks

    一.什么是Health Monitor ChecksHealth Monitor Checks能够发现文件损坏,物理.逻辑块损坏,undo.redo损坏,数据字典损坏等等.Health Monitor ...

  9. 问题记录:JavaFx 鼠标滑轮滚动事件监听!

    问题描述: 在listview的item里面添加鼠标拖拽排序功能.代码如下: setOnMouseDragged(event -> { //设定鼠标长按0.3秒后才可拖拽 防止误操作 isCan ...

随机推荐

  1. script指定src后内部代码无效

    /********** 无效 ***************/ <script type="text/javascript" src=""> fun ...

  2. cocos2d-x 显示触摸操作(显示水波点击效果,用于视频演示)

    昨天刚刚參加玩游戏设计大赛, 积累了一些东西. 接下去将会逐个分享出来. 首先是显示触摸操作. 由于要演示我们的作品.使用试玩过程中, 假设没办法显示我们的触摸操作(像录制视频一样, 点击了屏幕某点, ...

  3. 网络芯片应用:GPS公交车行驶记录仪

    项目描写叙述 佛罗里达大学学生 Miles Moody 使用WIZnet W5200以太网插板及Arduino Nano剖析了来自一个当地网页服务的HTML代码,并讲述了他每天带着公交车实时GPS坐标 ...

  4. poj--3281-- DiningI(最大流)

    Dining Time Limit: 2000MS   Memory Limit: 65536KB   64bit IO Format: %I64d & %I64u Submit Status ...

  5. AtCoder Beginner Contest 067 C - Splitting Pi

    C - Splitting Pile Time limit : 2sec / Memory limit : 256MB Score : 300 points Problem Statement Snu ...

  6. 实现人脸识别性别之路---open CV将图片显示出来

    import cv2filename='E:\\tensorflow\\bu.jpg'#图片的地址 # face_cascade=cv2.CascadeClassifier('C:\\anconda3 ...

  7. NOIP愤怒的小鸟

    愤怒的小鸟 Description: 给你\(n<=18\)个小猪,发射的小鸟轨迹为抛物线,求最小用多少个小鸟可以将小猪全部干掉 看到n很小,我想到了搜索,于是我用\(dfs\)枚举出,每个抛物 ...

  8. 【Linux下禁用rm命令之建立回收站】

    第一步 创建回收站目录 # 根据自己的习惯,找个位置创建一个用作回收文件的目录 # 我们这里将在root目录下面创建一个名为".trash"的隐藏文件 [root@fedora ~ ...

  9. python关于sorted里面key,reverse以及lamdba,operator这几个鸟人

     关于sorted:   help里给的解释 >>> help(sorted) Help on built-in function sorted in module __builti ...

  10. 比JLRoutes更强大更好用的iOS开源路由框架—FFRouter

    目前iOS常用路由框架是JLRouter.HHRouter.MGJRouter. 但是这些路由库都各有不足,首先是JLRouter,用不到的功能繁多,而且基于遍历查找URL,效率低下.HHRouter ...