Home | History | Annotate | Download | only in item
      1 /*
      2  * Copyright (C) 2012 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 com.android.loganalysis.parser.LogcatParser;
     19 
     20 import java.util.Arrays;
     21 import java.util.HashSet;
     22 import java.util.Set;
     23 
     24 /**
     25  * An {@link IItem} used to store ANR info.
     26  */
     27 public class AnrItem extends MiscLogcatItem {
     28     /**
     29      * An enum used to select the CPU usage category.
     30      */
     31     public enum CpuUsageCategory {
     32         TOTAL,
     33         USER,
     34         KERNEL,
     35         IOWAIT,
     36     }
     37 
     38     /**
     39      * An enum used to select the load category.
     40      */
     41     public enum LoadCategory {
     42         LOAD_1,
     43         LOAD_5,
     44         LOAD_15;
     45     }
     46 
     47     /** Constant for JSON output */
     48     public static final String ACTIVITY = "ACTIVITY";
     49     /** Constant for JSON output */
     50     public static final String REASON = "REASON";
     51     /** Constant for JSON output */
     52     public static final String TRACE = "TRACE";
     53 
     54     private static final Set<String> ATTRIBUTES = new HashSet<String>(Arrays.asList(
     55         CpuUsageCategory.TOTAL.toString(),
     56         CpuUsageCategory.USER.toString(),
     57         CpuUsageCategory.KERNEL.toString(),
     58         CpuUsageCategory.IOWAIT.toString(),
     59         LoadCategory.LOAD_1.toString(),
     60         LoadCategory.LOAD_5.toString(),
     61         LoadCategory.LOAD_15.toString(),
     62         ACTIVITY, REASON, TRACE));
     63 
     64     /**
     65      * The constructor for {@link AnrItem}.
     66      */
     67     public AnrItem() {
     68         super(ATTRIBUTES);
     69         setCategory(LogcatParser.ANR);
     70     }
     71 
     72     /**
     73      * Get the CPU usage for a given category.
     74      */
     75     public Double getCpuUsage(CpuUsageCategory category) {
     76         return (Double) getAttribute(category.toString());
     77     }
     78 
     79     /**
     80      * Set the CPU usage for a given category.
     81      */
     82     public void setCpuUsage(CpuUsageCategory category, Double usage) {
     83         setAttribute(category.toString(), usage);
     84     }
     85 
     86     /**
     87      * Get the load for a given category.
     88      */
     89     public Double getLoad(LoadCategory category) {
     90         return (Double) getAttribute(category.toString());
     91     }
     92 
     93     /**
     94      * Set the load for a given category.
     95      */
     96     public void setLoad(LoadCategory category, Double usage) {
     97         setAttribute(category.toString(), usage);
     98     }
     99 
    100     /**
    101      * Get the activity for the ANR.
    102      */
    103     public String getActivity() {
    104         return (String) getAttribute(ACTIVITY);
    105     }
    106 
    107     /**
    108      * Set the activity for the ANR.
    109      */
    110     public void setActivity(String activity) {
    111         setAttribute(ACTIVITY, activity);
    112     }
    113 
    114     /**
    115      * Get the reason for the ANR.
    116      */
    117     public String getReason() {
    118         return (String) getAttribute(REASON);
    119     }
    120 
    121     /**
    122      * Set the reason for the ANR.
    123      */
    124     public void setReason(String reason) {
    125         setAttribute(REASON, reason);
    126     }
    127 
    128     /**
    129      * Get the main trace for the ANR.
    130      */
    131     public String getTrace() {
    132         return (String) getAttribute(TRACE);
    133     }
    134 
    135     /**
    136      * Set the main trace for the ANR.
    137      */
    138     public void setTrace(String trace) {
    139         setAttribute(TRACE, trace);
    140     }
    141 }
    142