Home | History | Annotate | Download | only in storagemonitoring
      1 /*
      2  * Copyright (C) 2017 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 package android.car.storagemonitoring;
     17 
     18 import android.annotation.SystemApi;
     19 
     20 /**
     21  * Record of data as extracted from /proc/uid_io/stats
     22  *
     23  * @hide
     24  */
     25 @SystemApi
     26 public final class UidIoRecord {
     27 
     28     public final int uid;
     29 
     30     public final long foreground_rchar;
     31     public final long foreground_wchar;
     32     public final long foreground_read_bytes;
     33     public final long foreground_write_bytes;
     34     public final long foreground_fsync;
     35 
     36     public final long background_rchar;
     37     public final long background_wchar;
     38     public final long background_read_bytes;
     39     public final long background_write_bytes;
     40     public final long background_fsync;
     41 
     42     public UidIoRecord(int uid,
     43             long foreground_rchar,
     44             long foreground_wchar,
     45             long foreground_read_bytes,
     46             long foreground_write_bytes,
     47             long foreground_fsync,
     48             long background_rchar,
     49             long background_wchar,
     50             long background_read_bytes,
     51             long background_write_bytes,
     52             long background_fsync) {
     53         this.uid = uid;
     54 
     55         this.foreground_rchar = foreground_rchar;
     56         this.foreground_wchar = foreground_wchar;
     57         this.foreground_read_bytes = foreground_read_bytes;
     58         this.foreground_write_bytes = foreground_write_bytes;
     59         this.foreground_fsync = foreground_fsync;
     60 
     61         this.background_rchar = background_rchar;
     62         this.background_wchar = background_wchar;
     63         this.background_read_bytes = background_read_bytes;
     64         this.background_write_bytes = background_write_bytes;
     65         this.background_fsync = background_fsync;
     66     }
     67 
     68     /** @hide */
     69     public UidIoRecord delta(IoStatsEntry other) {
     70         if (uid != other.uid) {
     71             throw new IllegalArgumentException("cannot calculate delta between different user IDs");
     72         }
     73 
     74         return new UidIoRecord(uid,
     75             foreground_rchar - other.foreground.bytesRead,
     76             foreground_wchar - other.foreground.bytesWritten,
     77             foreground_read_bytes - other.foreground.bytesReadFromStorage,
     78             foreground_write_bytes - other.foreground.bytesWrittenToStorage,
     79             foreground_fsync - other.foreground.fsyncCalls,
     80             background_rchar - other.background.bytesRead,
     81             background_wchar - other.background.bytesWritten,
     82             background_read_bytes - other.background.bytesReadFromStorage,
     83             background_write_bytes - other.background.bytesWrittenToStorage,
     84             background_fsync - other.background.fsyncCalls);
     85     }
     86 
     87     /** @hide */
     88     public UidIoRecord delta(UidIoRecord other) {
     89         if (uid != other.uid) {
     90             throw new IllegalArgumentException("cannot calculate delta between different user IDs");
     91         }
     92 
     93         return new UidIoRecord(uid,
     94             foreground_rchar - other.foreground_rchar,
     95             foreground_wchar - other.foreground_wchar,
     96             foreground_read_bytes - other.foreground_read_bytes,
     97             foreground_write_bytes - other.foreground_write_bytes,
     98             foreground_fsync - other.foreground_fsync,
     99             background_rchar - other.background_rchar,
    100             background_wchar - other.background_wchar,
    101             background_read_bytes - other.background_read_bytes,
    102             background_write_bytes - other.background_write_bytes,
    103             background_fsync - other.background_fsync);
    104     }
    105 }
    106