Skip to content

Commit 29a8788

Browse files
authored
Merge pull request #287 from binjip978/parse_temp_int64
parse temp as signed number
2 parents 9654394 + d4fa775 commit 29a8788

File tree

4 files changed

+24
-15
lines changed

4 files changed

+24
-15
lines changed

fixtures.ttar

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3571,7 +3571,7 @@ Mode: 664
35713571
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
35723572
Path: fixtures/sys/class/thermal/thermal_zone1/temp
35733573
Lines: 1
3574-
44000
3574+
-44000
35753575
Mode: 664
35763576
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
35773577
Path: fixtures/sys/class/thermal/thermal_zone1/type
@@ -4577,17 +4577,6 @@ Lines: 1
45774577
0
45784578
Mode: 644
45794579
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
4580-
Path: fixtures/sys/fs/bcache/deaddd54-c735-46d5-868e-f331c5fd7c74/bdev0/writeback_rate_debug
4581-
Lines: 7
4582-
rate: 1.1M/sec
4583-
dirty: 20.4G
4584-
target: 20.4G
4585-
proportional: 427.5k
4586-
integral: 790.0k
4587-
change: 321.5k/sec
4588-
next io: 17ms
4589-
Mode: 644
4590-
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
45914580
Directory: fixtures/sys/fs/bcache/deaddd54-c735-46d5-868e-f331c5fd7c74/bdev0/stats_day
45924581
Mode: 755
45934582
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@@ -4760,6 +4749,17 @@ Lines: 1
47604749
0
47614750
Mode: 644
47624751
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
4752+
Path: fixtures/sys/fs/bcache/deaddd54-c735-46d5-868e-f331c5fd7c74/bdev0/writeback_rate_debug
4753+
Lines: 7
4754+
rate: 1.1M/sec
4755+
dirty: 20.4G
4756+
target: 20.4G
4757+
proportional: 427.5k
4758+
integral: 790.0k
4759+
change: 321.5k/sec
4760+
next io: 17ms
4761+
Mode: 644
4762+
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
47634763
Path: fixtures/sys/fs/bcache/deaddd54-c735-46d5-868e-f331c5fd7c74/btree_cache_size
47644764
Lines: 1
47654765
0

internal/util/parse.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,15 @@ func ReadUintFromFile(path string) (uint64, error) {
7373
return strconv.ParseUint(strings.TrimSpace(string(data)), 10, 64)
7474
}
7575

76+
// ReadIntFromFile reads a file and attempts to parse a int64 from it.
77+
func ReadIntFromFromFile(path string) (int64, error) {
78+
data, err := ioutil.ReadFile(path)
79+
if err != nil {
80+
return 0, err
81+
}
82+
return strconv.ParseInt(strings.TrimSpace(string(data)), 10, 64)
83+
}
84+
7685
// ParseBool parses a string into a boolean pointer.
7786
func ParseBool(b string) *bool {
7887
var truth bool

sysfs/class_thermal.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import (
2929
type ClassThermalZoneStats struct {
3030
Name string // The name of the zone from the directory structure.
3131
Type string // The type of thermal zone.
32-
Temp uint64 // Temperature in millidegree Celsius.
32+
Temp int64 // Temperature in millidegree Celsius.
3333
Policy string // One of the various thermal governors used for a particular zone.
3434
Mode *bool // Optional: One of the predefined values in [enabled, disabled].
3535
Passive *uint64 // Optional: millidegrees Celsius. (0 for disabled, > 1000 for enabled+value)
@@ -67,7 +67,7 @@ func parseClassThermalZone(zone string) (ClassThermalZoneStats, error) {
6767
if err != nil {
6868
return ClassThermalZoneStats{}, err
6969
}
70-
zoneTemp, err := util.ReadUintFromFile(filepath.Join(zone, "temp"))
70+
zoneTemp, err := util.ReadIntFromFromFile(filepath.Join(zone, "temp"))
7171
if err != nil {
7272
return ClassThermalZoneStats{}, err
7373
}

sysfs/class_thermal_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func TestClassThermalZoneStats(t *testing.T) {
4949
Name: "1",
5050
Type: "acpitz",
5151
Policy: "step_wise",
52-
Temp: 44000,
52+
Temp: -44000,
5353
Mode: enabled,
5454
Passive: &passive,
5555
},

0 commit comments

Comments
 (0)