-
Notifications
You must be signed in to change notification settings - Fork 691
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
process: fix fallback to V1 collector
Signed-off-by: Jan-Otto Kröpke <mail@jkroepke.de>
- Loading branch information
Showing
4 changed files
with
144 additions
and
118 deletions.
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
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
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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"syscall" | ||
"time" | ||
"unsafe" | ||
) | ||
|
||
var ( | ||
modkernel32 = syscall.NewLazyDLL("kernel32.dll") | ||
queryPerformanceFrequencyProc = modkernel32.NewProc("QueryPerformanceFrequency") | ||
queryPerformanceCounterProc = modkernel32.NewProc("QueryPerformanceCounter") | ||
|
||
qpcFrequency = queryPerformanceFrequency() | ||
qpcBase = queryPerformanceCounter() | ||
) | ||
|
||
func main() { | ||
fmt.Printf("qpcFrequency: %d, qpcBase: %d", qpcFrequency, qpcBase) | ||
fmt.Println() | ||
fmt.Println("Elapsed time: ", elapsed()) | ||
} | ||
|
||
func elapsed() time.Duration { | ||
elapsed := queryPerformanceCounter() - qpcBase | ||
return time.Duration(elapsed) * time.Second / (time.Duration(qpcFrequency) * time.Nanosecond) | ||
} | ||
|
||
func queryPerformanceCounter() int64 { | ||
var count int64 | ||
syscall.SyscallN(queryPerformanceCounterProc.Addr(), uintptr(unsafe.Pointer(&count))) | ||
return count | ||
} | ||
|
||
func queryPerformanceFrequency() int64 { | ||
var freq int64 | ||
syscall.SyscallN(queryPerformanceFrequencyProc.Addr(), uintptr(unsafe.Pointer(&freq))) | ||
return freq | ||
} |