-
Notifications
You must be signed in to change notification settings - Fork 8
/
faker.rb
executable file
·63 lines (51 loc) · 1.83 KB
/
faker.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/env ruby
# Generate fake JSON data to allow implementing client without access
# to CUDA devices
require 'sinatra'
require 'json'
$devices = [
{ :name => "Device1", :index => 0, :serial => "abcd1",
:features => ["temperature", "compute", "utilization",
"power", "memory", "clock", "name", "fan"]},
{ :name => "Device2", :index => 1, :serial => "abcd2",
:features => ["temperature", "compute", "utilization",
"power", "memory", "clock", "name", "fan"]},
{ :name => "Device3", :index => 2, :serial => "abcd3",
:features => ["temperature", "compute", "utilization",
"power", "memory", "clock", "name", "fan"]},
{ :name => "Device4", :index => 3, :serial => "abcd4",
:features => ["temperature", "compute", "utilization",
"power", "memory", "clock", "name", "fan"]}
]
set :public_folder, 'www/'
get '/' do
send_file File.join(settings.public_folder, 'index.html')
end
get '/ajax/init' do
JSON.generate({ :devices => $devices,
:driver_version => "1234.5",
:nvml_version => "5432.1",
:host => "foobarbaz"})
end
get '/ajax/update' do
$devices.each {|dev|
dev['memory'] = { :free => rand(200),
:used => rand(1000),
:total => 4096
}
dev['clock'] = {
:graphics => 500 + rand(100),
:sm => 500 + rand(100),
:mem => 500 + rand(100)
}
dev['fan'] = 50+rand(10)
dev['temperature'] = 50 + (rand(20) - 10)
dev['power'] = 50 + (rand(20) - 10)
dev['utilization'] = {
:memory => 50 + rand(50),
:gpu => 50 + rand(50)
}
}
JSON.generate({ :devices => $devices,
:time => Time.now.to_i})
end