From 82810f13cd4fc304c855edcdf5ca78db71b447a7 Mon Sep 17 00:00:00 2001 From: Jimmi Dyson Date: Fri, 27 Nov 2015 21:48:33 +0000 Subject: [PATCH] Remove unused code (via deadcode linter) --- container/docker/factory.go | 3 +- container/libcontainer/helpers.go | 5 ++- info/v1/container.go | 19 ----------- pages/containers.go | 14 -------- storage/bigquery/client/client.go | 1 - storage/test/storagetests.go | 11 ------- utils/fs/fs.go | 44 ------------------------- utils/fs/mockfs/fakefile.go | 35 -------------------- utils/fs/mockfs/mockfs.go | 55 ------------------------------- 9 files changed, 3 insertions(+), 184 deletions(-) delete mode 100644 utils/fs/fs.go delete mode 100644 utils/fs/mockfs/fakefile.go delete mode 100644 utils/fs/mockfs/mockfs.go diff --git a/container/docker/factory.go b/container/docker/factory.go index efac6123..3ba431ac 100644 --- a/container/docker/factory.go +++ b/container/docker/factory.go @@ -87,8 +87,7 @@ func RootDir() string { type storageDriver string const ( - devicemapperStorageDriver storageDriver = "devicemapper" - aufsStorageDriver storageDriver = "aufs" + aufsStorageDriver storageDriver = "aufs" ) type dockerFactory struct { diff --git a/container/libcontainer/helpers.go b/container/libcontainer/helpers.go index 83dcfc75..85453346 100644 --- a/container/libcontainer/helpers.go +++ b/container/libcontainer/helpers.go @@ -17,7 +17,6 @@ package libcontainer import ( "bufio" "fmt" - "io/ioutil" "os" "path" "strconv" @@ -146,8 +145,6 @@ func isIgnoredDevice(ifName string) bool { return false } -const netstatsLine = `%s %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d` - func scanInterfaceStats(netStatsFile string) ([]info.InterfaceStats, error) { file, err := os.Open(netStatsFile) if err != nil { @@ -213,6 +210,7 @@ func setInterfaceStatValues(fields []string, pointers []*uint64) error { return nil } +/* func tcpStatsFromProc(rootFs string, pid int, file string) (info.TcpStat, error) { tcpStatsFile := path.Join(rootFs, "proc", strconv.Itoa(pid), file) @@ -287,6 +285,7 @@ func scanTcpStats(tcpStatsFile string) (info.TcpStat, error) { return stats, nil } +*/ func GetProcesses(cgroupManager cgroups.Manager) ([]int, error) { pids, err := cgroupManager.GetPids() diff --git a/info/v1/container.go b/info/v1/container.go index 0994ad9d..d8d27fd1 100644 --- a/info/v1/container.go +++ b/info/v1/container.go @@ -476,17 +476,6 @@ func timeEq(t1, t2 time.Time, tolerance time.Duration) bool { return false } -func durationEq(a, b time.Duration, tolerance time.Duration) bool { - if a > b { - a, b = b, a - } - diff := a - b - if diff <= tolerance { - return true - } - return false -} - const ( // 10ms, i.e. 0.01s timePrecision time.Duration = 10 * time.Millisecond @@ -522,14 +511,6 @@ func (a *ContainerStats) StatsEq(b *ContainerStats) bool { return true } -// Saturate CPU usage to 0. -func calculateCpuUsage(prev, cur uint64) uint64 { - if prev > cur { - return 0 - } - return cur - prev -} - // Event contains information general to events such as the time at which they // occurred, their specific type, and the actual event. Event types are // differentiated by the EventType field of Event. diff --git a/pages/containers.go b/pages/containers.go index 6eab760e..d6f3144b 100644 --- a/pages/containers.go +++ b/pages/containers.go @@ -144,10 +144,6 @@ func printShares(shares *uint64) string { return fmt.Sprintf("%d", *shares) } -func toMegabytes(bytes uint64) float64 { - return float64(bytes) / (1 << 20) -} - // Size after which we consider memory to be "unlimited". This is not // MaxInt64 due to rounding by the kernel. const maxMemorySize = uint64(1 << 62) @@ -166,16 +162,6 @@ func printUnit(bytes uint64) string { return ByteSize(bytes).Unit() } -func toMemoryPercent(usage uint64, spec *info.ContainerSpec, machine *info.MachineInfo) int { - // Saturate limit to the machine size. - limit := uint64(spec.Memory.Limit) - if limit > uint64(machine.MemoryCapacity) { - limit = uint64(machine.MemoryCapacity) - } - - return int((usage * 100) / limit) -} - func serveContainersPage(m manager.Manager, w http.ResponseWriter, u *url.URL) error { start := time.Now() diff --git a/storage/bigquery/client/client.go b/storage/bigquery/client/client.go index db01528c..5a040970 100644 --- a/storage/bigquery/client/client.go +++ b/storage/bigquery/client/client.go @@ -36,7 +36,6 @@ var ( const ( errAlreadyExists string = "Error 409: Already Exists" - queryLimit int64 = 200 ) type Client struct { diff --git a/storage/test/storagetests.go b/storage/test/storagetests.go index db218e40..f9162833 100644 --- a/storage/test/storagetests.go +++ b/storage/test/storagetests.go @@ -77,17 +77,6 @@ func TimeEq(t1, t2 time.Time, tolerance time.Duration) bool { return false } -func durationEq(a, b time.Duration, tolerance time.Duration) bool { - if a > b { - a, b = b, a - } - diff := a - b - if diff <= tolerance { - return true - } - return false -} - const ( // 10ms, i.e. 0.01s timePrecision time.Duration = 10 * time.Millisecond diff --git a/utils/fs/fs.go b/utils/fs/fs.go deleted file mode 100644 index d5999a9b..00000000 --- a/utils/fs/fs.go +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright 2014 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 fs - -import ( - "io" - "os" -) - -type osFS struct{} - -func (osFS) Open(name string) (File, error) { return os.Open(name) } -func (osFS) Stat(name string) (os.FileInfo, error) { return os.Stat(name) } - -var fs FileSystem = osFS{} - -type FileSystem interface { - Open(name string) (File, error) -} - -type File interface { - io.ReadWriteCloser -} - -// Useful for tests. Not thread safe. -func ChangeFileSystem(filesystem FileSystem) { - fs = filesystem -} - -func Open(name string) (File, error) { - return fs.Open(name) -} diff --git a/utils/fs/mockfs/fakefile.go b/utils/fs/mockfs/fakefile.go deleted file mode 100644 index 77a3f487..00000000 --- a/utils/fs/mockfs/fakefile.go +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright 2014 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 mockfs - -import "bytes" - -type FakeFile struct { - bytes.Buffer - Name string -} - -func (self *FakeFile) Close() error { - return nil -} - -func AddTextFile(mockfs *MockFileSystem, name, content string) *FakeFile { - f := &FakeFile{ - Name: name, - Buffer: *bytes.NewBufferString(content), - } - mockfs.EXPECT().Open(name).Return(f, nil).AnyTimes() - return f -} diff --git a/utils/fs/mockfs/mockfs.go b/utils/fs/mockfs/mockfs.go deleted file mode 100644 index cc3d615e..00000000 --- a/utils/fs/mockfs/mockfs.go +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright 2014 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. - -// Automatically generated by MockGen. DO NOT EDIT! -// Source: github.com/google/cadvisor/utils/fs (interfaces: FileSystem) - -package mockfs - -import ( - gomock "github.com/golang/mock/gomock" - fs "github.com/google/cadvisor/utils/fs" -) - -// Mock of FileSystem interface -type MockFileSystem struct { - ctrl *gomock.Controller - recorder *_MockFileSystemRecorder -} - -// Recorder for MockFileSystem (not exported) -type _MockFileSystemRecorder struct { - mock *MockFileSystem -} - -func NewMockFileSystem(ctrl *gomock.Controller) *MockFileSystem { - mock := &MockFileSystem{ctrl: ctrl} - mock.recorder = &_MockFileSystemRecorder{mock} - return mock -} - -func (_m *MockFileSystem) EXPECT() *_MockFileSystemRecorder { - return _m.recorder -} - -func (_m *MockFileSystem) Open(_param0 string) (fs.File, error) { - ret := _m.ctrl.Call(_m, "Open", _param0) - ret0, _ := ret[0].(fs.File) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -func (_mr *_MockFileSystemRecorder) Open(arg0 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "Open", arg0) -}