1 /*
2  * Copyright (C) 2021 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 
17 package android.car.watchdog;
18 
19 import static com.android.car.internal.ExcludeFromCodeCoverageGeneratedReport.BOILERPLATE_CODE;
20 
21 import android.annotation.NonNull;
22 import android.os.Parcelable;
23 
24 import com.android.car.internal.ExcludeFromCodeCoverageGeneratedReport;
25 import com.android.car.internal.util.AnnotationValidations;
26 import com.android.car.internal.util.DataClass;
27 
28 /**
29  * Disk I/O overuse stats for a package.
30  */
31 @DataClass(genToString = true, genHiddenBuilder = true)
32 public final class IoOveruseStats implements Parcelable {
33     /**
34      * Start time, in epoch seconds, for the below stats.
35      */
36     private long mStartTime;
37 
38     /**
39      * Duration, in seconds, for the below stats.
40      */
41     private long mDurationInSeconds;
42 
43     /**
44      * Total times the package has written to disk beyond the allowed write bytes during the given
45      * period.
46      */
47     private long mTotalOveruses = 0;
48 
49     /**
50      * Total times the package was killed during the given period due to disk I/O overuse.
51      */
52     private long mTotalTimesKilled = 0;
53 
54     /**
55      * Aggregated number of bytes written to disk by the package during the given period.
56      */
57     private long mTotalBytesWritten = 0;
58 
59     /**
60      * Package may be killed on disk I/O overuse.
61      *
62      * <p>Disk I/O overuse is triggered on exceeding {@link #mRemainingWriteBytes}.
63      */
64     private boolean mKillableOnOveruse = false;
65 
66     /**
67      * Number of write bytes remaining in each application or system state.
68      *
69      * <p>On exceeding these limit in at least one system or application state, the package may be
70      * killed if {@link #mKillableOnOveruse} is {@code true}.
71      *
72      * <p>The above period does not apply to this field.
73      */
74     private @NonNull PerStateBytes mRemainingWriteBytes = new PerStateBytes(0L, 0L, 0L);
75 
76 
77 
78     // Code below generated by codegen v1.0.23.
79     //
80     // DO NOT MODIFY!
81     // CHECKSTYLE:OFF Generated code
82     //
83     // To regenerate run:
84     // $ codegen $ANDROID_BUILD_TOP/packages/services/Car/car-lib/src/android/car/watchdog/IoOveruseStats.java
85     // Added AddedInOrBefore or ApiRequirement Annotation manually
86     //
87     // To exclude the generated code from IntelliJ auto-formatting enable (one-time):
88     //   Settings > Editor > Code Style > Formatter Control
89     //@formatter:off
90 
91 
92     @DataClass.Generated.Member
IoOveruseStats( long startTime, long durationInSeconds, long totalOveruses, long totalTimesKilled, long totalBytesWritten, boolean killableOnOveruse, @NonNull PerStateBytes remainingWriteBytes)93     /* package-private */ IoOveruseStats(
94             long startTime,
95             long durationInSeconds,
96             long totalOveruses,
97             long totalTimesKilled,
98             long totalBytesWritten,
99             boolean killableOnOveruse,
100             @NonNull PerStateBytes remainingWriteBytes) {
101         this.mStartTime = startTime;
102         this.mDurationInSeconds = durationInSeconds;
103         this.mTotalOveruses = totalOveruses;
104         this.mTotalTimesKilled = totalTimesKilled;
105         this.mTotalBytesWritten = totalBytesWritten;
106         this.mKillableOnOveruse = killableOnOveruse;
107         this.mRemainingWriteBytes = remainingWriteBytes;
108         AnnotationValidations.validate(
109                 NonNull.class, null, mRemainingWriteBytes);
110 
111         // onConstructed(); // You can define this method to get a callback
112     }
113 
114     /**
115      * Start time, in epoch seconds, for the below stats.
116      */
117     @DataClass.Generated.Member
getStartTime()118     public long getStartTime() {
119         return mStartTime;
120     }
121 
122     /**
123      * Duration, in seconds, for the below stats.
124      */
125     @DataClass.Generated.Member
getDurationInSeconds()126     public long getDurationInSeconds() {
127         return mDurationInSeconds;
128     }
129 
130     /**
131      * Total times the package has written to disk beyond the allowed write bytes during the given
132      * period.
133      */
134     @DataClass.Generated.Member
getTotalOveruses()135     public long getTotalOveruses() {
136         return mTotalOveruses;
137     }
138 
139     /**
140      * Total times the package was killed during the given period due to disk I/O overuse.
141      */
142     @DataClass.Generated.Member
getTotalTimesKilled()143     public long getTotalTimesKilled() {
144         return mTotalTimesKilled;
145     }
146 
147     /**
148      * Aggregated number of bytes written to disk by the package during the given period.
149      */
150     @DataClass.Generated.Member
getTotalBytesWritten()151     public long getTotalBytesWritten() {
152         return mTotalBytesWritten;
153     }
154 
155     /**
156      * Package may be killed on disk I/O overuse.
157      *
158      * <p>Disk I/O overuse is triggered on exceeding {@link #getRemainingWriteBytes()}.
159      */
160     @DataClass.Generated.Member
isKillableOnOveruse()161     public boolean isKillableOnOveruse() {
162         return mKillableOnOveruse;
163     }
164 
165     /**
166      * Number of write bytes remaining in each application or system state.
167      *
168      * <p>On exceeding these limit in at least one system or application state, the package may be
169      * killed if {@link #isKillableOnOveruse()} is {@code true}.
170      *
171      * <p>The above period does not apply to this field.
172      */
173     @DataClass.Generated.Member
getRemainingWriteBytes()174     public @NonNull PerStateBytes getRemainingWriteBytes() {
175         return mRemainingWriteBytes;
176     }
177 
178     @Override
179     @DataClass.Generated.Member
toString()180     public String toString() {
181         // You can override field toString logic by defining methods like:
182         // String fieldNameToString() { ... }
183 
184         return "IoOveruseStats { " +
185                 "startTime = " + mStartTime + ", " +
186                 "durationInSeconds = " + mDurationInSeconds + ", " +
187                 "totalOveruses = " + mTotalOveruses + ", " +
188                 "totalTimesKilled = " + mTotalTimesKilled + ", " +
189                 "totalBytesWritten = " + mTotalBytesWritten + ", " +
190                 "killableOnOveruse = " + mKillableOnOveruse + ", " +
191                 "remainingWriteBytes = " + mRemainingWriteBytes +
192         " }";
193     }
194 
195     @Override
196     @DataClass.Generated.Member
writeToParcel(@onNull android.os.Parcel dest, int flags)197     public void writeToParcel(@NonNull android.os.Parcel dest, int flags) {
198         // You can override field parcelling by defining methods like:
199         // void parcelFieldName(Parcel dest, int flags) { ... }
200 
201         byte flg = 0;
202         if (mKillableOnOveruse) flg |= 0x20;
203         dest.writeByte(flg);
204         dest.writeLong(mStartTime);
205         dest.writeLong(mDurationInSeconds);
206         dest.writeLong(mTotalOveruses);
207         dest.writeLong(mTotalTimesKilled);
208         dest.writeLong(mTotalBytesWritten);
209         dest.writeTypedObject(mRemainingWriteBytes, flags);
210     }
211 
212     @Override
213     @DataClass.Generated.Member
214     @ExcludeFromCodeCoverageGeneratedReport(reason = BOILERPLATE_CODE)
describeContents()215     public int describeContents() { return 0; }
216 
217     /** @hide */
218     @SuppressWarnings({"unchecked", "RedundantCast"})
219     @DataClass.Generated.Member
IoOveruseStats(@onNull android.os.Parcel in)220     /* package-private */ IoOveruseStats(@NonNull android.os.Parcel in) {
221         // You can override field unparcelling by defining methods like:
222         // static FieldType unparcelFieldName(Parcel in) { ... }
223 
224         byte flg = in.readByte();
225         boolean killableOnOveruse = (flg & 0x20) != 0;
226         long startTime = in.readLong();
227         long durationInSeconds = in.readLong();
228         long totalOveruses = in.readLong();
229         long totalTimesKilled = in.readLong();
230         long totalBytesWritten = in.readLong();
231         PerStateBytes remainingWriteBytes = (PerStateBytes) in.readTypedObject(PerStateBytes.CREATOR);
232 
233         this.mStartTime = startTime;
234         this.mDurationInSeconds = durationInSeconds;
235         this.mTotalOveruses = totalOveruses;
236         this.mTotalTimesKilled = totalTimesKilled;
237         this.mTotalBytesWritten = totalBytesWritten;
238         this.mKillableOnOveruse = killableOnOveruse;
239         this.mRemainingWriteBytes = remainingWriteBytes;
240         AnnotationValidations.validate(
241                 NonNull.class, null, mRemainingWriteBytes);
242 
243         // onConstructed(); // You can define this method to get a callback
244     }
245 
246     @DataClass.Generated.Member
247     public static final @NonNull Parcelable.Creator<IoOveruseStats> CREATOR
248             = new Parcelable.Creator<IoOveruseStats>() {
249         @Override
250         public IoOveruseStats[] newArray(int size) {
251             return new IoOveruseStats[size];
252         }
253 
254         @Override
255         public IoOveruseStats createFromParcel(@NonNull android.os.Parcel in) {
256             return new IoOveruseStats(in);
257         }
258     };
259 
260     /**
261      * A builder for {@link IoOveruseStats}
262      * @hide
263      */
264     @SuppressWarnings("WeakerAccess")
265     @DataClass.Generated.Member
266     public static final class Builder {
267 
268         private long mStartTime;
269         private long mDurationInSeconds;
270         private long mTotalOveruses;
271         private long mTotalTimesKilled;
272         private long mTotalBytesWritten;
273         private boolean mKillableOnOveruse;
274         private @NonNull PerStateBytes mRemainingWriteBytes;
275 
276         private long mBuilderFieldsSet = 0L;
277 
278         /**
279          * Creates a new Builder.
280          *
281          * @param startTime
282          *   Start time, in epoch seconds, for the below stats.
283          * @param durationInSeconds
284          *   Duration, in seconds, for the below stats.
285          */
Builder( long startTime, long durationInSeconds)286         public Builder(
287                 long startTime,
288                 long durationInSeconds) {
289             mStartTime = startTime;
290             mDurationInSeconds = durationInSeconds;
291         }
292 
293         /**
294          * Start time, in epoch seconds, for the below stats.
295          */
296         @DataClass.Generated.Member
setStartTime(long value)297         public @NonNull Builder setStartTime(long value) {
298             checkNotUsed();
299             mBuilderFieldsSet |= 0x1;
300             mStartTime = value;
301             return this;
302         }
303 
304         /**
305          * Duration, in seconds, for the below stats.
306          */
307         @DataClass.Generated.Member
setDurationInSeconds(long value)308         public @NonNull Builder setDurationInSeconds(long value) {
309             checkNotUsed();
310             mBuilderFieldsSet |= 0x2;
311             mDurationInSeconds = value;
312             return this;
313         }
314 
315         /**
316          * Total times the package has written to disk beyond the allowed write bytes during the given
317          * period.
318          */
319         @DataClass.Generated.Member
setTotalOveruses(long value)320         public @NonNull Builder setTotalOveruses(long value) {
321             checkNotUsed();
322             mBuilderFieldsSet |= 0x4;
323             mTotalOveruses = value;
324             return this;
325         }
326 
327         /**
328          * Total times the package was killed during the given period due to disk I/O overuse.
329          */
330         @DataClass.Generated.Member
setTotalTimesKilled(long value)331         public @NonNull Builder setTotalTimesKilled(long value) {
332             checkNotUsed();
333             mBuilderFieldsSet |= 0x8;
334             mTotalTimesKilled = value;
335             return this;
336         }
337 
338         /**
339          * Aggregated number of bytes written to disk by the package during the given period.
340          */
341         @DataClass.Generated.Member
setTotalBytesWritten(long value)342         public @NonNull Builder setTotalBytesWritten(long value) {
343             checkNotUsed();
344             mBuilderFieldsSet |= 0x10;
345             mTotalBytesWritten = value;
346             return this;
347         }
348 
349         /**
350          * Package may be killed on disk I/O overuse.
351          *
352          * <p>Disk I/O overuse is triggered on exceeding {@link #mRemainingWriteBytes}.
353          */
354         @DataClass.Generated.Member
setKillableOnOveruse(boolean value)355         public @NonNull Builder setKillableOnOveruse(boolean value) {
356             checkNotUsed();
357             mBuilderFieldsSet |= 0x20;
358             mKillableOnOveruse = value;
359             return this;
360         }
361 
362         /**
363          * Number of write bytes remaining in each application or system state.
364          *
365          * <p>On exceeding these limit in at least one system or application state, the package may be
366          * killed if {@link #mKillableOnOveruse} is {@code true}.
367          *
368          * <p>The above period does not apply to this field.
369          */
370         @DataClass.Generated.Member
setRemainingWriteBytes(@onNull PerStateBytes value)371         public @NonNull Builder setRemainingWriteBytes(@NonNull PerStateBytes value) {
372             checkNotUsed();
373             mBuilderFieldsSet |= 0x40;
374             mRemainingWriteBytes = value;
375             return this;
376         }
377 
378         /** Builds the instance. This builder should not be touched after calling this! */
build()379         public @NonNull IoOveruseStats build() {
380             checkNotUsed();
381             mBuilderFieldsSet |= 0x80; // Mark builder used
382 
383             if ((mBuilderFieldsSet & 0x4) == 0) {
384                 mTotalOveruses = 0;
385             }
386             if ((mBuilderFieldsSet & 0x8) == 0) {
387                 mTotalTimesKilled = 0;
388             }
389             if ((mBuilderFieldsSet & 0x10) == 0) {
390                 mTotalBytesWritten = 0;
391             }
392             if ((mBuilderFieldsSet & 0x20) == 0) {
393                 mKillableOnOveruse = false;
394             }
395             if ((mBuilderFieldsSet & 0x40) == 0) {
396                 mRemainingWriteBytes = new PerStateBytes(0L, 0L, 0L);
397             }
398             IoOveruseStats o = new IoOveruseStats(
399                     mStartTime,
400                     mDurationInSeconds,
401                     mTotalOveruses,
402                     mTotalTimesKilled,
403                     mTotalBytesWritten,
404                     mKillableOnOveruse,
405                     mRemainingWriteBytes);
406             return o;
407         }
408 
checkNotUsed()409         private void checkNotUsed() {
410             if ((mBuilderFieldsSet & 0x80) != 0) {
411                 throw new IllegalStateException(
412                         "This Builder should not be reused. Use a new Builder instance instead");
413             }
414         }
415     }
416 
417     @DataClass.Generated(
418             time = 1628099298965L,
419             codegenVersion = "1.0.23",
420             sourceFile = "packages/services/Car/car-lib/src/android/car/watchdog/IoOveruseStats.java",
421             inputSignatures = "private  long mStartTime\nprivate  long mDurationInSeconds\nprivate  long mTotalOveruses\nprivate  long mTotalTimesKilled\nprivate  long mTotalBytesWritten\nprivate  boolean mKillableOnOveruse\nprivate @android.annotation.NonNull android.car.watchdog.PerStateBytes mRemainingWriteBytes\nclass IoOveruseStats extends java.lang.Object implements [android.os.Parcelable]\n@com.android.car.internal.util.DataClass(genToString=true, genHiddenBuilder=true)")
422     @Deprecated
423     @ExcludeFromCodeCoverageGeneratedReport(reason = BOILERPLATE_CODE)
__metadata()424     private void __metadata() {}
425 
426 
427     //@formatter:on
428     // End of generated code
429 
430 }
431