Home | History | Annotate | Download | only in item
      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 
     17 package com.android.loganalysis.item;
     18 
     19 import java.util.Arrays;
     20 import java.util.HashSet;
     21 import java.util.Set;
     22 
     23 /**
     24  * An {@link IItem} used to store stage info logged in dmesg.
     25  * For example: [   14.425056] init: init second stage started!
     26  */
     27 public class DmesgStageInfoItem extends GenericItem {
     28 
     29     /** Constant for JSON output */
     30     public static final String STAGE_NAME = "STAGE_NAME";
     31     /** Constant for JSON output */
     32     public static final String STAGE_START_TIME = "STAGE_START_TIME";
     33     /** Constant for JSON output */
     34     public static final String STAGE_DURATION = "STAGE_DURATION";
     35 
     36     private static final Set<String> ATTRIBUTES = new HashSet<String>(Arrays.asList(
     37             STAGE_NAME, STAGE_START_TIME, STAGE_DURATION));
     38 
     39     /**
     40      * The constructor for {@link DmesgStageInfoItem}.
     41      */
     42     public DmesgStageInfoItem() {
     43         super(ATTRIBUTES);
     44     }
     45 
     46     /**
     47      * The constructor for {@link DmesgStageInfoItem}.
     48      */
     49     public DmesgStageInfoItem(String name, Long startTime, Long duration) {
     50         super(ATTRIBUTES);
     51         setAttribute(STAGE_NAME, name);
     52         setAttribute(STAGE_START_TIME, startTime);
     53         setAttribute(STAGE_DURATION, duration);
     54     }
     55 
     56     /**
     57      * Get the name of the stage
     58      */
     59     public String getStageName() {
     60         return (String) getAttribute(STAGE_NAME);
     61     }
     62 
     63     /**
     64      * Set the name of the stage
     65      */
     66     public void setStageName(String stageName) {
     67         setAttribute(STAGE_NAME, stageName);
     68     }
     69 
     70     /**
     71      * Get the start time in msecs
     72      */
     73     public Long getStartTime() {
     74         return (Long) getAttribute(STAGE_START_TIME);
     75     }
     76 
     77     /**
     78      * Set the start time in msecs
     79      */
     80     public void setStartTime(Long startTime) {
     81         setAttribute(STAGE_START_TIME, startTime);
     82     }
     83 
     84     /**
     85      * Get the duration in msecs
     86      */
     87     public Long getDuration() {
     88         return (Long) getAttribute(STAGE_DURATION);
     89     }
     90 
     91     /**
     92      * Set the duration in msecs
     93      */
     94     public void setDuration(Long duration) {
     95         setAttribute(STAGE_DURATION, duration);
     96     }
     97 
     98     @Override
     99     public String toString() {
    100         return "StageInfoItem [getStageName()=" + getStageName() + ", getStartTime()="
    101                 + getStartTime() + ", getDuration()=" + getDuration() + "]";
    102     }
    103 
    104 }
    105