forked from influxdata/telegraf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
unit_converter.go
49 lines (38 loc) · 1.03 KB
/
unit_converter.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// +build linux
package intel_powerstat
import (
"math"
"strconv"
)
const (
microJouleToJoule = 1.0 / 1000000
microWattToWatt = 1.0 / 1000000
kiloHertzToMegaHertz = 1.0 / 1000
nanoSecondsToSeconds = 1.0 / 1000000000
cyclesToHertz = 1.0 / 1000000
)
func convertMicroJoulesToJoules(mJ float64) float64 {
return mJ * microJouleToJoule
}
func convertMicroWattToWatt(mW float64) float64 {
return mW * microWattToWatt
}
func convertKiloHertzToMegaHertz(kHz float64) float64 {
return kHz * kiloHertzToMegaHertz
}
func convertNanoSecondsToSeconds(ns int64) float64 {
return float64(ns) * nanoSecondsToSeconds
}
func convertProcessorCyclesToHertz(pc uint64) float64 {
return float64(pc) * cyclesToHertz
}
func roundFloatToNearestTwoDecimalPlaces(n float64) float64 {
return math.Round(n*100) / 100
}
func convertIntegerArrayToStringArray(array []int64) []string {
stringArray := make([]string, 0)
for _, value := range array {
stringArray = append(stringArray, strconv.FormatInt(value, 10))
}
return stringArray
}