Skip to content

Commit 337e613

Browse files
committed
New specterum fingerprint generator.
1 parent 7d74a12 commit 337e613

File tree

5 files changed

+199
-34
lines changed

5 files changed

+199
-34
lines changed

_/css/style.css

+17
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,23 @@ mark {background-color: #fcd700; color: #000; font-style: italic; font-weight: b
149149
body {
150150
background-color: #FFEFA6;
151151
}
152+
153+
.wrapper {
154+
width: 1000px;
155+
padding:0;
156+
}
157+
158+
article {
159+
float: left;
160+
width: 700px;
161+
margin: 0;
162+
}
163+
164+
aside {
165+
width: 290px;
166+
float: left;
167+
margin: 0;
168+
}
152169
div.node {
153170
border: 1px solid black;
154171
float: left;

fingerprint.php

+85-15
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,41 @@
11
<?php
2+
error_reporting(E_ALL & ~E_NOTICE);
3+
require_once("./inc/utility.inc.php");
24
//Li9jYWNoZS8yY2IxYjQzLmNhY2hl
35
$cache = trim(stripslashes(base64_decode($_GET['cache'])));
46
$nodePixels = (int) $_GET['nodesize'];
57
if ($nodePixels <= 0) $nodePixels = 40;
68

9+
$type = trim($_GET['type']);
10+
11+
if (empty($type)) $type = "random";
12+
713
$text = @file_get_contents($cache);
814
if (empty($text)) die;
915

1016
$data = unserialize($text);
1117
$nodes = $data["nodes"];
1218
list($wp, $wd, $wc) = $data["cooff"];
1319

14-
15-
1620
$sum = $wp + $wd + $wc;
1721
$wp /= $sum;
1822
$wd /= $sum;
1923
$wc /= $sum;
2024

25+
2126
$numNodes = count($nodes);
2227
$coresPerNode = count($nodes[0]["cores"]);
2328
$numCores = $numNodes*$coresPerNode;
2429

30+
$min = -$wc * (($coresPerNode * ($coresPerNode - 1)) / 2);
31+
$max = ($wd * $coresPerNode) + ((1.0) * $coresPerNode * $wp);
32+
33+
$hue_min = 250;
34+
$hue_max = 10;
35+
$sat = 100;
36+
$ilu = 100;
37+
38+
2539
$break = floor(sqrt($numNodes));
2640

2741
$width = $break * $nodePixels;
@@ -52,9 +66,18 @@
5266
$bad += ($tmp);
5367
$nodes[$i]["vis"]["bad"] = $bad;
5468
$nodes[$i]["vis"]["good"] = $good;
69+
70+
$obj = ($wd * $d) - ($wc * $c) + ($wp * ($on));
71+
$hue = (($obj - $min) / ($max - $min)) * ($hue_max - $hue_min);
72+
$hue += $hue_min;
73+
74+
$nodes[$i]["vis"]["hue"] = $hue;
75+
//echo "$obj:$hue;";
5576
}
5677

5778
}
79+
//echo "\nmin: $min, max: $max";
80+
//die;
5881

5982
$img = imagecreatetruecolor($width, $height);
6083

@@ -73,27 +96,74 @@
7396
$bad = $nodes[$i]["vis"]["bad"];
7497

7598

99+
$count = 0;
100+
$turn = 0;
76101
for ($y = 0; $y < $nodePixels; $y++)
77102
{
78103
for ($x = 0; $x < $nodePixels; $x++)
79104
{
80-
if (($nodes[$i]["numOnCores"]) == 0)
105+
if ($type == "specterum")
81106
{
82-
$col = $colors["blank"];
83-
}
84-
else if ($good > 0)
85-
{
86-
$col = $colors["green"];
87-
$good--;
88-
}
89-
else if ($bad > 0)
90-
{
91-
$col = $colors["red"];
92-
$bad--;
107+
if (($nodes[$i]["numOnCores"]) == 0)
108+
{
109+
$col = $colors["blank"];
110+
}
111+
else
112+
{
113+
list($rr, $gg, $bb) = GetRGB($nodes[$i]["vis"]["hue"], $sat, $ilu);
114+
$col = imagecolorallocate($img, $rr, $gg, $bb);
115+
}
93116
}
94117
else
95118
{
96-
$col = $colors["blank"];
119+
if (($nodes[$i]["numOnCores"]) == 0)
120+
{
121+
$col = $colors["blank"];
122+
}
123+
else
124+
{
125+
if ($type == "order")
126+
{
127+
$turn = ($count++ % 3);
128+
}
129+
else if ($type == "random")
130+
{
131+
$turn = (rand(0, 2));
132+
}
133+
134+
if ($turn == 0)
135+
{
136+
if ($good > 0)
137+
{
138+
$col = $colors["green"];
139+
$good--;
140+
}
141+
else
142+
{
143+
$turn = 1;
144+
}
145+
}
146+
147+
148+
if ($turn == 1)
149+
{
150+
if ($bad > 0)
151+
{
152+
$col = $colors["red"];
153+
$bad--;
154+
}
155+
else
156+
{
157+
$turn = 2;
158+
}
159+
}
160+
161+
162+
if ($turn == 2)
163+
{
164+
$col = $colors["blank"];
165+
}
166+
}
97167
}
98168
imagesetpixel($img, round($x + $offsetX), round($y + $offsetY), $col);
99169
}

inc/utility.inc.php

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
/*
3+
** Converts HSV to RGB values
4+
** –––––––––––––––––––––––––––––––––––––––––––––––––––––
5+
** Reference: http://en.wikipedia.org/wiki/HSL_and_HSV
6+
** Purpose: Useful for generating colours with
7+
** same hue-value for web designs.
8+
** Input: Hue (H) Integer 0-360
9+
** Saturation (S) Integer 0-100
10+
** Lightness (V) Integer 0-100
11+
** Output: String "R,G,B"
12+
** Suitable for CSS function RGB().
13+
* From: https://gist.github.com/2323023
14+
*/
15+
16+
function GetRGB($iH, $iS, $iV) {
17+
18+
if($iH < 0) $iH = 0; // Hue:
19+
if($iH > 360) $iH = 360; // 0-360
20+
if($iS < 0) $iS = 0; // Saturation:
21+
if($iS > 100) $iS = 100; // 0-100
22+
if($iV < 0) $iV = 0; // Lightness:
23+
if($iV > 100) $iV = 100; // 0-100
24+
25+
$dS = $iS/100.0; // Saturation: 0.0-1.0
26+
$dV = $iV/100.0; // Lightness: 0.0-1.0
27+
$dC = $dV*$dS; // Chroma: 0.0-1.0
28+
$dH = $iH/60.0; // H-Prime: 0.0-6.0
29+
$dT = $dH; // Temp variable
30+
31+
while($dT >= 2.0) $dT -= 2.0; // php modulus does not work with float
32+
$dX = $dC*(1-abs($dT-1)); // as used in the Wikipedia link
33+
34+
switch($dH) {
35+
case($dH >= 0.0 && $dH < 1.0):
36+
$dR = $dC; $dG = $dX; $dB = 0.0; break;
37+
case($dH >= 1.0 && $dH < 2.0):
38+
$dR = $dX; $dG = $dC; $dB = 0.0; break;
39+
case($dH >= 2.0 && $dH < 3.0):
40+
$dR = 0.0; $dG = $dC; $dB = $dX; break;
41+
case($dH >= 3.0 && $dH < 4.0):
42+
$dR = 0.0; $dG = $dX; $dB = $dC; break;
43+
case($dH >= 4.0 && $dH < 5.0):
44+
$dR = $dX; $dG = 0.0; $dB = $dC; break;
45+
case($dH >= 5.0 && $dH < 6.0):
46+
$dR = $dC; $dG = 0.0; $dB = $dX; break;
47+
default:
48+
$dR = 0.0; $dG = 0.0; $dB = 0.0; break;
49+
}
50+
51+
$dM = $dV - $dC;
52+
$dR += $dM; $dG += $dM; $dB += $dM;
53+
$dR *= 255; $dG *= 255; $dB *= 255;
54+
55+
return array($dR, $dG, $dB);
56+
}
57+
58+
?>

inc/visualizer.inc.php

+17-4
Original file line numberDiff line numberDiff line change
@@ -149,13 +149,26 @@ private function saveDataToFile($filename)
149149
$this->cache = $filename;
150150
$data = array("cooff" => array($this->wp, $this->wd, $this->wc), "nodes" => $this->nodesData);
151151
file_put_contents($filename, serialize($data));
152-
echo "Printed Data to '$filename' base64:" . base64_encode($filename);
152+
//echo "Printed Data to '$filename' base64:" . base64_encode($filename);
153153
}
154154

155155
public function getCacheFilename()
156156
{
157157
return $this->cache;
158158
}
159+
160+
public function getStats()
161+
{
162+
return array(
163+
"numNodes" => $this->numNodes,
164+
"numCores" => $this->numCores,
165+
"numContendedNodes" => $this->numContendedNodes,
166+
"numPoweredOnNodes" => $this->numPoweredOnNodes,
167+
"numCoScheduledBuddies" => $this->numCoScheduledBuddies,
168+
"numFullUtilizedNodes" => $this->numFullUtilizedNodes
169+
);
170+
}
171+
159172
private function analyse()
160173
{
161174
$this->numContendedNodes = 0;
@@ -354,7 +367,7 @@ public function drawNode($ni, $id, $class = "", $text = "", $break = false)
354367

355368
$cclass = ($this->nodesData[$ni]["isCoscheduled"]) ? "green" : "";
356369
$pclass = ($this->nodesData[$ni]["isFullyUtilized"]) ? "green" : "";
357-
echo '<br clear="all" style="clear: all;" />';
370+
echo '<br clear="all" style="clear: both;" />';
358371
echo '<div class="shared-resource '.$dclass.'"></div>';
359372
echo '<div class="comm-buddies '.$cclass.'"></div>';
360373
echo '<div class="power-util '.$pclass.'"></div>';
@@ -372,8 +385,8 @@ public function visualize()
372385
$this->drawNode($i, "node-$i","", "", ($i > 0) && ($i % $break_size == 0));
373386
}
374387

375-
echo "<h2>Contented: $this->numContendedNodes, CoScheduled: $this->numCoScheduledBuddies, On: $this->numPoweredOnNodes, Fully Utilized: $this->numFullUtilizedNodes</h2>";
376-
print_r($this->getObjectiveFunctionValue());
388+
//echo "<h2>Contented: $this->numContendedNodes, CoScheduled: $this->numCoScheduledBuddies, On: $this->numPoweredOnNodes, Fully Utilized: $this->numFullUtilizedNodes</h2>";
389+
//print_r($this->getObjectiveFunctionValue());
377390
}
378391

379392
public function generateJSONForConnections($sym = true)

index.php

+22-15
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
</nav>
1515
-->
1616
</header>
17-
17+
<br clear="all" style="clear: both" />
1818
<article>
1919
<?php
2020
require_once("./inc/visualizer.inc.php");
@@ -29,6 +29,7 @@
2929
else
3030
{
3131
$viz->visualize();
32+
3233
//print_r($viz->generateJSFromCommunication());
3334
}
3435

@@ -38,17 +39,8 @@
3839
//$viz->drawNode($cores, "core-1");
3940
//$viz->drawNode($cores, "core-2");
4041
?>
41-
<br clear="all" style="clear: both" />
4242

43-
44-
<div id="control">
45-
<input id="togglec" type="button" value="Toggle Connections" />
46-
</div>
47-
<pre id="debug">
48-
<?php
49-
//echo nl2br($viz->generateJSFromCommunication());
50-
?>
51-
</pre>
43+
5244
<!--
5345
<div id="node0" style="position: absolute; block; width:100px; height:100px; border:1px solid red; left:10px; top:100px">Box 0</div>
5446
<div id="node1" style="position: absolute; width:100px; height:100px; border:1px solid red; left:300px; top:400px">Box 1</div>
@@ -57,14 +49,29 @@
5749

5850
<aside>
5951

60-
<h2>Sidebar comes here</h2>
61-
52+
<div id="control">
53+
<input id="togglec" type="button" value="Toggle Connections" />
54+
</div>
55+
56+
<?php
57+
print_r($viz->getStats());
58+
print_r($viz->getObjectiveFunctionValue());
59+
echo '<div id="fingerprint-wrapper">';
60+
echo '<img class="fingerprint" src="./fingerprint.php?nodesize=20&type=random&cache='.base64_encode($viz->getCacheFilename()).'" alt="" border="0" />';
61+
echo '<img class="fingerprint" src="./fingerprint.php?nodesize=20&type=order&cache='.base64_encode($viz->getCacheFilename()).'" alt="" border="0" />';
62+
echo '<img class="fingerprint" src="./fingerprint.php?nodesize=20&type=specterum&cache='.base64_encode($viz->getCacheFilename()).'" alt="" border="0" />';
63+
echo '</div>';
64+
?>
6265
</aside>
63-
66+
<br clear="all" style="clear: both" />
6467
<footer>
6568

6669
<p><small>Footer Comes Here</small></p>
67-
70+
<pre id="debug">
71+
<?php
72+
//echo nl2br($viz->generateJSFromCommunication());
73+
?>
74+
</pre>
6875
</footer>
6976

7077
</div>

0 commit comments

Comments
 (0)