forked from LineageOS/android_frameworks_base
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDebug.java
More file actions
2917 lines (2688 loc) · 109 KB
/
Copy pathDebug.java
File metadata and controls
2917 lines (2688 loc) · 109 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (C) 2007 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.os;
import android.annotation.FlaggedApi;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.app.AppGlobals;
import android.compat.annotation.UnsupportedAppUsage;
import android.content.Context;
import android.graphics.Bitmap;
import android.util.Log;
import com.android.internal.util.FastPrintWriter;
import com.android.internal.util.Preconditions;
import com.android.internal.util.TypedProperties;
import dalvik.annotation.optimization.CriticalNative;
import dalvik.system.VMDebug;
import org.apache.harmony.dalvik.ddmc.Chunk;
import org.apache.harmony.dalvik.ddmc.ChunkHandler;
import org.apache.harmony.dalvik.ddmc.DdmServer;
import java.io.File;
import java.io.FileDescriptor;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.Reader;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Provides various debugging methods for Android applications, including
* tracing and allocation counts.
* <p><strong>Logging Trace Files</strong></p>
* <p>Debug can create log files that give details about an application, such as
* a call stack and start/stop times for any running methods. See <a
* href="{@docRoot}studio/profile/traceview.html">Inspect Trace Logs with
* Traceview</a> for information about reading trace files. To start logging
* trace files, call one of the startMethodTracing() methods. To stop tracing,
* call {@link #stopMethodTracing()}.
*/
public final class Debug
{
private static final String TAG = "Debug";
/**
* Flags for startMethodTracing(). These can be ORed together.
*
* TRACE_COUNT_ALLOCS adds the results from startAllocCounting to the
* trace key file.
*
* @deprecated Accurate counting is a burden on the runtime and may be removed.
*/
// This must match VMDebug.TRACE_COUNT_ALLOCS.
@Deprecated
public static final int TRACE_COUNT_ALLOCS = 1;
/**
* Flags for printLoadedClasses(). Default behavior is to only show
* the class name.
*/
public static final int SHOW_FULL_DETAIL = 1;
public static final int SHOW_CLASSLOADER = (1 << 1);
public static final int SHOW_INITIALIZED = (1 << 2);
// set/cleared by waitForDebugger()
private static volatile boolean mWaiting = false;
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
private Debug() {}
/*
* How long to wait for the debugger to finish sending requests. I've
* seen this hit 800msec on the device while waiting for a response
* to travel over USB and get processed, so we take that and add
* half a second.
*/
private static final int MIN_DEBUGGER_IDLE = 1300; // msec
/* how long to sleep when polling for activity */
private static final int SPIN_DELAY = 200; // msec
/**
* Default trace file path and file
*/
private static final String DEFAULT_TRACE_BODY = "dmtrace";
private static final String DEFAULT_TRACE_EXTENSION = ".trace";
private static final String[] FRAMEWORK_FEATURES = new String[] {
"opengl-tracing",
"view-hierarchy",
"support_boot_stages",
"app_info",
};
/*
* Default return value for getInstanceCounts methods.
*/
private static final long[] EMPTY_COUNT_CLASS_INSTANCES = new long[0];
/**
* This class is used to retrieved various statistics about the memory mappings for this
* process. The returned info is broken down by dalvik, native, and other. All results are in kB.
*/
public static class MemoryInfo implements Parcelable {
/** The proportional set size for dalvik heap. (Doesn't include other Dalvik overhead.) */
public int dalvikPss;
/** The proportional set size that is swappable for dalvik heap. */
/** @hide We may want to expose this, eventually. */
@UnsupportedAppUsage
public int dalvikSwappablePss;
/** @hide The resident set size for dalvik heap. (Without other Dalvik overhead.) */
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
public int dalvikRss;
/** The private dirty pages used by dalvik heap. */
public int dalvikPrivateDirty;
/** The shared dirty pages used by dalvik heap. */
public int dalvikSharedDirty;
/** The private clean pages used by dalvik heap. */
/** @hide We may want to expose this, eventually. */
@UnsupportedAppUsage
public int dalvikPrivateClean;
/** The shared clean pages used by dalvik heap. */
/** @hide We may want to expose this, eventually. */
@UnsupportedAppUsage
public int dalvikSharedClean;
/** The dirty dalvik pages that have been swapped out. */
/** @hide We may want to expose this, eventually. */
@UnsupportedAppUsage
public int dalvikSwappedOut;
/** The dirty dalvik pages that have been swapped out, proportional. */
/** @hide We may want to expose this, eventually. */
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
public int dalvikSwappedOutPss;
/** The proportional set size for the native heap. */
public int nativePss;
/** The proportional set size that is swappable for the native heap. */
/** @hide We may want to expose this, eventually. */
@UnsupportedAppUsage
public int nativeSwappablePss;
/** @hide The resident set size for the native heap. */
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
public int nativeRss;
/** The private dirty pages used by the native heap. */
public int nativePrivateDirty;
/** The shared dirty pages used by the native heap. */
public int nativeSharedDirty;
/** The private clean pages used by the native heap. */
/** @hide We may want to expose this, eventually. */
@UnsupportedAppUsage
public int nativePrivateClean;
/** The shared clean pages used by the native heap. */
/** @hide We may want to expose this, eventually. */
@UnsupportedAppUsage
public int nativeSharedClean;
/** The dirty native pages that have been swapped out. */
/** @hide We may want to expose this, eventually. */
@UnsupportedAppUsage
public int nativeSwappedOut;
/** The dirty native pages that have been swapped out, proportional. */
/** @hide We may want to expose this, eventually. */
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
public int nativeSwappedOutPss;
/** The proportional set size for everything else. */
public int otherPss;
/** The proportional set size that is swappable for everything else. */
/** @hide We may want to expose this, eventually. */
@UnsupportedAppUsage
public int otherSwappablePss;
/** @hide The resident set size for everything else. */
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
public int otherRss;
/** The private dirty pages used by everything else. */
public int otherPrivateDirty;
/** The shared dirty pages used by everything else. */
public int otherSharedDirty;
/** The private clean pages used by everything else. */
/** @hide We may want to expose this, eventually. */
@UnsupportedAppUsage
public int otherPrivateClean;
/** The shared clean pages used by everything else. */
/** @hide We may want to expose this, eventually. */
@UnsupportedAppUsage
public int otherSharedClean;
/** The dirty pages used by anyting else that have been swapped out. */
/** @hide We may want to expose this, eventually. */
@UnsupportedAppUsage
public int otherSwappedOut;
/** The dirty pages used by anyting else that have been swapped out, proportional. */
/** @hide We may want to expose this, eventually. */
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
public int otherSwappedOutPss;
/** Whether the kernel reports proportional swap usage */
/** @hide */
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
public boolean hasSwappedOutPss;
// LINT.IfChange
/** @hide */
public static final int HEAP_UNKNOWN = 0;
/** @hide */
public static final int HEAP_DALVIK = 1;
/** @hide */
public static final int HEAP_NATIVE = 2;
/** @hide */
public static final int OTHER_DALVIK_OTHER = 0;
/** @hide */
public static final int OTHER_STACK = 1;
/** @hide */
public static final int OTHER_CURSOR = 2;
/** @hide */
public static final int OTHER_ASHMEM = 3;
/** @hide */
public static final int OTHER_GL_DEV = 4;
/** @hide */
public static final int OTHER_UNKNOWN_DEV = 5;
/** @hide */
public static final int OTHER_SO = 6;
/** @hide */
public static final int OTHER_JAR = 7;
/** @hide */
public static final int OTHER_APK = 8;
/** @hide */
public static final int OTHER_TTF = 9;
/** @hide */
public static final int OTHER_DEX = 10;
/** @hide */
public static final int OTHER_OAT = 11;
/** @hide */
public static final int OTHER_ART = 12;
/** @hide */
public static final int OTHER_UNKNOWN_MAP = 13;
/** @hide */
public static final int OTHER_GRAPHICS = 14;
/** @hide */
public static final int OTHER_GL = 15;
/** @hide */
public static final int OTHER_OTHER_MEMTRACK = 16;
// Needs to be declared here for the DVK_STAT ranges below.
/** @hide */
@UnsupportedAppUsage
public static final int NUM_OTHER_STATS = 17;
// Dalvik subsections.
/** @hide */
public static final int OTHER_DALVIK_NORMAL = 17;
/** @hide */
public static final int OTHER_DALVIK_LARGE = 18;
/** @hide */
public static final int OTHER_DALVIK_ZYGOTE = 19;
/** @hide */
public static final int OTHER_DALVIK_NON_MOVING = 20;
// Section begins and ends for dumpsys, relative to the DALVIK categories.
/** @hide */
public static final int OTHER_DVK_STAT_DALVIK_START =
OTHER_DALVIK_NORMAL - NUM_OTHER_STATS;
/** @hide */
public static final int OTHER_DVK_STAT_DALVIK_END =
OTHER_DALVIK_NON_MOVING - NUM_OTHER_STATS;
// Dalvik Other subsections.
/** @hide */
public static final int OTHER_DALVIK_OTHER_LINEARALLOC = 21;
/** @hide */
public static final int OTHER_DALVIK_OTHER_ACCOUNTING = 22;
/** @hide */
public static final int OTHER_DALVIK_OTHER_ZYGOTE_CODE_CACHE = 23;
/** @hide */
public static final int OTHER_DALVIK_OTHER_APP_CODE_CACHE = 24;
/** @hide */
public static final int OTHER_DALVIK_OTHER_COMPILER_METADATA = 25;
/** @hide */
public static final int OTHER_DALVIK_OTHER_INDIRECT_REFERENCE_TABLE = 26;
/** @hide */
public static final int OTHER_DVK_STAT_DALVIK_OTHER_START =
OTHER_DALVIK_OTHER_LINEARALLOC - NUM_OTHER_STATS;
/** @hide */
public static final int OTHER_DVK_STAT_DALVIK_OTHER_END =
OTHER_DALVIK_OTHER_INDIRECT_REFERENCE_TABLE - NUM_OTHER_STATS;
// Dex subsections (Boot vdex, App dex, and App vdex).
/** @hide */
public static final int OTHER_DEX_BOOT_VDEX = 27;
/** @hide */
public static final int OTHER_DEX_APP_DEX = 28;
/** @hide */
public static final int OTHER_DEX_APP_VDEX = 29;
/** @hide */
public static final int OTHER_DVK_STAT_DEX_START = OTHER_DEX_BOOT_VDEX - NUM_OTHER_STATS;
/** @hide */
public static final int OTHER_DVK_STAT_DEX_END = OTHER_DEX_APP_VDEX - NUM_OTHER_STATS;
// Art subsections (App image, boot image).
/** @hide */
public static final int OTHER_ART_APP = 30;
/** @hide */
public static final int OTHER_ART_BOOT = 31;
// LINT.ThenChange(/system/memory/libmeminfo/include/meminfo/androidprocheaps.h)
/** @hide */
public static final int OTHER_DVK_STAT_ART_START = OTHER_ART_APP - NUM_OTHER_STATS;
/** @hide */
public static final int OTHER_DVK_STAT_ART_END = OTHER_ART_BOOT - NUM_OTHER_STATS;
/** @hide */
@UnsupportedAppUsage
public static final int NUM_DVK_STATS = OTHER_ART_BOOT + 1 - OTHER_DALVIK_NORMAL;
/** @hide */
public static final int NUM_CATEGORIES = 9;
/** @hide */
public static final int OFFSET_PSS = 0;
/** @hide */
public static final int OFFSET_SWAPPABLE_PSS = 1;
/** @hide */
public static final int OFFSET_RSS = 2;
/** @hide */
public static final int OFFSET_PRIVATE_DIRTY = 3;
/** @hide */
public static final int OFFSET_SHARED_DIRTY = 4;
/** @hide */
public static final int OFFSET_PRIVATE_CLEAN = 5;
/** @hide */
public static final int OFFSET_SHARED_CLEAN = 6;
/** @hide */
public static final int OFFSET_SWAPPED_OUT = 7;
/** @hide */
public static final int OFFSET_SWAPPED_OUT_PSS = 8;
@UnsupportedAppUsage
private int[] otherStats = new int[(NUM_OTHER_STATS+NUM_DVK_STATS)*NUM_CATEGORIES];
public MemoryInfo() {
}
/**
* @hide Copy contents from another object.
*/
public void set(MemoryInfo other) {
dalvikPss = other.dalvikPss;
dalvikSwappablePss = other.dalvikSwappablePss;
dalvikRss = other.dalvikRss;
dalvikPrivateDirty = other.dalvikPrivateDirty;
dalvikSharedDirty = other.dalvikSharedDirty;
dalvikPrivateClean = other.dalvikPrivateClean;
dalvikSharedClean = other.dalvikSharedClean;
dalvikSwappedOut = other.dalvikSwappedOut;
dalvikSwappedOutPss = other.dalvikSwappedOutPss;
nativePss = other.nativePss;
nativeSwappablePss = other.nativeSwappablePss;
nativeRss = other.nativeRss;
nativePrivateDirty = other.nativePrivateDirty;
nativeSharedDirty = other.nativeSharedDirty;
nativePrivateClean = other.nativePrivateClean;
nativeSharedClean = other.nativeSharedClean;
nativeSwappedOut = other.nativeSwappedOut;
nativeSwappedOutPss = other.nativeSwappedOutPss;
otherPss = other.otherPss;
otherSwappablePss = other.otherSwappablePss;
otherRss = other.otherRss;
otherPrivateDirty = other.otherPrivateDirty;
otherSharedDirty = other.otherSharedDirty;
otherPrivateClean = other.otherPrivateClean;
otherSharedClean = other.otherSharedClean;
otherSwappedOut = other.otherSwappedOut;
otherSwappedOutPss = other.otherSwappedOutPss;
hasSwappedOutPss = other.hasSwappedOutPss;
System.arraycopy(other.otherStats, 0, otherStats, 0, otherStats.length);
}
/**
* Return total PSS memory usage in kB.
*/
public int getTotalPss() {
return dalvikPss + nativePss + otherPss + getTotalSwappedOutPss();
}
/**
* @hide Return total PSS memory usage in kB.
*/
@UnsupportedAppUsage
public int getTotalUss() {
return dalvikPrivateClean + dalvikPrivateDirty
+ nativePrivateClean + nativePrivateDirty
+ otherPrivateClean + otherPrivateDirty;
}
/**
* Return total PSS memory usage in kB mapping a file of one of the following extension:
* .so, .jar, .apk, .ttf, .dex, .odex, .oat, .art .
*/
public int getTotalSwappablePss() {
return dalvikSwappablePss + nativeSwappablePss + otherSwappablePss;
}
/**
* @hide Return total RSS memory usage in kB.
*/
public int getTotalRss() {
return dalvikRss + nativeRss + otherRss;
}
/**
* Return total private dirty memory usage in kB.
*/
public int getTotalPrivateDirty() {
return dalvikPrivateDirty + nativePrivateDirty + otherPrivateDirty;
}
/**
* Return total shared dirty memory usage in kB.
*/
public int getTotalSharedDirty() {
return dalvikSharedDirty + nativeSharedDirty + otherSharedDirty;
}
/**
* Return total shared clean memory usage in kB.
*/
public int getTotalPrivateClean() {
return dalvikPrivateClean + nativePrivateClean + otherPrivateClean;
}
/**
* Return total shared clean memory usage in kB.
*/
public int getTotalSharedClean() {
return dalvikSharedClean + nativeSharedClean + otherSharedClean;
}
/**
* Return total swapped out memory in kB.
* @hide
*/
public int getTotalSwappedOut() {
return dalvikSwappedOut + nativeSwappedOut + otherSwappedOut;
}
/**
* Return total swapped out memory in kB, proportional.
* @hide
*/
public int getTotalSwappedOutPss() {
return dalvikSwappedOutPss + nativeSwappedOutPss + otherSwappedOutPss;
}
/** @hide */
@UnsupportedAppUsage
public int getOtherPss(int which) {
return otherStats[which * NUM_CATEGORIES + OFFSET_PSS];
}
/** @hide */
public int getOtherSwappablePss(int which) {
return otherStats[which * NUM_CATEGORIES + OFFSET_SWAPPABLE_PSS];
}
/** @hide */
public int getOtherRss(int which) {
return otherStats[which * NUM_CATEGORIES + OFFSET_RSS];
}
/** @hide */
@UnsupportedAppUsage
public int getOtherPrivateDirty(int which) {
return otherStats[which * NUM_CATEGORIES + OFFSET_PRIVATE_DIRTY];
}
/** @hide */
@UnsupportedAppUsage
public int getOtherSharedDirty(int which) {
return otherStats[which * NUM_CATEGORIES + OFFSET_SHARED_DIRTY];
}
/** @hide */
public int getOtherPrivateClean(int which) {
return otherStats[which * NUM_CATEGORIES + OFFSET_PRIVATE_CLEAN];
}
/** @hide */
@UnsupportedAppUsage
public int getOtherPrivate(int which) {
return getOtherPrivateClean(which) + getOtherPrivateDirty(which);
}
/** @hide */
public int getOtherSharedClean(int which) {
return otherStats[which * NUM_CATEGORIES + OFFSET_SHARED_CLEAN];
}
/** @hide */
public int getOtherSwappedOut(int which) {
return otherStats[which * NUM_CATEGORIES + OFFSET_SWAPPED_OUT];
}
/** @hide */
public int getOtherSwappedOutPss(int which) {
return otherStats[which * NUM_CATEGORIES + OFFSET_SWAPPED_OUT_PSS];
}
/** @hide */
@UnsupportedAppUsage
public static String getOtherLabel(int which) {
switch (which) {
case OTHER_DALVIK_OTHER: return "Dalvik Other";
case OTHER_STACK: return "Stack";
case OTHER_CURSOR: return "Cursor";
case OTHER_ASHMEM: return "Ashmem";
case OTHER_GL_DEV: return "Gfx dev";
case OTHER_UNKNOWN_DEV: return "Other dev";
case OTHER_SO: return ".so mmap";
case OTHER_JAR: return ".jar mmap";
case OTHER_APK: return ".apk mmap";
case OTHER_TTF: return ".ttf mmap";
case OTHER_DEX: return ".dex mmap";
case OTHER_OAT: return ".oat mmap";
case OTHER_ART: return ".art mmap";
case OTHER_UNKNOWN_MAP: return "Other mmap";
case OTHER_GRAPHICS: return "EGL mtrack";
case OTHER_GL: return "GL mtrack";
case OTHER_OTHER_MEMTRACK: return "Other mtrack";
case OTHER_DALVIK_NORMAL: return ".Heap";
case OTHER_DALVIK_LARGE: return ".LOS";
case OTHER_DALVIK_ZYGOTE: return ".Zygote";
case OTHER_DALVIK_NON_MOVING: return ".NonMoving";
case OTHER_DALVIK_OTHER_LINEARALLOC: return ".LinearAlloc";
case OTHER_DALVIK_OTHER_ACCOUNTING: return ".GC";
case OTHER_DALVIK_OTHER_ZYGOTE_CODE_CACHE: return ".ZygoteJIT";
case OTHER_DALVIK_OTHER_APP_CODE_CACHE: return ".AppJIT";
case OTHER_DALVIK_OTHER_COMPILER_METADATA: return ".CompilerMetadata";
case OTHER_DALVIK_OTHER_INDIRECT_REFERENCE_TABLE: return ".IndirectRef";
case OTHER_DEX_BOOT_VDEX: return ".Boot vdex";
case OTHER_DEX_APP_DEX: return ".App dex";
case OTHER_DEX_APP_VDEX: return ".App vdex";
case OTHER_ART_APP: return ".App art";
case OTHER_ART_BOOT: return ".Boot art";
default: return "????";
}
}
/**
* Returns the value of a particular memory statistic or {@code null} if no
* such memory statistic exists.
*
* <p>The following table lists the memory statistics that are supported.
* Note that memory statistics may be added or removed in a future API level.</p>
*
* <table>
* <thead>
* <tr>
* <th>Memory statistic name</th>
* <th>Meaning</th>
* <th>Example</th>
* <th>Supported (API Levels)</th>
* </tr>
* </thead>
* <tbody>
* <tr>
* <td>summary.java-heap</td>
* <td>The private Java Heap usage in kB. This corresponds to the Java Heap field
* in the App Summary section output by dumpsys meminfo.</td>
* <td>{@code 1442}</td>
* <td>23</td>
* </tr>
* <tr>
* <td>summary.native-heap</td>
* <td>The private Native Heap usage in kB. This corresponds to the Native Heap
* field in the App Summary section output by dumpsys meminfo.</td>
* <td>{@code 1442}</td>
* <td>23</td>
* </tr>
* <tr>
* <td>summary.code</td>
* <td>The memory usage for static code and resources in kB. This corresponds to
* the Code field in the App Summary section output by dumpsys meminfo.</td>
* <td>{@code 1442}</td>
* <td>23</td>
* </tr>
* <tr>
* <td>summary.stack</td>
* <td>The stack usage in kB. This corresponds to the Stack field in the
* App Summary section output by dumpsys meminfo.</td>
* <td>{@code 1442}</td>
* <td>23</td>
* </tr>
* <tr>
* <td>summary.graphics</td>
* <td>The graphics usage in kB. This corresponds to the Graphics field in the
* App Summary section output by dumpsys meminfo.</td>
* <td>{@code 1442}</td>
* <td>23</td>
* </tr>
* <tr>
* <td>summary.private-other</td>
* <td>Other private memory usage in kB. This corresponds to the Private Other
* field output in the App Summary section by dumpsys meminfo.</td>
* <td>{@code 1442}</td>
* <td>23</td>
* </tr>
* <tr>
* <td>summary.system</td>
* <td>Shared and system memory usage in kB. This corresponds to the System
* field output in the App Summary section by dumpsys meminfo.</td>
* <td>{@code 1442}</td>
* <td>23</td>
* </tr>
* <tr>
* <td>summary.total-pss</td>
* <td>Total PSS memory usage in kB.</td>
* <td>{@code 1442}</td>
* <td>23</td>
* </tr>
* <tr>
* <td>summary.total-swap</td>
* <td>Total swap usage in kB.</td>
* <td>{@code 1442}</td>
* <td>23</td>
* </tr>
* </tbody>
* </table>
*/
public String getMemoryStat(String statName) {
switch(statName) {
case "summary.java-heap":
return Integer.toString(getSummaryJavaHeap());
case "summary.native-heap":
return Integer.toString(getSummaryNativeHeap());
case "summary.code":
return Integer.toString(getSummaryCode());
case "summary.stack":
return Integer.toString(getSummaryStack());
case "summary.graphics":
return Integer.toString(getSummaryGraphics());
case "summary.private-other":
return Integer.toString(getSummaryPrivateOther());
case "summary.system":
return Integer.toString(getSummarySystem());
case "summary.total-pss":
return Integer.toString(getSummaryTotalPss());
case "summary.total-swap":
return Integer.toString(getSummaryTotalSwap());
default:
return null;
}
}
/**
* Returns a map of the names/values of the memory statistics
* that {@link #getMemoryStat(String)} supports.
*
* @return a map of the names/values of the supported memory statistics.
*/
public Map<String, String> getMemoryStats() {
Map<String, String> stats = new HashMap<String, String>();
stats.put("summary.java-heap", Integer.toString(getSummaryJavaHeap()));
stats.put("summary.native-heap", Integer.toString(getSummaryNativeHeap()));
stats.put("summary.code", Integer.toString(getSummaryCode()));
stats.put("summary.stack", Integer.toString(getSummaryStack()));
stats.put("summary.graphics", Integer.toString(getSummaryGraphics()));
stats.put("summary.private-other", Integer.toString(getSummaryPrivateOther()));
stats.put("summary.system", Integer.toString(getSummarySystem()));
stats.put("summary.total-pss", Integer.toString(getSummaryTotalPss()));
stats.put("summary.total-swap", Integer.toString(getSummaryTotalSwap()));
return stats;
}
/**
* Pss of Java Heap bytes in KB due to the application.
* Notes:
* * OTHER_ART is the boot image. Anything private here is blamed on
* the application, not the system.
* * dalvikPrivateDirty includes private zygote, which means the
* application dirtied something allocated by the zygote. We blame
* the application for that memory, not the system.
* * Does not include OTHER_DALVIK_OTHER, which is considered VM
* Overhead and lumped into Private Other.
* * We don't include dalvikPrivateClean, because there should be no
* such thing as private clean for the Java Heap.
* @hide
*/
@UnsupportedAppUsage
public int getSummaryJavaHeap() {
return dalvikPrivateDirty + getOtherPrivate(OTHER_ART);
}
/**
* Pss of Native Heap bytes in KB due to the application.
* Notes:
* * Includes private dirty malloc space.
* * We don't include nativePrivateClean, because there should be no
* such thing as private clean for the Native Heap.
* @hide
*/
@UnsupportedAppUsage
public int getSummaryNativeHeap() {
return nativePrivateDirty;
}
/**
* Pss of code and other static resource bytes in KB due to
* the application.
* @hide
*/
@UnsupportedAppUsage
public int getSummaryCode() {
return getOtherPrivate(OTHER_SO)
+ getOtherPrivate(OTHER_JAR)
+ getOtherPrivate(OTHER_APK)
+ getOtherPrivate(OTHER_TTF)
+ getOtherPrivate(OTHER_DEX)
+ getOtherPrivate(OTHER_OAT)
+ getOtherPrivate(OTHER_DALVIK_OTHER_ZYGOTE_CODE_CACHE)
+ getOtherPrivate(OTHER_DALVIK_OTHER_APP_CODE_CACHE);
}
/**
* Pss in KB of the stack due to the application.
* Notes:
* * Includes private dirty stack, which includes both Java and Native
* stack.
* * Does not include private clean stack, because there should be no
* such thing as private clean for the stack.
* @hide
*/
@UnsupportedAppUsage
public int getSummaryStack() {
return getOtherPrivateDirty(OTHER_STACK);
}
/**
* Pss in KB of graphics due to the application.
* Notes:
* * Includes private Gfx, EGL, and GL.
* * Warning: These numbers can be misreported by the graphics drivers.
* * We don't include shared graphics. It may make sense to, because
* shared graphics are likely buffers due to the application
* anyway, but it's simpler to implement to just group all shared
* memory into the System category.
* @hide
*/
@UnsupportedAppUsage
public int getSummaryGraphics() {
return getOtherPrivate(OTHER_GL_DEV)
+ getOtherPrivate(OTHER_GRAPHICS)
+ getOtherPrivate(OTHER_GL);
}
/**
* Pss in KB due to the application that haven't otherwise been
* accounted for.
* @hide
*/
@UnsupportedAppUsage
public int getSummaryPrivateOther() {
return getTotalPrivateClean()
+ getTotalPrivateDirty()
- getSummaryJavaHeap()
- getSummaryNativeHeap()
- getSummaryCode()
- getSummaryStack()
- getSummaryGraphics();
}
/**
* Pss in KB due to the system.
* Notes:
* * Includes all shared memory.
* @hide
*/
@UnsupportedAppUsage
public int getSummarySystem() {
return getTotalPss()
- getTotalPrivateClean()
- getTotalPrivateDirty();
}
/**
* Rss of Java Heap bytes in KB due to the application.
* @hide
*/
public int getSummaryJavaHeapRss() {
return dalvikRss + getOtherRss(OTHER_ART);
}
/**
* Rss of Native Heap bytes in KB due to the application.
* @hide
*/
public int getSummaryNativeHeapRss() {
return nativeRss;
}
/**
* Rss of code and other static resource bytes in KB due to
* the application.
* @hide
*/
public int getSummaryCodeRss() {
return getOtherRss(OTHER_SO)
+ getOtherRss(OTHER_JAR)
+ getOtherRss(OTHER_APK)
+ getOtherRss(OTHER_TTF)
+ getOtherRss(OTHER_DEX)
+ getOtherRss(OTHER_OAT)
+ getOtherRss(OTHER_DALVIK_OTHER_ZYGOTE_CODE_CACHE)
+ getOtherRss(OTHER_DALVIK_OTHER_APP_CODE_CACHE);
}
/**
* Rss in KB of the stack due to the application.
* @hide
*/
public int getSummaryStackRss() {
return getOtherRss(OTHER_STACK);
}
/**
* Rss in KB of graphics due to the application.
* @hide
*/
public int getSummaryGraphicsRss() {
return getOtherRss(OTHER_GL_DEV)
+ getOtherRss(OTHER_GRAPHICS)
+ getOtherRss(OTHER_GL);
}
/**
* Rss in KB due to either the application or system that haven't otherwise been
* accounted for.
* @hide
*/
public int getSummaryUnknownRss() {
return getTotalRss()
- getSummaryJavaHeapRss()
- getSummaryNativeHeapRss()
- getSummaryCodeRss()
- getSummaryStackRss()
- getSummaryGraphicsRss();
}
/**
* Total Pss in KB.
* @hide
*/
public int getSummaryTotalPss() {
return getTotalPss();
}
/**
* Total Swap in KB.
* Notes:
* * Some of this memory belongs in other categories, but we don't
* know if the Swap memory is shared or private, so we don't know
* what to blame on the application and what on the system.
* For now, just lump all the Swap in one place.
* For kernels reporting SwapPss {@link #getSummaryTotalSwapPss()}
* will report the application proportional Swap.
* @hide
*/
public int getSummaryTotalSwap() {
return getTotalSwappedOut();
}
/**
* Total proportional Swap in KB.
* Notes:
* * Always 0 if {@link #hasSwappedOutPss} is false.
* @hide
*/
public int getSummaryTotalSwapPss() {
return getTotalSwappedOutPss();
}
/**
* Return true if the kernel is reporting pss swapped out... that is, if
* {@link #getSummaryTotalSwapPss()} will return non-0 values.
* @hide
*/
public boolean hasSwappedOutPss() {
return hasSwappedOutPss;
}
public int describeContents() {
return 0;
}
public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(dalvikPss);
dest.writeInt(dalvikSwappablePss);
dest.writeInt(dalvikRss);
dest.writeInt(dalvikPrivateDirty);
dest.writeInt(dalvikSharedDirty);
dest.writeInt(dalvikPrivateClean);
dest.writeInt(dalvikSharedClean);
dest.writeInt(dalvikSwappedOut);
dest.writeInt(dalvikSwappedOutPss);
dest.writeInt(nativePss);
dest.writeInt(nativeSwappablePss);
dest.writeInt(nativeRss);
dest.writeInt(nativePrivateDirty);
dest.writeInt(nativeSharedDirty);
dest.writeInt(nativePrivateClean);
dest.writeInt(nativeSharedClean);
dest.writeInt(nativeSwappedOut);
dest.writeInt(nativeSwappedOutPss);
dest.writeInt(otherPss);
dest.writeInt(otherSwappablePss);
dest.writeInt(otherRss);
dest.writeInt(otherPrivateDirty);
dest.writeInt(otherSharedDirty);
dest.writeInt(otherPrivateClean);
dest.writeInt(otherSharedClean);
dest.writeInt(otherSwappedOut);
dest.writeInt(hasSwappedOutPss ? 1 : 0);
dest.writeInt(otherSwappedOutPss);
dest.writeIntArray(otherStats);
}
public void readFromParcel(Parcel source) {
dalvikPss = source.readInt();
dalvikSwappablePss = source.readInt();
dalvikRss = source.readInt();
dalvikPrivateDirty = source.readInt();
dalvikSharedDirty = source.readInt();
dalvikPrivateClean = source.readInt();
dalvikSharedClean = source.readInt();
dalvikSwappedOut = source.readInt();
dalvikSwappedOutPss = source.readInt();
nativePss = source.readInt();
nativeSwappablePss = source.readInt();
nativeRss = source.readInt();
nativePrivateDirty = source.readInt();
nativeSharedDirty = source.readInt();
nativePrivateClean = source.readInt();
nativeSharedClean = source.readInt();
nativeSwappedOut = source.readInt();
nativeSwappedOutPss = source.readInt();
otherPss = source.readInt();
otherSwappablePss = source.readInt();
otherRss = source.readInt();
otherPrivateDirty = source.readInt();
otherSharedDirty = source.readInt();
otherPrivateClean = source.readInt();
otherSharedClean = source.readInt();
otherSwappedOut = source.readInt();
hasSwappedOutPss = source.readInt() != 0;
otherSwappedOutPss = source.readInt();
otherStats = source.createIntArray();
}
public static final @android.annotation.NonNull Creator<MemoryInfo> CREATOR = new Creator<MemoryInfo>() {
public MemoryInfo createFromParcel(Parcel source) {
return new MemoryInfo(source);
}
public MemoryInfo[] newArray(int size) {
return new MemoryInfo[size];
}
};
private MemoryInfo(Parcel source) {
readFromParcel(source);
}
}