From 2cc6983a2103d64cd33a0fb67dc7ea2adcac3ba8 Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Thu, 18 Aug 2022 19:15:20 +0200 Subject: [PATCH] runtime/pprof: report MaxRSS on windows Use GetProcessMemoryInfo to report MaxRSS in memory profiles on windows. Change-Id: I4ac5fe58961b1d5da8a5c1caa8a6e3d0a3281837 Reviewed-on: https://go-review.googlesource.com/c/go/+/424414 Reviewed-by: Cherry Mui Reviewed-by: Joedian Reid Run-TryBot: Tobias Klauser Auto-Submit: Tobias Klauser TryBot-Result: Gopher Robot --- src/runtime/pprof/pprof_norusage.go | 2 +- src/runtime/pprof/pprof_windows.go | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 src/runtime/pprof/pprof_windows.go diff --git a/src/runtime/pprof/pprof_norusage.go b/src/runtime/pprof/pprof_norusage.go index 3d6052519c..8de38086c7 100644 --- a/src/runtime/pprof/pprof_norusage.go +++ b/src/runtime/pprof/pprof_norusage.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -//go:build !aix && !darwin && !dragonfly && !freebsd && !linux && !netbsd && !openbsd && !solaris +//go:build !aix && !darwin && !dragonfly && !freebsd && !linux && !netbsd && !openbsd && !solaris && !windows package pprof diff --git a/src/runtime/pprof/pprof_windows.go b/src/runtime/pprof/pprof_windows.go new file mode 100644 index 0000000000..23ef2f80fe --- /dev/null +++ b/src/runtime/pprof/pprof_windows.go @@ -0,0 +1,22 @@ +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package pprof + +import ( + "fmt" + "internal/syscall/windows" + "io" + "syscall" + "unsafe" +) + +func addMaxRSS(w io.Writer) { + var m windows.PROCESS_MEMORY_COUNTERS + p, _ := syscall.GetCurrentProcess() + err := windows.GetProcessMemoryInfo(p, &m, uint32(unsafe.Sizeof(m))) + if err == nil { + fmt.Fprintf(w, "# MaxRSS = %d\n", m.PeakWorkingSetSize) + } +} -- 2.50.0