Skip to content

Commit

Permalink
2014040201
Browse files Browse the repository at this point in the history
  • Loading branch information
Sneezry committed Apr 1, 2014
1 parent cf52bd7 commit af8531d
Show file tree
Hide file tree
Showing 9 changed files with 1,707 additions and 0 deletions.
1,431 changes: 1,431 additions & 0 deletions performance monitor/Chart.js

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions performance monitor/background.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
chrome.app.runtime.onLaunched.addListener(function() {
var main_window = chrome.app.window.get('main');
if(main_window){
main_window.show();
}
else{
chrome.app.window.create('main.html', {
//'id': 'main',
'bounds': {
'width': 542,
'height': 360
},
'resizable': false,
'frame': 'none'
});
}
});
9 changes: 9 additions & 0 deletions performance monitor/control.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
var current_window = chrome.app.window.current();

document.getElementById('minimize').onclick = function(){
current_window.minimize();
}

document.getElementById('close').onclick = function(){
current_window.close();
}
Binary file added performance monitor/images/icon128.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added performance monitor/images/icon16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added performance monitor/images/icon48.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
76 changes: 76 additions & 0 deletions performance monitor/main.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<html>
<head>
<title>Performance Monitor</title>
<style>
body {
margin: 0;
padding: 0;
border: #EEE 1px solid;
}

#title_bar {
-webkit-app-region: drag;
height: 22px;
line-height: 22px;
font-size: 16px;
background: #EEE;
padding: 0 10px;
box-sizing: border-box;
}

#title_bar a {
-webkit-app-region: no-drag;
display: inline-block;
float: right;
height: 12px;
width: 12px;
margin: 5px;
border: gray 1px solid;
box-sizing: border-box;
border-radius: 6px;
}

#title_bar a:hover {
background: gray;
}

#box_body {
padding: 20px;
}

.chart {
margin-bottom: 20px;
font-size: 0;
}

.urge_item {
color: gray;
padding: 2px 0;
font-size: 14px;
border-bottom: #EEE 1px solid;
margin-bottom: 4px;
}
</style>
</head>
<body>
<div id="title_bar">Performance Monitor
<a id="close" href="#"></a>
<a id="minimize" href="#"></a>
</div>
<div id="box_body">
<div class="urge_item">CPU Urge</div>
<div class="chart">
<canvas id="cpu_total" width="100" height="100"></canvas>
<canvas id="cpu_history" width="400" height="100"></canvas>
</div>
<div class="urge_item">Memory Urge</div>
<div class="chart">
<canvas id="mem_total" width="100" height="100"></canvas>
<canvas id="mem_history" width="400" height="100"></canvas>
</div>
</div>
<script src="control.js"></script>
<script src="Chart.js"></script>
<script src="main.js"></script>
</body>
</html>
154 changes: 154 additions & 0 deletions performance monitor/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
function getCpuUrge(callback){
chrome.system.cpu.getInfo(function(info){
var total = 0;
var user = 0;
var kernel = 0;
for(var i=0; i<info.processors.length; i++){
total += info.processors[i].usage.total - cpu_history.last_total[i];
cpu_history.last_total[i] = info.processors[i].usage.total;
user += info.processors[i].usage.user - cpu_history.last_user[i];
cpu_history.last_user[i] = info.processors[i].usage.user;
kernel += info.processors[i].usage.kernel - cpu_history.last_kernel[i];
cpu_history.last_kernel[i] = info.processors[i].usage.kernel;
}
user = Math.round(user/total*100);
kernel = Math.round(kernel/total*100);
callback({user:user,kernel:kernel,total:user+kernel});
});
}

function getMemUrge(callback){
chrome.system.memory.getInfo(function(info){
callback(info);
});
}

function updateCpuHistory(){
getCpuUrge(function(urge){
cpu_history.user.shift();
cpu_history.user.push(urge.user);
cpu_history.kernel.shift();
cpu_history.kernel.push(urge.kernel);
cpu_history.total.shift();
cpu_history.total.push(urge.total);
showCpu();
});
}

function updateMemHistory(){
getMemUrge(function(urge){
mem_history.used.shift();
mem_history.used.push(Math.round((urge.capacity-urge.availableCapacity)/urge.capacity*100));
showMem();
});
}

function updateData(){
updateCpuHistory();
updateMemHistory();
}

function showCpu(){
var history = {
labels : (function(){for(var i=0,labels=[];i<ponits_num;labels.push(''),i++);return labels;})(),
datasets : [
{
fillColor : "rgba(220,220,220,0.5)",
data : cpu_history.total
},
{
fillColor : "rgba(90,140,255,0.5)",
data : cpu_history.kernel
},
{
fillColor : "rgba(255,90,90,0.5)",
data : cpu_history.user
}
]
};

var now = [
{
value: cpu_history.total[ponits_num-1],
color:"rgba(220,220,220,0.7)"
},
{
value : 100-cpu_history.total[ponits_num-1],
color : "rgba(220,220,220,0.3)"
}
];
var his_ctx = document.getElementById('cpu_history').getContext("2d");
var now_ctx = document.getElementById("cpu_total").getContext("2d");
new Chart(his_ctx).Line(history, {scaleFontSize:4,pointDot:false,animation:false});
new Chart(now_ctx).Pie(now, {segmentShowStroke:false,animation:false});
}

function showMem(){
var history = {
labels : (function(){for(var i=0,labels=[];i<ponits_num;labels.push(''),i++);return labels;})(),
datasets : [
{
fillColor : "rgba(220,220,220,0.5)",
data : mem_history.used
}
]
};

var now = [
{
value: mem_history.used[ponits_num-1],
color:"rgba(220,220,220,0.7)"
},
{
value : 100-mem_history.used[ponits_num-1],
color : "rgba(220,220,220,0.3)"
}
];
var his_ctx = document.getElementById('mem_history').getContext("2d");
var now_ctx = document.getElementById("mem_total").getContext("2d");
new Chart(his_ctx).Line(history, {scaleFontSize:4,pointDot:false,animation:false});
new Chart(now_ctx).Pie(now, {segmentShowStroke:false,animation:false});
}

function init(){
cpu_history = {
user: [],
kernel: [],
total: [],
last_user: [],
last_kernel: [],
last_total: []
};
mem_history = {
used: []
};
init_cpu_history();
}

function init_cpu_history(){
for(var i=0; i<ponits_num; i++){
cpu_history.user.push(0);
cpu_history.kernel.push(0);
cpu_history.total.push(0);
}
chrome.system.cpu.getInfo(function(info){
for(var i=0; i<info.processors.length; i++){
cpu_history.last_total.push(info.processors[i].usage.total);
cpu_history.last_user.push(info.processors[i].usage.user);
cpu_history.last_kernel.push(info.processors[i].usage.kernel);
}
init_mem_history();
});
}

function init_mem_history(){
for(var i=0; i<ponits_num; i++){
mem_history.used.push(0);
}
updateData();
setInterval(updateData, 1000);
}

var cpu_history, mem_history, ponits_num=20;

init();
20 changes: 20 additions & 0 deletions performance monitor/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"app": {
"background": {
"scripts": ["background.js"]
}
},
"manifest_version": 2,
"name": "Performance Monitor",
"version": "1.0",
"description": "A performance monitor to show cpu and memory status.",
"icons": {
"16": "images/icon16.png",
"48": "images/icon48.png",
"128": "images/icon128.png"
},
"permissions": [
"system.cpu",
"system.memory"
]
}

0 comments on commit af8531d

Please sign in to comment.