Remove cgo use and lots of ad-hoc defined kernel constants
This commit is contained in:
parent
9fdea2af96
commit
1493d8af7d
@ -1,26 +0,0 @@
|
|||||||
// Copyright 2015 Google Inc. All Rights Reserved.
|
|
||||||
//
|
|
||||||
// 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 netlink
|
|
||||||
|
|
||||||
/*
|
|
||||||
#include <linux/taskstats.h>
|
|
||||||
*/
|
|
||||||
import "C"
|
|
||||||
|
|
||||||
type TaskStats C.struct_taskstats
|
|
||||||
|
|
||||||
const (
|
|
||||||
__TASKSTATS_CMD_MAX = C.__TASKSTATS_CMD_MAX
|
|
||||||
)
|
|
@ -22,16 +22,7 @@ import (
|
|||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
info "github.com/google/cadvisor/info/v1"
|
info "github.com/google/cadvisor/info/v1"
|
||||||
)
|
"golang.org/x/sys/unix"
|
||||||
|
|
||||||
const (
|
|
||||||
// Kernel constants for tasks stats.
|
|
||||||
genlIdCtrl = syscall.NLMSG_MIN_TYPE // GENL_ID_CTRL
|
|
||||||
taskstatsGenlName = "TASKSTATS" // TASKSTATS_GENL_NAME
|
|
||||||
cgroupStatsCmdAttrFd = 0x1 // CGROUPSTATS_CMD_ATTR_FD
|
|
||||||
ctrlAttrFamilyId = 0x1 // CTRL_ATTR_FAMILY_ID
|
|
||||||
ctrlAttrFamilyName = 0x2 // CTRL_ATTR_FAMILY_NAME
|
|
||||||
ctrlCmdGetFamily = 0x3 // CTRL_CMD_GETFAMILY
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -124,15 +115,15 @@ func prepareMessage(headerType uint16, cmd uint8, attributes []byte) (msg netlin
|
|||||||
// Prepares message to query family id for task stats.
|
// Prepares message to query family id for task stats.
|
||||||
func prepareFamilyMessage() (msg netlinkMessage) {
|
func prepareFamilyMessage() (msg netlinkMessage) {
|
||||||
buf := bytes.NewBuffer([]byte{})
|
buf := bytes.NewBuffer([]byte{})
|
||||||
addAttribute(buf, ctrlAttrFamilyName, taskstatsGenlName, len(taskstatsGenlName)+1)
|
addAttribute(buf, unix.CTRL_ATTR_FAMILY_NAME, unix.TASKSTATS_GENL_NAME, len(unix.TASKSTATS_GENL_NAME)+1)
|
||||||
return prepareMessage(genlIdCtrl, ctrlCmdGetFamily, buf.Bytes())
|
return prepareMessage(unix.GENL_ID_CTRL, unix.CTRL_CMD_GETFAMILY, buf.Bytes())
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prepares message to query task stats for a task group.
|
// Prepares message to query task stats for a task group.
|
||||||
func prepareCmdMessage(id uint16, cfd uintptr) (msg netlinkMessage) {
|
func prepareCmdMessage(id uint16, cfd uintptr) (msg netlinkMessage) {
|
||||||
buf := bytes.NewBuffer([]byte{})
|
buf := bytes.NewBuffer([]byte{})
|
||||||
addAttribute(buf, cgroupStatsCmdAttrFd, uint32(cfd), 4)
|
addAttribute(buf, unix.CGROUPSTATS_CMD_ATTR_FD, uint32(cfd), 4)
|
||||||
return prepareMessage(id, __TASKSTATS_CMD_MAX+1, buf.Bytes())
|
return prepareMessage(id, unix.CGROUPSTATS_CMD_GET, buf.Bytes())
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extracts returned family id from the response.
|
// Extracts returned family id from the response.
|
||||||
@ -158,7 +149,7 @@ func parseFamilyResp(msg syscall.NetlinkMessage) (uint16, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
if attr.Type == ctrlAttrFamilyId {
|
if attr.Type == unix.CTRL_ATTR_FAMILY_ID {
|
||||||
err = binary.Read(buf, Endian, &id)
|
err = binary.Read(buf, Endian, &id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
|
Loading…
Reference in New Issue
Block a user