avg_power.sh 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #!/bin/bash
  2. #
  3. # Script to measure the average power drawn by
  4. # the device.
  5. #
  6. # Copyright (C) 2007-2009 Michael Buesch <mb@bu3sch.de>
  7. # GPLv2+
  8. #
  9. PCIBX="./pcibx -V1 $@" # path to pcibx
  10. cnt=50 # number of measurements
  11. echo "1 + 1" | bc 2>&1 >/dev/null
  12. if [ $? -ne 0 ]; then
  13. echo "Could not execute \"bc\"."
  14. echo "Is bc installed?"
  15. exit 1
  16. fi
  17. function measure # $1=what
  18. {
  19. local tmp
  20. tmp="$($PCIBX --cmd-measure$1)"
  21. [ $? -eq 0 ] || exit 1
  22. RES="$(echo $tmp | cut -d' ' -f2)"
  23. }
  24. S="scale=3;"
  25. avg_a5="0"
  26. avg_a12="0"
  27. avg_a33="0"
  28. avg_v5="0"
  29. avg_v12="0"
  30. avg_v33="0"
  31. echo -n "measuring" >&2
  32. for ((i = 0; i < $cnt; i++)); do
  33. echo -n "." >&2
  34. measure a5
  35. avg_a5=$(echo "$S $avg_a5 + $RES" | bc)
  36. measure v5uut
  37. avg_v5=$(echo "$S $avg_v5 + $RES" | bc)
  38. measure a12
  39. avg_a12=$(echo "$S $avg_a12 + $RES" | bc)
  40. measure v12uut
  41. avg_v12=$(echo "$S $avg_v12 + $RES" | bc)
  42. measure a33
  43. avg_a33=$(echo "$S $avg_a33 + $RES" | bc)
  44. measure v33uut
  45. avg_v33=$(echo "$S $avg_v33 + $RES" | bc)
  46. done
  47. echo "OK" >&2
  48. echo >&2
  49. avg_a5=$(echo "$S $avg_a5 / $cnt" | bc)
  50. avg_a12=$(echo "$S $avg_a12 / $cnt" | bc)
  51. avg_a33=$(echo "$S $avg_a33 / $cnt" | bc)
  52. avg_v5=$(echo "$S $avg_v5 / $cnt" | bc)
  53. avg_v12=$(echo "$S $avg_v12 / $cnt" | bc)
  54. avg_v33=$(echo "$S $avg_v33 / $cnt" | bc)
  55. va5=$(echo "$S $avg_v5 * $avg_a5" | bc)
  56. va12=$(echo "$S $avg_v12 * $avg_a12" | bc)
  57. va33=$(echo "$S $avg_v33 * $avg_a33" | bc)
  58. va_all=$(echo "$S $va5 + $va12 + $va33" | bc)
  59. echo "5V line: $avg_v5 Volts, $avg_a5 Ampere => $va5 VA"
  60. echo "12V line: $avg_v12 Volts, $avg_a12 Ampere => $va12 VA"
  61. echo "3.3V line: $avg_v33 Volts, $avg_a33 Ampere => $va33 VA"
  62. echo "-------------"
  63. echo "= $va_all VA"
  64. exit 0