mirror of
				https://github.com/moby/moby.git
				synced 2022-11-09 12:21:53 -05:00 
			
		
		
		
	stats: avoid cgo in collector
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
This commit is contained in:
		
							parent
							
								
									230a55d337
								
							
						
					
					
						commit
						cf104d85c3
					
				
					 1 changed files with 5 additions and 12 deletions
				
			
		| 
						 | 
				
			
			@ -9,13 +9,9 @@ import (
 | 
			
		|||
	"strings"
 | 
			
		||||
 | 
			
		||||
	"github.com/opencontainers/runc/libcontainer/system"
 | 
			
		||||
	"golang.org/x/sys/unix"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
#include <unistd.h>
 | 
			
		||||
*/
 | 
			
		||||
import "C"
 | 
			
		||||
 | 
			
		||||
// platformNewStatsCollector performs platform specific initialisation of the
 | 
			
		||||
// Collector structure.
 | 
			
		||||
func platformNewStatsCollector(s *Collector) {
 | 
			
		||||
| 
						 | 
				
			
			@ -70,13 +66,10 @@ func (s *Collector) getSystemCPUUsage() (uint64, error) {
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
func (s *Collector) getNumberOnlineCPUs() (uint32, error) {
 | 
			
		||||
	i, err := C.sysconf(C._SC_NPROCESSORS_ONLN)
 | 
			
		||||
	// According to POSIX - errno is undefined after successful
 | 
			
		||||
	// sysconf, and can be non-zero in several cases, so look for
 | 
			
		||||
	// error in returned value not in errno.
 | 
			
		||||
	// (https://sourceware.org/bugzilla/show_bug.cgi?id=21536)
 | 
			
		||||
	if i == -1 {
 | 
			
		||||
	var cpuset unix.CPUSet
 | 
			
		||||
	err := unix.SchedGetaffinity(0, &cpuset)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return 0, err
 | 
			
		||||
	}
 | 
			
		||||
	return uint32(i), nil
 | 
			
		||||
	return uint32(cpuset.Count()), nil
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue