Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
kuebk committed Sep 7, 2011
0 parents commit df98b16
Show file tree
Hide file tree
Showing 18 changed files with 4,435 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
@@ -0,0 +1,3 @@
[submodule "browser/flot"]
path = browser/flot
url = git://github.com/flot/flot.git
20 changes: 20 additions & 0 deletions LICENSE
@@ -0,0 +1,20 @@
Copyright (C) 2011 by Jakub Lekstan <kuebzky@gmail.com>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

2 changes: 2 additions & 0 deletions README.md
@@ -0,0 +1,2 @@
##Build:
node-waf configure build
1 change: 1 addition & 0 deletions browser/flot
Submodule flot added at 93c7c9
123 changes: 123 additions & 0 deletions browser/index.html
@@ -0,0 +1,123 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>node-gpu charts</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.6.2.js"></script>
<script type="text/javascript" src="flot/jquery.flot.js"></script>
<style type="text/css">
.chartContainer {
overflow: hidden;
}
.chartContainer > div {
float: left;
}
</style>
</head>
<body>
<div id="charts"></div>
<script>
var createGraph = function(canvasName, chartData, targetElement){
var canvas = document.createElement('div');
canvas.id = canvasName;
canvas.style.width = 400;
canvas.style.height = 200;

var title = document.createElement('h2');
title.appendChild(document.createTextNode(canvasName));

canvas.appendChild(title);

targetElement.appendChild(canvas);

var tmp = chartData.slice(0);
var chart = $.plot(canvas, tmp, {
series: {
shadowSize: 0,
lines: { show: true },
points: { show: true }
},
yaxis: {
ticks: 10,
tickDecimals: 0
},
xaxis: {
show: false
},
legend: {
backgroundOpacity: 0.1,
backgroundColor: "#000000"
}
});
return chart;
}

var interval;
var stop = function(){window.clearInterval(interval)};

$.getJSON(location.protocol + '//' + location.hostname + ':8080/?getInfo', function(data){

var chartName, chartKeys, chartData = {}, charts = {}, items = ['temperature', 'fanspeed', 'activity', 'core', 'memory'];
var items = ['temperature', 'fanspeed', 'activity'];
var chartsContainer = document.getElementById('charts'), container;

for(var i = 0, l = data.length; i < l; i++){
chartName = data[i].name;
chartKeys = data[i].data;
chartData[data[i].name] = {};
charts[data[i].name] = {}

container = document.createElement('div');
container.id = chartName;
container.className = 'chartContainer';
chartsContainer.appendChild(container);

for(var j = 0, q = items.length; j < q; j++){
chartData[data[i].name][items[j]] = [];

for(var k = 0, w = chartKeys.length; k < w; k++){
chartData[data[i].name][items[j]][k] = {label: chartKeys[k], data: []};
}

charts[data[i].name][items[j]] = createGraph(chartName + '-' + items[j], chartData[data[i].name][items[j]], container);
}
}
interval = window.setInterval(function(){
$.getJSON(location.protocol + '//' + location.hostname + ':8080/', function(data){
var tmp
for(var i = 0, l = data.length; i < l; i++){

for(var j = 0, q = items.length; j < q; j++){
for(var k = 0, w = data[i].data.length; k < w; k++){
chartData[data[i].name][items[j]][k].data.push(data[i].data[k][items[j]]);

if(chartData[data[i].name][items[j]][k].data.length > 50){
chartData[data[i].name][items[j]][k].data.shift();
}
}

charts[data[i].name][items[j]].setData(prepareArray(chartData[data[i].name][items[j]]));
charts[data[i].name][items[j]].setupGrid();
charts[data[i].name][items[j]].draw();
}
}
});
}, 500);
});

var prepareArray = function(data){
var tmp = $.extend(true, [], data);

for(var i = 0, l = tmp.length; i < l; i++){
//tmp.data[i] = [i, tmp.data[i]];
for(var j = 0, k = tmp[i].data.length; j < k; j++){
tmp[i].data[j] = [j, tmp[i].data[j]];
}
}

return tmp;
};
</script>
</body>
</html>

96 changes: 96 additions & 0 deletions master/index.js
@@ -0,0 +1,96 @@
/*
* Copyright (C) 2011 by Jakub Lekstan <kuebzky@gmail.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

var net = require('net'), http = require('http');
var hosts = ['czupakabra', 'bitcoin-1', 'bitcoin-2', 'bitcoin-3', 'bitcoin-4'], port = 8888, sockets = [], counter = 0, socket;

var sckCallback = function(){};

for(var i = 0, l = hosts.length; i < l; i++){
socket = new net.createConnection(port, hosts[i]);
socket.num = i;
socket.on('connect', function(){
sockets[this.num] = this;
createHttpServer();
});
socket.on('data', function(d){
sckCallback(d, this.num);
});
socket.setKeepAlive(true);
socket.setNoDelay(true);
}

var createHttpServer = function(){
if(hosts.length != ++counter) return;

var server = http.createServer(function(request, response){
console.log('request received' + (new Date()));
var data = [], c = 0, tmp = [];

var fnc = function(){
console.log('can we continue with processing request?');
if(sockets.length != ++c) return;
console.log("yes, we can\n\n\n");

var body = JSON.stringify(data);

response.setHeader("Content-length", body.length);
response.setHeader("Access-Control-Allow-Origin", "*");
response.writeHead(200, {"Content-type": "application/json"});
response.end(body);
}

sckCallback = function(d, i){
console.log('received data from socket', i, d.toString());
try{
if(tmp[i] != ''){
console.log('RECEIVED DATA FOR INCOMPLETE RESPONSE', d.toString(), tmp[i]);
}
data[i] = {
name: hosts[i],
data: JSON.parse(tmp[i] + d)
};
fnc();
}catch(e){
tmp[i] = tmp[i] + d.toString();
console.log('INCOMPLETE DATA FROM SOCKET', e.message, d.toString(), tmp[i], "\n\n");
}
};
for(var i = 0, l = sockets.length; i < l; i++){
tmp[i] = '';
console.log('sending data to socket', i);
if(request.url.indexOf('getInfo') !== -1){
sockets[i].write('getInfo');
}else{
sockets[i].write('getData');
}
console.log('sent');
}


});
server.useChunkedEncodingByDefault = false;
server.listen(8080);
};

var receiveData = function(i, data){
};
108 changes: 108 additions & 0 deletions slave/index.js
@@ -0,0 +1,108 @@
/*
* Copyright (C) 2011 by Jakub Lekstan <kuebzky@gmail.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

var net = require('net');
var gpu = require('../bin/gpu.node');

//initializing adl3
try{
var create = gpu.amd.ADL_Main_Control_Create(1);
if(create.status != gpu.amd.ADL_OK) throw -1;

var numberOfAdapters = gpu.amd.ADL_Adapter_NumberOfAdapters_Get();
if(numberOfAdapters.status != gpu.amd.ADL_OK) throw -2;

var allAdaptersData = gpu.amd.ADL_Adapter_AdapterInfo_Get(numberOfAdapters.data), activeAdaptersData = [], tmp;
if(allAdaptersData.status != gpu.amd.ADL_OK) throw -3;

for(var i = 0, l = allAdaptersData.data.length; i < l; i++){
tmp = gpu.amd.ADL_Adapter_Active_Get(i);

if(tmp.status == gpu.amd.ADL_OK && tmp.data == gpu.amd.ADL_TRUE){
activeAdaptersData.push(allAdaptersData.data[i]);
}
}
}catch(e){
console.log('Failed to init ADL:', e.message);
gpu.amd.ADL_Main_Control_Destroy();
process.exit(1);
}

process.on('exit', function(){
gpu.amd.ADL_Main_Control_Destroy();
}).on('uncaughtException', function(e){
console.log('Uncaught exception:', e.message);
gpu.amd.ADL_Main_Control_Destroy();
process.exit(1);
});

var server = net.createServer({
allowHalfOpen: true
},function(socket){
socket.setNoDelay(true);
socket.on('data', function(buffer){
console.log('data received');

var data = [];

if(buffer.toString() == 'getInfo'){
for(var i = 0, l = activeAdaptersData.length; i < l; i++){
data.push(activeAdaptersData[i].strAdapterName);
}
}else{
var tmp, temperature, fan, activity;

for(var i = 0, l = activeAdaptersData.length; i < l; i++){
tmp = {
temperature: 0,
fanspeed: 0,
activity: 0,
core: 0,
memory: 0
};

temperature = gpu.amd.ADL_Overdrive5_Temperature_Get(activeAdaptersData[i].iAdapterIndex, 0);
if(temperature.status == gpu.amd.ADL_OK){
tmp.temperature = temperature.data.iTemperature/1000;
}

fan = gpu.amd.ADL_Overdrive5_FanSpeed_Get(activeAdaptersData[i].iAdapterIndex, 0);
if(fan.status == gpu.amd.ADL_OK){
tmp.fanspeed = fan.data.iFanSpeed;
}

activity = gpu.amd.ADL_Overdrive5_CurrentActivity_Get(activeAdaptersData[i].iAdapterIndex);
if(activity.status == gpu.amd.ADL_OK){
tmp.activity = activity.data.iActivityPercent;
tmp.core = activity.data.iEngineClock/100;
tmp.memory = activity.data.iMemoryClock/100;
}

data.push(tmp);
}
}

console.log('sending data');
socket.write(JSON.stringify(data));
console.log('sent');
});
}).listen(8888);

0 comments on commit df98b16

Please sign in to comment.