-
Notifications
You must be signed in to change notification settings - Fork 2
/
usage_stats_model.php
87 lines (75 loc) · 2.82 KB
/
usage_stats_model.php
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php
use CFPropertyList\CFPropertyList;
class Usage_stats_model extends \Model {
function __construct($serial='')
{
parent::__construct('id', 'usage_stats'); // Primary key, tablename
$this->rs['id'] = '';
$this->rs['serial_number'] = $serial; $this->rt['serial_number'] = 'VARCHAR(255) UNIQUE';
$this->rs['timestamp'] = 0; $this->rt['timestamp'] = 'BIGINT';
$this->rs['thermal_pressure'] = '';
$this->rs['backlight_max'] = 0;
$this->rs['backlight_min'] = 0;
$this->rs['backlight'] = 0;
$this->rs['keyboard_backlight'] = 0;
$this->rs['ibyte_rate'] = 0.0;
$this->rs['ibytes'] = 0.0;
$this->rs['ipacket_rate'] = 0.0;
$this->rs['ipackets'] = 0.0;
$this->rs['obyte_rate'] = 0.0;
$this->rs['obytes'] = 0.0;
$this->rs['opacket_rate'] = 0.0;
$this->rs['opackets'] = 0.0;
$this->rs['rbytes_per_s'] = 0.0;
$this->rs['rops_per_s'] = 0.0;
$this->rs['wbytes_per_s'] = 0.0;
$this->rs['wops_per_s'] = 0.0;
$this->rs['rbytes_diff'] = 0.0;
$this->rs['rops_diff'] = 0.0;
$this->rs['wbytes_diff'] = 0.0;
$this->rs['wops_diff'] = 0.0;
$this->rs['package_watts'] = 0.0;
$this->rs['package_joules'] = 0.0;
$this->rs['freq_hz'] = 0.0; // CPU
$this->rs['freq_ratio'] = 0.0; // CPU
$this->rs['gpu_name'] = '';
$this->rs['gpu_freq_hz'] = 0.0;
$this->rs['gpu_freq_mhz'] = 0.0;
$this->rs['gpu_freq_ratio'] = 0.0;
$this->rs['gpu_busy'] = 0.0;
$this->rs['kern_bootargs'] = "";
if ($serial) {
$this->retrieve_record($serial);
}
$this->serial_number = $serial;
}
// ------------------------------------------------------------------------
/**
* Process data sent by postflight
*
* @param string data
* @author tuxudo
**/
function process($plist)
{
// Check if we have data
if ( ! $plist){
throw new Exception("Error Processing Request: No property list found", 1);
}
// Process incoming usage_stats.plist
$parser = new CFPropertyList();
$parser->parse($plist, CFPropertyList::FORMAT_XML);
$plist = $parser->toArray();
$fields = array('timestamp','thermal_pressure','backlight_max','backlight_min','backlight','keyboard_backlight','ibyte_rate','ibytes','ipacket_rate','ipackets','obyte_rate','obytes','opacket_rate','opackets','rbytes_per_s','rops_per_s','wbytes_per_s','wops_per_s','rbytes_diff','rops_diff','wbytes_diff','wops_diff','package_watts','package_joules','freq_hz','freq_ratio','gpu_name','gpu_freq_hz','gpu_freq_mhz','gpu_freq_ratio','gpu_busy','kern_bootargs');
foreach ($fields as $field) {
// If key does not exist in $plist, null it
if ( ! array_key_exists($field, $plist)) {
$this->$field = null;
} else {
$this->$field = $plist[$field];
}
}
// Save the data
$this->save();
}
}