diff options
author | Enrico Granata <egranata@google.com> | 2018-01-22 17:34:46 -0800 |
---|---|---|
committer | Enrico Granata <egranata@google.com> | 2018-02-05 12:39:12 -0800 |
commit | 1690a62b71936aa4c9f555858e0560ddaf8e54ba (patch) | |
tree | 34a2b1de6f6bb59042d60cf685a876554999242b /tests/common_utils | |
parent | 97912b4c72d72cc5d866e0e91c4bc9a0f56abe9a (diff) | |
download | Car-1690a62b71936aa4c9f555858e0560ddaf8e54ba.tar.gz |
Implement logic in CarStorageMonitoringManager to detect the cost (in terms of disk I/O) of the previous shutdown
ext4 and f2fs offer lifetime_write_kbytes files via sysfs that let userspace discover the amount of data
written to each individual partition throughout its lifetime.
Using this information, we execute this algorithm:
- when CarService goes down, store lifetime_write_kbytes info for all mounted partitions;
- at the next boot, calculate lifetime_write_kbytes for all mounted partitions again;
- for every partition that existed at both shutdown and reboot, calculate the difference of the written amount;
- add up those deltas: this is the total amount of writes since CarService went down;
- take the aggregate UID I/O activity, and add up all bytes written to disk inferred from there: this is the cost of getting where we are;
- subtract this aggregate from the previously computed total delta: this is a fair approximation of the cost of shutdown
Test: tests in carservice_test and carservice_unit_test
Bug: 32512551
Change-Id: Ia791eaa1fdb4bf026c1760e2bd333c30a413721f
Fixes: 72236603
Diffstat (limited to 'tests/common_utils')
-rw-r--r-- | tests/common_utils/src/com/android/car/test/utils/TemporaryDirectory.java | 10 | ||||
-rw-r--r-- | tests/common_utils/src/com/android/car/test/utils/TemporaryFile.java | 8 |
2 files changed, 18 insertions, 0 deletions
diff --git a/tests/common_utils/src/com/android/car/test/utils/TemporaryDirectory.java b/tests/common_utils/src/com/android/car/test/utils/TemporaryDirectory.java index fa5727d903..e1c4735faa 100644 --- a/tests/common_utils/src/com/android/car/test/utils/TemporaryDirectory.java +++ b/tests/common_utils/src/com/android/car/test/utils/TemporaryDirectory.java @@ -60,6 +60,10 @@ public class TemporaryDirectory implements AutoCloseable { private static final SimpleFileVisitor<Path> DELETE = new DeletingVisitor(); + TemporaryDirectory(Path directory) throws IOException { + mDirectory = Files.createDirectory(directory); + } + public TemporaryDirectory(@Nullable String prefix) throws IOException { if (prefix == null) { prefix = TemporaryDirectory.class.getSimpleName(); @@ -77,4 +81,10 @@ public class TemporaryDirectory implements AutoCloseable { public File getDirectory() { return mDirectory.toFile(); } + + public Path getPath() { return mDirectory; } + + public TemporaryDirectory getSubdirectory(String name) throws IOException { + return new TemporaryDirectory(mDirectory.resolve(name)); + } } diff --git a/tests/common_utils/src/com/android/car/test/utils/TemporaryFile.java b/tests/common_utils/src/com/android/car/test/utils/TemporaryFile.java index 518f4a9b4d..cd0f323223 100644 --- a/tests/common_utils/src/com/android/car/test/utils/TemporaryFile.java +++ b/tests/common_utils/src/com/android/car/test/utils/TemporaryFile.java @@ -46,6 +46,10 @@ public final class TemporaryFile implements AutoCloseable { mFile = File.createTempFile(prefix, String.valueOf(SystemClock.elapsedRealtimeNanos())); } + public TemporaryFile(File path) { + mFile = path; + } + @Override public void close() throws Exception { Files.delete(mFile.toPath()); @@ -57,6 +61,10 @@ public final class TemporaryFile implements AutoCloseable { writer.close(); } + public FileWriter newFileWriter() throws IOException { + return new FileWriter(mFile); + } + public File getFile() { return mFile; } |