-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Report Windows pagefile usage in bytes #1837
Merged
pjanotti
merged 1 commit into
open-telemetry:master
from
james-bebbington:pagefile-usage-in-bytes
Sep 25, 2020
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,14 +24,37 @@ import ( | |
) | ||
|
||
var ( | ||
modPsapi = windows.NewLazySystemDLL("psapi.dll") | ||
procEnumPageFilesW = modPsapi.NewProc("EnumPageFilesW") | ||
modKernel32 = windows.NewLazySystemDLL("kernel32.dll") | ||
modPsapi = windows.NewLazySystemDLL("psapi.dll") | ||
|
||
procGetNativeSystemInfo = modKernel32.NewProc("GetNativeSystemInfo") | ||
procEnumPageFilesW = modPsapi.NewProc("EnumPageFilesW") | ||
) | ||
|
||
type systemInfo struct { | ||
wProcessorArchitecture uint16 | ||
wReserved uint16 | ||
dwPageSize uint32 | ||
lpMinimumApplicationAddress uintptr | ||
lpMaximumApplicationAddress uintptr | ||
dwActiveProcessorMask uintptr | ||
dwNumberOfProcessors uint32 | ||
dwProcessorType uint32 | ||
dwAllocationGranularity uint32 | ||
wProcessorLevel uint16 | ||
wProcessorRevision uint16 | ||
} | ||
|
||
func getPageSize() uint64 { | ||
var sysInfo systemInfo | ||
procGetNativeSystemInfo.Call(uintptr(unsafe.Pointer(&sysInfo))) | ||
return uint64(sysInfo.dwPageSize) | ||
} | ||
|
||
type pageFileData struct { | ||
name string | ||
used uint64 | ||
total uint64 | ||
name string | ||
usedPages uint64 | ||
totalPages uint64 | ||
Comment on lines
+56
to
+57
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
} | ||
|
||
// system type as defined in https://docs.microsoft.com/en-us/windows/win32/api/psapi/ns-psapi-enum_page_file_information | ||
|
@@ -60,9 +83,9 @@ func pEnumPageFileCallbackW(pageFiles *[]*pageFileData, enumPageFileInfo *enumPa | |
pageFileName := syscall.UTF16ToString((*lpFilenamePtr)[:]) | ||
|
||
pfData := &pageFileData{ | ||
name: pageFileName, | ||
used: enumPageFileInfo.totalInUse, | ||
total: enumPageFileInfo.totalSize, | ||
name: pageFileName, | ||
usedPages: enumPageFileInfo.totalInUse, | ||
totalPages: enumPageFileInfo.totalSize, | ||
} | ||
|
||
*pageFiles = append(*pageFiles, pfData) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,7 +54,7 @@ var swapUsageDescriptor = func() pdata.Metric { | |
metric.InitEmpty() | ||
metric.SetName("system.swap.usage") | ||
metric.SetDescription("Swap (unix) or pagefile (windows) usage.") | ||
metric.SetUnit("pages") | ||
metric.SetUnit("bytes") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated as per open-telemetry/opentelemetry-specification#937 (comment) |
||
metric.SetDataType(pdata.MetricDataTypeIntSum) | ||
sum := metric.IntSum() | ||
sum.InitEmpty() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check returned error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GetNativeSystemInfo
doesn't return error or sets last error per https://docs.microsoft.com/en-us/windows/win32/api/sysinfoapi/nf-sysinfoapi-getnativesysteminfo