| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2015 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2015 The WebRTC Project Authors. All rights reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 this.userTime = userTime; | 107 this.userTime = userTime; |
| 108 this.systemTime = systemTime; | 108 this.systemTime = systemTime; |
| 109 this.idleTime = idleTime; | 109 this.idleTime = idleTime; |
| 110 } | 110 } |
| 111 } | 111 } |
| 112 | 112 |
| 113 private static class MovingAverage { | 113 private static class MovingAverage { |
| 114 private final int size; | 114 private final int size; |
| 115 private double sum; | 115 private double sum; |
| 116 private double currentValue; | 116 private double currentValue; |
| 117 private double circBuffer[]; | 117 private double[] circBuffer; |
| 118 private int circBufferIndex; | 118 private int circBufferIndex; |
| 119 | 119 |
| 120 public MovingAverage(int size) { | 120 public MovingAverage(int size) { |
| 121 if (size <= 0) { | 121 if (size <= 0) { |
| 122 throw new AssertionError("Size value in MovingAverage ctor should be pos
itive."); | 122 throw new AssertionError("Size value in MovingAverage ctor should be pos
itive."); |
| 123 } | 123 } |
| 124 this.size = size; | 124 this.size = size; |
| 125 circBuffer = new double[size]; | 125 circBuffer = new double[size]; |
| 126 } | 126 } |
| 127 | 127 |
| (...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 473 long userTime = 0; | 473 long userTime = 0; |
| 474 long systemTime = 0; | 474 long systemTime = 0; |
| 475 long idleTime = 0; | 475 long idleTime = 0; |
| 476 try { | 476 try { |
| 477 BufferedReader reader = new BufferedReader(new FileReader("/proc/stat")); | 477 BufferedReader reader = new BufferedReader(new FileReader("/proc/stat")); |
| 478 try { | 478 try { |
| 479 // line should contain something like this: | 479 // line should contain something like this: |
| 480 // cpu 5093818 271838 3512830 165934119 101374 447076 272086 0 0 0 | 480 // cpu 5093818 271838 3512830 165934119 101374 447076 272086 0 0 0 |
| 481 // user nice system idle iowait irq softirq | 481 // user nice system idle iowait irq softirq |
| 482 String line = reader.readLine(); | 482 String line = reader.readLine(); |
| 483 String lines[] = line.split("\\s+"); | 483 String[] lines = line.split("\\s+"); |
| 484 int length = lines.length; | 484 int length = lines.length; |
| 485 if (length >= 5) { | 485 if (length >= 5) { |
| 486 userTime = parseLong(lines[1]); // user | 486 userTime = parseLong(lines[1]); // user |
| 487 userTime += parseLong(lines[2]); // nice | 487 userTime += parseLong(lines[2]); // nice |
| 488 systemTime = parseLong(lines[3]); // system | 488 systemTime = parseLong(lines[3]); // system |
| 489 idleTime = parseLong(lines[4]); // idle | 489 idleTime = parseLong(lines[4]); // idle |
| 490 } | 490 } |
| 491 if (length >= 8) { | 491 if (length >= 8) { |
| 492 userTime += parseLong(lines[5]); // iowait | 492 userTime += parseLong(lines[5]); // iowait |
| 493 systemTime += parseLong(lines[6]); // irq | 493 systemTime += parseLong(lines[6]); // irq |
| 494 systemTime += parseLong(lines[7]); // softirq | 494 systemTime += parseLong(lines[7]); // softirq |
| 495 } | 495 } |
| 496 } catch (Exception e) { | 496 } catch (Exception e) { |
| 497 Log.e(TAG, "Problems parsing /proc/stat", e); | 497 Log.e(TAG, "Problems parsing /proc/stat", e); |
| 498 return null; | 498 return null; |
| 499 } finally { | 499 } finally { |
| 500 reader.close(); | 500 reader.close(); |
| 501 } | 501 } |
| 502 } catch (FileNotFoundException e) { | 502 } catch (FileNotFoundException e) { |
| 503 Log.e(TAG, "Cannot open /proc/stat for reading", e); | 503 Log.e(TAG, "Cannot open /proc/stat for reading", e); |
| 504 return null; | 504 return null; |
| 505 } catch (IOException e) { | 505 } catch (IOException e) { |
| 506 Log.e(TAG, "Problems reading /proc/stat", e); | 506 Log.e(TAG, "Problems reading /proc/stat", e); |
| 507 return null; | 507 return null; |
| 508 } | 508 } |
| 509 return new ProcStat(userTime, systemTime, idleTime); | 509 return new ProcStat(userTime, systemTime, idleTime); |
| 510 } | 510 } |
| 511 } | 511 } |
| OLD | NEW |