-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmemory_model.php
142 lines (122 loc) · 5.74 KB
/
memory_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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
<?php
use CFPropertyList\CFPropertyList;
class Memory_model extends \Model {
function __construct($serial='')
{
parent::__construct('id', 'memory'); //primary key, tablename
$this->rs['id'] = '';
$this->rs['serial_number'] = $serial;
$this->rs['name'] = '';
$this->rs['dimm_size'] = '';
$this->rs['dimm_speed'] = '';
$this->rs['dimm_type'] = '';
$this->rs['dimm_status'] = '';
$this->rs['dimm_manufacturer'] = '';
$this->rs['dimm_part_number'] = '';
$this->rs['dimm_serial_number'] = '';
$this->rs['dimm_ecc_errors'] = '';
$this->rs['global_ecc_state'] = 0; // can be 0, 1, or 2
$this->rs['is_memory_upgradeable'] = 0; // true/false
$this->rs['free'] = 0;
$this->rs['active'] = 0;
$this->rs['inactive'] = 0;
$this->rs['speculative'] = 0;
$this->rs['throttled'] = 0;
$this->rs['wireddown'] = 0;
$this->rs['purgeable'] = 0;
$this->rs['translationfaults'] = 0;
$this->rs['copyonwrite'] = 0;
$this->rs['zerofilled'] = 0;
$this->rs['reactivated'] = 0;
$this->rs['purged'] = 0;
$this->rs['filebacked'] = 0;
$this->rs['anonymous'] = 0;
$this->rs['storedincompressor'] = 0;
$this->rs['occupiedbycompressor'] = 0;
$this->rs['decompressions'] = 0;
$this->rs['compressions'] = 0;
$this->rs['pageins'] = 0;
$this->rs['pageouts'] = 0;
$this->rs['swapins'] = 0;
$this->rs['swapouts'] = 0;
$this->rs['memorypressure'] = 0;
$this->rs['swaptotal'] = 0;
$this->rs['swapused'] = 0;
$this->rs['swapfree'] = 0;
$this->rs['swapencrypted'] = 0; // true/false
$this->serial_number = $serial;
}
// ------------------------------------------------------------------------
/**
* Process data sent by postflight
*
* @param string data
* @author tuxudo
**/
function process($plist)
{
if ( ! $plist){
throw new Exception("Error Processing Request: No property list found", 1);
}
// Delete previous set
$this->deleteWhere('serial_number=?', $this->serial_number);
$parser = new CFPropertyList();
$parser->parse($plist, CFPropertyList::FORMAT_XML);
$myList = $parser->toArray();
// Process each entry
foreach ($myList as $memstick) {
// Check if we have a name
if( ! array_key_exists("name", $memstick)){
continue;
}
// Don't process empty VMware memory
if( array_key_exists("name", $memstick) && substr($memstick['name'], 0, 10) === "RAM slot #" && array_key_exists("dimm_size", $memstick) && $memstick['dimm_size'] == "empty"){
continue;
}
// Don't process empty VMware memory
if( array_key_exists("name", $memstick) && substr($memstick['name'], 0, 10) === "NVD slot #" && array_key_exists("dimm_size", $memstick) && $memstick['dimm_size'] == "empty"){
continue;
}
// Process singular memory data
$singularitems = array ('global_ecc_state','is_memory_upgradeable','free','active','inactive','speculative','throttled','wireddown','purgeable','translationfaults','copyonwrite','zerofilled','reactivated','purged','filebacked','anonymous','storedincompressor','occupiedbycompressor','decompressions','compressions','pageins','pageouts','swapins','swapouts','memorypressure','swaptotal','swapused','swapfree','swapencrypted');
foreach ($singularitems as $singlekey) {
if( array_key_exists($singlekey, $memstick)){
$this->rs[$singlekey] = $memstick[$singlekey];
} else {
$this->rs[$singlekey] = null;
}
}
// Add manufacturer name and cleanup
if (array_key_exists("dimm_manufacturer",$memstick)) {
$memstick['dimm_manufacturer'] = str_replace(array('0x029E','0x014F','0x802C','0x830B','0x80AD','0x02FE','0x0000','0x8394','0x0D9B','0x2C00','0x80CE','0xAD00','0xCE00','0x5105','0x8551','0x0198','0x859b','0x859B','0x7F7F7F7F7F9BFFFF'), array('Corsair (0x029E)','Transcend Information (0x014F)','Micron Technology (0x802C)','Nanya (0x830B)','Hynix Semiconductor (0x80AD)','Elpida Memory (0x02FE)','TransIntl (0x0000)','Mushkin (0x8394)','Crucial (0x0D9B)','Micron Technology (0x2C00)','Samsung Electronics (0x80CE)','Hynix Semiconductor (0xAD00)','Samsung Electronics (0xCE00)','Qimonda AG (0x5105)','Qimonda AG (0x8551)','Kingston (0x0198)',' Crucial (0x859b)',' Crucial (0x859B)',' Crucial (0x7F7F7F7F7F9BFFFF)'),$memstick['dimm_manufacturer']);
$memstick['dimm_manufacturer'] = str_replace(array("000000000000","FE0000000000"),array("",""),$memstick['dimm_manufacturer']);
}
// Process each key
foreach ($this->rs as $key => $value) {
$this->rs[$key] = $value;
if(array_key_exists($key, $memstick))
{
$this->rs[$key] = $memstick[$key];
}
}
// Remove space after DIMM
$this->rs['name'] = str_replace("DIMM ","DIMM",$this->rs['name']);
// The improve readability of bank name
$this->rs['name'] = str_replace(array("BANK","/","DIMM"," slot #"),array("Bank"," - ","DIMM ",""),$this->rs['name']);
// If empty, null the values
if(array_key_exists("dimm_size", $memstick) && $memstick['dimm_size'] == "empty"){
$this->rs['dimm_status'] = "empty";
$this->rs['dimm_size'] = '';
$this->rs['dimm_speed'] = '';
$this->rs['dimm_manufacturer'] = '';
$this->rs['dimm_type'] = '';
$this->rs['dimm_part_number'] = '';
$this->rs['dimm_serial_number'] = '';
$this->rs['dimm_ecc_errors'] = '';
}
// Save memory stick data
$this->id = '';
$this->save();
}
}
}