本文整理汇总了Golang中syscall.Filetime类的典型用法代码示例。如果您正苦于以下问题:Golang Filetime类的具体用法?Golang Filetime怎么用?Golang Filetime使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Filetime类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: readFiletime
// readFiletime reads a Windows Filetime struct and converts it to a
// time.Time value with a UTC timezone.
func readFiletime(reader io.Reader) (*time.Time, error) {
var filetime syscall.Filetime
err := binary.Read(reader, binary.LittleEndian, &filetime.LowDateTime)
if err != nil {
return nil, err
}
err = binary.Read(reader, binary.LittleEndian, &filetime.HighDateTime)
if err != nil {
return nil, err
}
t := time.Unix(0, filetime.Nanoseconds()).UTC()
return &t, nil
}
示例2: toFileInfo
func toFileInfo(name string, fa, sizehi, sizelo uint32, ctime, atime, mtime syscall.Filetime) FileInfo {
fs := new(FileStat)
fs.mode = 0
if fa&syscall.FILE_ATTRIBUTE_DIRECTORY != 0 {
fs.mode |= ModeDir
}
if fa&syscall.FILE_ATTRIBUTE_READONLY != 0 {
fs.mode |= 0444
} else {
fs.mode |= 0666
}
fs.size = int64(sizehi)<<32 + int64(sizelo)
fs.name = name
fs.modTime = time.Unix(0, mtime.Nanoseconds())
fs.Sys = &winTimes{atime, ctime}
return fs
}
示例3: PdhCollectQueryDataWithTime
// Collects the current raw data value for all counters in the specified query and
// updates the status code of each counter.
//
// Time stamp when the first counter value in the query was retrieved. The time is specified as FILETIME.
func PdhCollectQueryDataWithTime(queryHdl syscall.Handle) (*time.Time, error) {
var TimeStamp syscall.Filetime
r, _, err := procPdhCollectQueryDataWithTime.Call(
uintptr(queryHdl),
uintptr(unsafe.Pointer(&TimeStamp)))
if r != 0 && err != nil {
if r == uintptr(PDH_NO_DATA) {
// Has not values
return nil, errors.New(codeText[PDH_NO_DATA])
}
return nil, err
}
ts := time.Unix(0, TimeStamp.Nanoseconds())
return &ts, nil
}
示例4: Get
func (c *Cpu) Get() error {
var (
idleTime syscall.Filetime
kernelTime syscall.Filetime // Includes kernel and idle time.
userTime syscall.Filetime
)
r1, _, e1 := syscall.Syscall(procGetSystemTimes.Addr(), 3,
uintptr(unsafe.Pointer(&idleTime)),
uintptr(unsafe.Pointer(&kernelTime)),
uintptr(unsafe.Pointer(&userTime)),
)
if err := checkErrno(r1, e1); err != nil {
return fmt.Errorf("GetSystemTimes: %s", err)
}
c.Idle = uint64(idleTime.Nanoseconds())
c.Sys = uint64(kernelTime.Nanoseconds()) - c.Idle
c.User = uint64(userTime.Nanoseconds())
return nil
}
示例5: setFileInfo
func setFileInfo(fi *FileInfo, name string, fa, sizehi, sizelo uint32, ctime, atime, wtime syscall.Filetime) *FileInfo {
fi.Mode = 0
if fa&syscall.FILE_ATTRIBUTE_DIRECTORY != 0 {
fi.Mode = fi.Mode | syscall.S_IFDIR
} else {
fi.Mode = fi.Mode | syscall.S_IFREG
}
if fa&syscall.FILE_ATTRIBUTE_READONLY != 0 {
fi.Mode = fi.Mode | 0444
} else {
fi.Mode = fi.Mode | 0666
}
fi.Size = int64(sizehi)<<32 + int64(sizelo)
fi.Name = name
fi.FollowedSymlink = false
fi.Atime_ns = atime.Nanoseconds()
fi.Mtime_ns = wtime.Nanoseconds()
fi.Ctime_ns = ctime.Nanoseconds()
return fi
}
示例6: trackCPUUsage
func trackCPUUsage() {
handle, err := syscall.GetCurrentProcess()
if err != nil {
l.Warnln("Cannot track CPU usage:", err)
return
}
var ctime, etime, ktime, utime syscall.Filetime
err = syscall.GetProcessTimes(handle, &ctime, &etime, &ktime, &utime)
if err != nil {
l.Warnln("Cannot track CPU usage:", err)
return
}
prevTime := ctime.Nanoseconds()
prevUsage := ktime.Nanoseconds() + utime.Nanoseconds() // Always overflows
for range time.NewTicker(time.Second).C {
err := syscall.GetProcessTimes(handle, &ctime, &etime, &ktime, &utime)
if err != nil {
continue
}
curTime := time.Now().UnixNano()
timeDiff := curTime - prevTime
// This is sometimes 0, no clue why.
if timeDiff == 0 {
continue
}
curUsage := ktime.Nanoseconds() + utime.Nanoseconds()
usageDiff := curUsage - prevUsage
cpuUsageLock.Lock()
copy(cpuUsagePercent[1:], cpuUsagePercent[0:])
cpuUsagePercent[0] = 100 * float64(usageDiff) / float64(timeDiff)
cpuUsageLock.Unlock()
prevTime = curTime
prevUsage = curUsage
}
}
示例7: mkModTime
func mkModTime(mtime syscall.Filetime) time.Time {
return time.Unix(0, mtime.Nanoseconds())
}
示例8: win32TimeToTar
func win32TimeToTar(ft syscall.Filetime) (string, time.Time) {
return fmt.Sprintf("%d", uint64(ft.LowDateTime)+(uint64(ft.HighDateTime)<<32)), time.Unix(0, ft.Nanoseconds())
}
示例9: filetimeToDuration
func filetimeToDuration(ft *syscall.Filetime) time.Duration {
ns := ft.Nanoseconds()
return time.Duration(ns)
}