mirror of
https://github.com/containers/podman.git
synced 2025-11-16 11:07:44 +08:00
vendor: update containers/psgo
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
This commit is contained in:
20
vendor/github.com/containers/psgo/internal/host/host.go
generated
vendored
20
vendor/github.com/containers/psgo/internal/host/host.go
generated
vendored
@@ -24,26 +24,6 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
/*
|
||||
#include <unistd.h>
|
||||
*/
|
||||
import "C"
|
||||
|
||||
var (
|
||||
// cache host queries to redundant calculations
|
||||
clockTicks *int64
|
||||
bootTime *int64
|
||||
)
|
||||
|
||||
// ClockTicks returns sysconf(SC_CLK_TCK).
|
||||
func ClockTicks() int64 {
|
||||
if clockTicks == nil {
|
||||
ticks := int64(C.sysconf(C._SC_CLK_TCK))
|
||||
clockTicks = &ticks
|
||||
}
|
||||
return *clockTicks
|
||||
}
|
||||
|
||||
// BootTime parses /proc/uptime returns the boot time in seconds since the
|
||||
// Epoch, 1970-01-01 00:00:00 +0000 (UTC).
|
||||
func BootTime() (int64, error) {
|
||||
|
||||
37
vendor/github.com/containers/psgo/internal/host/host_cgo.go
generated
vendored
Normal file
37
vendor/github.com/containers/psgo/internal/host/host_cgo.go
generated
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
// Copyright 2018 psgo 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 host extracts data from the host, such as the system's boot time or
|
||||
// the tick rate of the system clock.
|
||||
package host
|
||||
|
||||
/*
|
||||
#include <unistd.h>
|
||||
*/
|
||||
import "C"
|
||||
|
||||
var (
|
||||
// cache host queries to redundant calculations
|
||||
clockTicks *int64
|
||||
bootTime *int64
|
||||
)
|
||||
|
||||
// ClockTicks returns sysconf(SC_CLK_TCK).
|
||||
func ClockTicks() (int64, error) {
|
||||
if clockTicks == nil {
|
||||
ticks := int64(C.sysconf(C._SC_CLK_TCK))
|
||||
clockTicks = &ticks
|
||||
}
|
||||
return *clockTicks, nil
|
||||
}
|
||||
84
vendor/github.com/containers/psgo/internal/host/host_nocgo.go
generated
vendored
Normal file
84
vendor/github.com/containers/psgo/internal/host/host_nocgo.go
generated
vendored
Normal file
@@ -0,0 +1,84 @@
|
||||
// +build !cgo
|
||||
|
||||
// Copyright 2018 psgo 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 host extracts data from the host, such as the system's boot time or
|
||||
// the tick rate of the system clock.
|
||||
package host
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
var (
|
||||
// cache host queries to redundant calculations
|
||||
clockTicks *int64
|
||||
bootTime *int64
|
||||
)
|
||||
|
||||
func getNativeEndianness() binary.ByteOrder {
|
||||
var i int32 = 0x00000001
|
||||
u := unsafe.Pointer(&i)
|
||||
if *((*byte)(u)) == 0x01 {
|
||||
return binary.LittleEndian
|
||||
}
|
||||
return binary.BigEndian
|
||||
}
|
||||
|
||||
const (
|
||||
atClktck = 17
|
||||
)
|
||||
|
||||
func getFromAuxv(what uint, whatName string) (uint, error) {
|
||||
dataLen := int(unsafe.Sizeof(int(0)))
|
||||
p, err := ioutil.ReadFile("/proc/self/auxv")
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
native := getNativeEndianness()
|
||||
for i := 0; i < len(p); {
|
||||
var k, v uint
|
||||
|
||||
switch dataLen {
|
||||
case 4:
|
||||
k = uint(native.Uint32(p[i : i+dataLen]))
|
||||
v = uint(native.Uint32(p[i+dataLen : i+dataLen*2]))
|
||||
case 8:
|
||||
k = uint(native.Uint64(p[i : i+dataLen]))
|
||||
v = uint(native.Uint64(p[i+dataLen : i+dataLen*2]))
|
||||
}
|
||||
i += dataLen * 2
|
||||
if k == what {
|
||||
return v, nil
|
||||
}
|
||||
}
|
||||
return 0, fmt.Errorf("cannot find %s in auxv", whatName)
|
||||
}
|
||||
|
||||
// ClockTicks returns sysconf(SC_CLK_TCK).
|
||||
func ClockTicks() (int64, error) {
|
||||
if clockTicks == nil {
|
||||
ret, err := getFromAuxv(atClktck, "AT_CLKTCK")
|
||||
if err != nil {
|
||||
return -1, err
|
||||
}
|
||||
ticks := int64(ret)
|
||||
clockTicks = &ticks
|
||||
}
|
||||
return *clockTicks, nil
|
||||
}
|
||||
12
vendor/github.com/containers/psgo/internal/process/process.go
generated
vendored
12
vendor/github.com/containers/psgo/internal/process/process.go
generated
vendored
@@ -192,8 +192,12 @@ func (p *Process) ElapsedTime() (time.Duration, error) {
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
clockTicks, err := host.ClockTicks()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
sinceBoot = sinceBoot / host.ClockTicks()
|
||||
sinceBoot = sinceBoot / clockTicks
|
||||
|
||||
bootTime, err := host.BootTime()
|
||||
if err != nil {
|
||||
@@ -213,7 +217,11 @@ func (p *Process) CPUTime() (time.Duration, error) {
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
secs := (user + system) / host.ClockTicks()
|
||||
clockTicks, err := host.ClockTicks()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
secs := (user + system) / clockTicks
|
||||
cpu := time.Unix(secs, 0)
|
||||
return cpu.Sub(time.Unix(0, 0)), nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user