Skip to content

Commit

Permalink
Merge pull request #287 from binjip978/parse_temp_int64
Browse files Browse the repository at this point in the history
parse temp as signed number
  • Loading branch information
pgier authored May 5, 2020
2 parents 9654394 + d4fa775 commit 29a8788
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 15 deletions.
24 changes: 12 additions & 12 deletions fixtures.ttar
Original file line number Diff line number Diff line change
Expand Up @@ -3571,7 +3571,7 @@ Mode: 664
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Path: fixtures/sys/class/thermal/thermal_zone1/temp
Lines: 1
44000
-44000
Mode: 664
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Path: fixtures/sys/class/thermal/thermal_zone1/type
Expand Down Expand Up @@ -4577,17 +4577,6 @@ Lines: 1
0
Mode: 644
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Path: fixtures/sys/fs/bcache/deaddd54-c735-46d5-868e-f331c5fd7c74/bdev0/writeback_rate_debug
Lines: 7
rate: 1.1M/sec
dirty: 20.4G
target: 20.4G
proportional: 427.5k
integral: 790.0k
change: 321.5k/sec
next io: 17ms
Mode: 644
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Directory: fixtures/sys/fs/bcache/deaddd54-c735-46d5-868e-f331c5fd7c74/bdev0/stats_day
Mode: 755
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Expand Down Expand Up @@ -4760,6 +4749,17 @@ Lines: 1
0
Mode: 644
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Path: fixtures/sys/fs/bcache/deaddd54-c735-46d5-868e-f331c5fd7c74/bdev0/writeback_rate_debug
Lines: 7
rate: 1.1M/sec
dirty: 20.4G
target: 20.4G
proportional: 427.5k
integral: 790.0k
change: 321.5k/sec
next io: 17ms
Mode: 644
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Path: fixtures/sys/fs/bcache/deaddd54-c735-46d5-868e-f331c5fd7c74/btree_cache_size
Lines: 1
0
Expand Down
9 changes: 9 additions & 0 deletions internal/util/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,15 @@ func ReadUintFromFile(path string) (uint64, error) {
return strconv.ParseUint(strings.TrimSpace(string(data)), 10, 64)
}

// ReadIntFromFile reads a file and attempts to parse a int64 from it.
func ReadIntFromFromFile(path string) (int64, error) {
data, err := ioutil.ReadFile(path)
if err != nil {
return 0, err
}
return strconv.ParseInt(strings.TrimSpace(string(data)), 10, 64)
}

// ParseBool parses a string into a boolean pointer.
func ParseBool(b string) *bool {
var truth bool
Expand Down
4 changes: 2 additions & 2 deletions sysfs/class_thermal.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
type ClassThermalZoneStats struct {
Name string // The name of the zone from the directory structure.
Type string // The type of thermal zone.
Temp uint64 // Temperature in millidegree Celsius.
Temp int64 // Temperature in millidegree Celsius.
Policy string // One of the various thermal governors used for a particular zone.
Mode *bool // Optional: One of the predefined values in [enabled, disabled].
Passive *uint64 // Optional: millidegrees Celsius. (0 for disabled, > 1000 for enabled+value)
Expand Down Expand Up @@ -67,7 +67,7 @@ func parseClassThermalZone(zone string) (ClassThermalZoneStats, error) {
if err != nil {
return ClassThermalZoneStats{}, err
}
zoneTemp, err := util.ReadUintFromFile(filepath.Join(zone, "temp"))
zoneTemp, err := util.ReadIntFromFromFile(filepath.Join(zone, "temp"))
if err != nil {
return ClassThermalZoneStats{}, err
}
Expand Down
2 changes: 1 addition & 1 deletion sysfs/class_thermal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func TestClassThermalZoneStats(t *testing.T) {
Name: "1",
Type: "acpitz",
Policy: "step_wise",
Temp: 44000,
Temp: -44000,
Mode: enabled,
Passive: &passive,
},
Expand Down

0 comments on commit 29a8788

Please sign in to comment.