Copyright 2018 The Prometheus Authors Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

package procfs

import (
	
	
	

	
)
ProcStatus provides status information about the process, read from /proc/[pid]/stat.
The process ID.
The process name.
Thread group ID.
Peak virtual memory size.
Virtual memory size.
Locked memory size.
Pinned memory size.
Peak resident set size.
Resident set size (sum of RssAnnon RssFile and RssShmem).
Size of resident anonymous memory.
Size of resident file mappings.
Size of resident shared memory.
Size of data segments.
Size of stack segments.
Size of text segments.
Shared library code size.
Page table entries size.
Size of second-level page tables.
Swapped-out virtual memory size by anonymous private.
Size of hugetlb memory portions
Number of voluntary context switches.
Number of involuntary context switches.
NewStatus returns the current status information of the process.
func ( Proc) () (ProcStatus, error) {
	,  := util.ReadFileNoStat(.path("status"))
	if  != nil {
		return ProcStatus{}, 
	}

	 := ProcStatus{PID: .PID}

	 := strings.Split(string(), "\n")
	for ,  := range  {
		if !bytes.Contains([]byte(), []byte(":")) {
			continue
		}

		 := strings.SplitN(, ":", 2)
removes spaces
		 := string(strings.TrimSpace([0]))
removes "kB"
		 = string(bytes.Trim([]byte(), " kB"))
value to int when possible we can skip error check here, 'cause vKBytes is not used when value is a string
convert kB to B
		 :=  * 1024

		.fillStatus(, , , )
	}

	return , nil
}

func ( *ProcStatus) ( string,  string,  uint64,  uint64) {
	switch  {
	case "Tgid":
		.TGID = int()
	case "Name":
		.Name = 
	case "VmPeak":
		.VmPeak = 
	case "VmSize":
		.VmSize = 
	case "VmLck":
		.VmLck = 
	case "VmPin":
		.VmPin = 
	case "VmHWM":
		.VmHWM = 
	case "VmRSS":
		.VmRSS = 
	case "RssAnon":
		.RssAnon = 
	case "RssFile":
		.RssFile = 
	case "RssShmem":
		.RssShmem = 
	case "VmData":
		.VmData = 
	case "VmStk":
		.VmStk = 
	case "VmExe":
		.VmExe = 
	case "VmLib":
		.VmLib = 
	case "VmPTE":
		.VmPTE = 
	case "VmPMD":
		.VmPMD = 
	case "VmSwap":
		.VmSwap = 
	case "HugetlbPages":
		.HugetlbPages = 
	case "voluntary_ctxt_switches":
		.VoluntaryCtxtSwitches = 
	case "nonvoluntary_ctxt_switches":
		.NonVoluntaryCtxtSwitches = 
	}
}
TotalCtxtSwitches returns the total context switch.