Skip to content

Commit

Permalink
address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
jaypipes committed Mar 16, 2020
1 parent 0e96671 commit f90bcd9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
11 changes: 5 additions & 6 deletions memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ import (
"math"
)

type MemoryBank struct {
Name string `json:"name"`
type MemoryModule struct {
Label string `json:"label"`
Location string `json:"location"`
SerialNumber string `json:"serial_number"`
Expand All @@ -21,11 +20,11 @@ type MemoryBank struct {
}

type MemoryInfo struct {
Banks []*MemoryBank `json:"banks"`
TotalPhysicalBytes int64 `json:"total_physical_bytes"`
TotalUsableBytes int64 `json:"total_usable_bytes"`
TotalPhysicalBytes int64 `json:"total_physical_bytes"`
TotalUsableBytes int64 `json:"total_usable_bytes"`
// An array of sizes, in bytes, of memory pages supported by the host
SupportedPageSizes []uint64 `json:"supported_page_sizes"`
SupportedPageSizes []uint64 `json:"supported_page_sizes"`
Modules []*MemoryModule `json:"modules"`
}

func Memory(opts ...*WithOption) (*MemoryInfo, error) {
Expand Down
12 changes: 5 additions & 7 deletions memory_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type win32OperatingSystem struct {
TotalVisibleMemorySize uint64
}

const wmqlPhysicalMemor = "SELECT BankLabel, Capacity, DataWidth, Description, DeviceLocator, Manufacturer, Model, Name, PartNumber, PositionInRow, SerialNumber, Speed, Tag, TotalWidth FROM Win32_PhysicalMemory"
const wmqlPhysicalMemory = "SELECT BankLabel, Capacity, DataWidth, Description, DeviceLocator, Manufacturer, Model, Name, PartNumber, PositionInRow, SerialNumber, Speed, Tag, TotalWidth FROM Win32_PhysicalMemory"

type win32PhysicalMemory struct {
BankLabel string
Expand All @@ -47,22 +47,20 @@ func (ctx *context) memFillInfo(info *MemoryInfo) error {
return err
}
var win32MemDescriptions []win32PhysicalMemory
if err := wmi.Query(wmqlPhysicalMemor, &win32MemDescriptions); err != nil {
if err := wmi.Query(wmqlPhysicalMemory, &win32MemDescriptions); err != nil {
return err
}
// Converting into standard structures
// Handling physical memory banks
info.Banks = make([]*MemoryBank, 0, len(win32MemDescriptions))
// Handling physical memory modules
info.Modules = make([]*MemoryModule, 0, len(win32MemDescriptions))
for _, description := range win32MemDescriptions {
info.Banks = append(info.Banks, &MemoryBank{
Name: description.Description,
info.Modules = append(info.Modules, &MemoryModule{
Label: description.BankLabel,
Location: description.DeviceLocator,
SerialNumber: description.SerialNumber,
SizeBytes: int64(description.Capacity),
Vendor: description.Manufacturer,
})
//totalPhysicalBytes += description.Capacity
}
// Handling physical memory total/free size (as seen by OS)
var totalUsableBytes uint64
Expand Down

0 comments on commit f90bcd9

Please sign in to comment.