(filePath string)
| 74 | } |
| 75 | |
| 76 | func readCpuUsage(filePath string) (float64, error) { |
| 77 | found := false |
| 78 | var usageUsec float64 |
| 79 | f, err := os.Open(filePath) |
| 80 | if err != nil { |
| 81 | return usageUsec, err |
| 82 | } |
| 83 | defer f.Close() |
| 84 | |
| 85 | r := bufio.NewReader(f) |
| 86 | for { |
| 87 | line, err := r.ReadString('\n') |
| 88 | if err != nil { |
| 89 | break |
| 90 | } |
| 91 | line = strings.TrimRight(line, "\n") |
| 92 | split := strings.Split(line, " ") |
| 93 | if len(split) < 2 { |
| 94 | continue |
| 95 | } |
| 96 | if split[0] == "usage_usec" { |
| 97 | usageUsec, err = strconv.ParseFloat(split[1], 64) |
| 98 | if err != nil { |
| 99 | return usageUsec, err |
| 100 | } |
| 101 | found = true |
| 102 | break |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | if !found { |
| 107 | return usageUsec, fmt.Errorf("field usage_usec not found") |
| 108 | } |
| 109 | |
| 110 | return usageUsec, nil |
| 111 | } |
| 112 | |
| 113 | func readUint64(filePath string) (uint64, error) { |
| 114 | var ret uint64 |
no outgoing calls
no test coverage detected