Home | History | Annotate | Download | only in item
      1 /*
      2  * Copyright (C) 2018 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 com.android.loganalysis.item;
     17 
     18 import org.json.JSONException;
     19 import org.json.JSONObject;
     20 
     21 import java.util.HashMap;
     22 import java.util.Map;
     23 
     24 /**
     25  * An {@link IItem} used to store output from `dumpsys meminfo --checkin PROCESS` where PROCESS is
     26  * from the output of `dumpsys meminfo`. Data is stored as a map of categories to a map of
     27  * measurement types to values.
     28  */
     29 public class DumpsysProcessMeminfoItem extends GenericMapItem<Map<String, Long>> {
     30     // Should match value from ActivityThread
     31     public static final int ACTIVITY_THREAD_CHECKIN_VERSION = 4;
     32 
     33     // Default Categories
     34     public static final String NATIVE = "NATIVE";
     35     public static final String DALVIK = "DALVIK";
     36     public static final String OTHER = "OTHER";
     37     public static final String TOTAL = "TOTAL";
     38 
     39     // Memory Measurement Types
     40     public static final String PSS = "PSS";
     41     public static final String SWAPPABLE_PSS = "SWAPPABLE_PSS";
     42     public static final String SHARED_DIRTY = "SHARED_DIRTY";
     43     public static final String SHARED_CLEAN = "SHARED_CLEAN";
     44     public static final String PRIVATE_DIRTY = "PRIVATE_DIRTY";
     45     public static final String PRIVATE_CLEAN = "PRIVATE_CLEAN";
     46     public static final String SWAPPED_OUT = "SWAPPED_OUT";
     47     public static final String SWAPPED_OUT_PSS = "SWAPPED_OUT_PSS";
     48     // NATIVE, DALVIK, TOTAL only
     49     public static final String MAX = "MAX";
     50     public static final String ALLOCATED = "ALLOCATED";
     51     public static final String FREE = "FREE";
     52 
     53     public static final String[] MAIN_OUTPUT_ORDER = {
     54         MAX,
     55         ALLOCATED,
     56         FREE,
     57         PSS,
     58         SWAPPABLE_PSS,
     59         SHARED_DIRTY,
     60         SHARED_CLEAN,
     61         PRIVATE_DIRTY,
     62         PRIVATE_CLEAN,
     63         SWAPPED_OUT,
     64         SWAPPED_OUT_PSS
     65     };
     66     public static final String[] OTHER_OUTPUT_ORDER = {
     67         PSS,
     68         SWAPPABLE_PSS,
     69         SHARED_DIRTY,
     70         SHARED_CLEAN,
     71         PRIVATE_DIRTY,
     72         PRIVATE_CLEAN,
     73         SWAPPED_OUT,
     74         SWAPPED_OUT_PSS
     75     };
     76 
     77     private int mPid;
     78     private String mProcessName;
     79 
     80     public DumpsysProcessMeminfoItem() {
     81         this.put(NATIVE, new HashMap<>());
     82         this.put(DALVIK, new HashMap<>());
     83         this.put(OTHER, new HashMap<>());
     84         this.put(TOTAL, new HashMap<>());
     85     }
     86 
     87     /** Get the pid */
     88     public int getPid() {
     89         return mPid;
     90     }
     91 
     92     /** Set the pid */
     93     public void setPid(int pid) {
     94         mPid = pid;
     95     }
     96 
     97     /** Get the process name */
     98     public String getProcessName() {
     99         return mProcessName;
    100     }
    101 
    102     /** Set the process name */
    103     public void setProcessName(String processName) {
    104         mProcessName = processName;
    105     }
    106 
    107     /** {@inheritDoc} */
    108     @Override
    109     public JSONObject toJson() {
    110         JSONObject result = super.toJson();
    111         try {
    112             result.put("pid", mPid);
    113             result.put("process_name", mProcessName);
    114         } catch (JSONException e) {
    115             //ignore
    116         }
    117         return result;
    118     }
    119 }
    120