Skip to content

Commit de3a686

Browse files
author
binjip978
committed
parse temp as signed number
Signed-off-by: binjip978 <[email protected]>
1 parent c5c7bc5 commit de3a686

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
@@ -3160,7 +3160,7 @@ Mode: 664
31603160
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
31613161
Path: fixtures/sys/class/thermal/thermal_zone1/temp
31623162
Lines: 1
3163-
44000
3163+
-44000
31643164
Mode: 664
31653165
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
31663166
Path: fixtures/sys/class/thermal/thermal_zone1/type
@@ -4166,17 +4166,6 @@ Lines: 1
41664166
0
41674167
Mode: 644
41684168
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
4169-
Path: fixtures/sys/fs/bcache/deaddd54-c735-46d5-868e-f331c5fd7c74/bdev0/writeback_rate_debug
4170-
Lines: 7
4171-
rate: 1.1M/sec
4172-
dirty: 20.4G
4173-
target: 20.4G
4174-
proportional: 427.5k
4175-
integral: 790.0k
4176-
change: 321.5k/sec
4177-
next io: 17ms
4178-
Mode: 644
4179-
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
41804169
Directory: fixtures/sys/fs/bcache/deaddd54-c735-46d5-868e-f331c5fd7c74/bdev0/stats_day
41814170
Mode: 755
41824171
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@@ -4349,6 +4338,17 @@ Lines: 1
43494338
0
43504339
Mode: 644
43514340
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
4341+
Path: fixtures/sys/fs/bcache/deaddd54-c735-46d5-868e-f331c5fd7c74/bdev0/writeback_rate_debug
4342+
Lines: 7
4343+
rate: 1.1M/sec
4344+
dirty: 20.4G
4345+
target: 20.4G
4346+
proportional: 427.5k
4347+
integral: 790.0k
4348+
change: 321.5k/sec
4349+
next io: 17ms
4350+
Mode: 644
4351+
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
43524352
Path: fixtures/sys/fs/bcache/deaddd54-c735-46d5-868e-f331c5fd7c74/btree_cache_size
43534353
Lines: 1
43544354
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)