當前位置: 首頁>>代碼示例>>Golang>>正文


Golang syscall.Filetime類代碼示例

本文整理匯總了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
}
開發者ID:MingchunZhao,項目名稱:beats,代碼行數:15,代碼來源:wineventlog_windows.go

示例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
}
開發者ID:krasin,項目名稱:go-deflate,代碼行數:17,代碼來源:stat_windows.go

示例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
}
開發者ID:entuerto,項目名稱:sysmon,代碼行數:23,代碼來源:pdh_windows.go

示例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
}
開發者ID:hyperhq,項目名稱:runv,代碼行數:20,代碼來源:sigar_windows.go

示例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
}
開發者ID:go-nosql,項目名稱:golang,代碼行數:20,代碼來源:stat_windows.go

示例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
	}
}
開發者ID:letiemble,項目名稱:syncthing,代碼行數:39,代碼來源:gui_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類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。