aboutsummaryrefslogtreecommitdiff
path: root/test/usage_windows.go
blob: 883473960708d238631131291a516b8892b04177 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// Copyright (C) 2014 The Syncthing Authors.
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
// You can obtain one at http://mozilla.org/MPL/2.0/.

//go:build integration && benchmark && windows
// +build integration,benchmark,windows

package integration

import (
	"log"
	"os"
	"syscall"
	"time"
)

func ftToDuration(ft *syscall.Filetime) time.Duration {
	n := int64(ft.HighDateTime)<<32 + int64(ft.LowDateTime) // in 100-nanosecond intervals
	return time.Duration(n*100) * time.Nanosecond
}

func printUsage(name string, proc *os.ProcessState, total int64) {
	if rusage, ok := proc.SysUsage().(*syscall.Rusage); ok {
		mib := total / 1024 / 1024
		log.Printf("%s: Utime: %s / MiB", name, time.Duration(rusage.UserTime.Nanoseconds()/mib))
		log.Printf("%s: Stime: %s / MiB", name, time.Duration(rusage.KernelTime.Nanoseconds()/mib))
	}
}