当前位置: 首页>>代码示例>>Golang>>正文


Golang Filetime.Nanoseconds方法代码示例

本文整理汇总了Golang中syscall.Filetime.Nanoseconds方法的典型用法代码示例。如果您正苦于以下问题:Golang Filetime.Nanoseconds方法的具体用法?Golang Filetime.Nanoseconds怎么用?Golang Filetime.Nanoseconds使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在syscall.Filetime的用法示例。


在下文中一共展示了Filetime.Nanoseconds方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: 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
		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
	}
}
开发者ID:ericcapricorn,项目名称:syncthing,代码行数:35,代码来源:gui_windows.go

示例2: 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
}
开发者ID:MingchunZhao,项目名称:beats,代码行数:15,代码来源:wineventlog_windows.go

示例3: 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
}
开发者ID:krasin,项目名称:go-deflate,代码行数:17,代码来源:stat_windows.go

示例4: 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
}
开发者ID:entuerto,项目名称:sysmon,代码行数:23,代码来源:pdh_windows.go

示例5: 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
}
开发者ID:hyperhq,项目名称:runv,代码行数:20,代码来源:sigar_windows.go

示例6: 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
}
开发者ID:go-nosql,项目名称:golang,代码行数:20,代码来源:stat_windows.go

示例7: mkModTime

func mkModTime(mtime syscall.Filetime) time.Time {
	return time.Unix(0, mtime.Nanoseconds())
}
开发者ID:funkygao,项目名称:govtil,代码行数:3,代码来源:stat_windows.go

示例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())
}
开发者ID:Clarifai,项目名称:kubernetes,代码行数:3,代码来源:tar.go

示例9: filetimeToDuration

func filetimeToDuration(ft *syscall.Filetime) time.Duration {
	ns := ft.Nanoseconds()
	return time.Duration(ns)
}
开发者ID:hooklift,项目名称:terraform,代码行数:4,代码来源:usage_windows.go


注:本文中的syscall.Filetime.Nanoseconds方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。