mirror of
https://github.com/priyanshujain/sanderling.git
synced 2026-10-02 11:07:10 +00:00
fix(driver): a CPU sample the driver never took is absent, not zero
CDP exposes no per-page CPU, so chrome's Metrics filled CPUPercent with a zero, which is the same answer an idle app gives. Making the field optional is the same fix as the iOS reads: absence is the only honest way to say nothing looked.
This commit is contained in:
1 parent
577993b540
commit
1fb910e0a2
3 files changed
+8
-3
No files matched your search
@@ -183,7 +183,10 @@ type Health struct {
|
||||
}
|
||||
|
||||
type Metrics struct {
|
||||
CPUPercent float64
|
||||
// CPUPercent is nil on a driver that samples memory but not CPU, which
|
||||
// Chrome does: zero is a reading an idle app can produce, so a driver that
|
||||
// never looked has to answer with nothing rather than with that.
|
||||
CPUPercent *float64
|
||||
HeapBytes int64
|
||||
TotalMemoryBytes int64
|
||||
}
|
||||
|
||||
@@ -300,8 +300,9 @@ func (c *Client) Metrics(ctx context.Context, bundleID string) (driver.Metrics,
|
||||
if err != nil {
|
||||
return driver.Metrics{}, err
|
||||
}
|
||||
cpuPercent := response.GetCpuPercent()
|
||||
return driver.Metrics{
|
||||
CPUPercent: response.GetCpuPercent(),
|
||||
CPUPercent: &cpuPercent,
|
||||
HeapBytes: response.GetHeapBytes(),
|
||||
TotalMemoryBytes: response.GetTotalMemoryBytes(),
|
||||
}, nil
|
||||
|
||||
@@ -651,7 +651,8 @@ func TestClient_MetricsMapsResponseFields(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got.CPUPercent != 12.5 || got.HeapBytes != 100 || got.TotalMemoryBytes != 200 {
|
||||
if got.CPUPercent == nil || *got.CPUPercent != 12.5 ||
|
||||
got.HeapBytes != 100 || got.TotalMemoryBytes != 200 {
|
||||
t.Errorf("metrics mapping wrong: %+v", got)
|
||||
}
|
||||
if len(state.fake.metricsBundles) != 1 || state.fake.metricsBundles[0] != "com.example" {
|
||||
|
||||
Reference in new issue
Block a user