utils.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*
  2. Copyright 2015 The Kubernetes Authors.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package main
  14. import (
  15. "fmt"
  16. "log"
  17. "os/exec"
  18. "strconv"
  19. )
  20. const (
  21. consumeCPUBinary = "./consume-cpu/consume-cpu"
  22. consumeMemBinary = "stress"
  23. )
  24. // ConsumeCPU consumes a given number of millicores for the specified duration.
  25. func ConsumeCPU(millicores int, durationSec int) {
  26. log.Printf("ConsumeCPU millicores: %v, durationSec: %v", millicores, durationSec)
  27. // creating new consume cpu process
  28. arg1 := fmt.Sprintf("-millicores=%d", millicores)
  29. arg2 := fmt.Sprintf("-duration-sec=%d", durationSec)
  30. consumeCPU := exec.Command(consumeCPUBinary, arg1, arg2)
  31. consumeCPU.Run()
  32. }
  33. // ConsumeMem consumes a given number of megabytes for the specified duration.
  34. func ConsumeMem(megabytes int, durationSec int) {
  35. log.Printf("ConsumeMem megabytes: %v, durationSec: %v", megabytes, durationSec)
  36. megabytesString := strconv.Itoa(megabytes) + "M"
  37. durationSecString := strconv.Itoa(durationSec)
  38. // creating new consume memory process
  39. consumeMem := exec.Command(consumeMemBinary, "-m", "1", "--vm-bytes", megabytesString, "--vm-hang", "0", "-t", durationSecString)
  40. consumeMem.Run()
  41. }
  42. // GetCurrentStatus prints out a no-op.
  43. func GetCurrentStatus() {
  44. log.Printf("GetCurrentStatus")
  45. // not implemented
  46. }