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 com.android.loganalysis.item; 18 19 import java.util.Arrays; 20 import java.util.HashSet; 21 import java.util.Set; 22 23 /** An {@link IItem} used to store Module info logged in dmesg. */ 24 public class DmesgModuleInfoItem extends GenericItem { 25 26 /** Constant for JSON output */ 27 public static final String MODULE_NAME = "MODULE_NAME"; 28 29 public static final String MODULE_START_TIME = "MODULE_START_TIME"; 30 31 public static final String MODULE_END_TIME = "MODULE_END_TIME"; 32 33 public static final String MODULE_COUNT = "MODULE_COUNT"; 34 35 public static final String MODULE_DURATION = "MODULE_DURATION"; 36 37 private static final Set<String> ATTRIBUTES = 38 new HashSet<String>( 39 Arrays.asList( 40 MODULE_NAME, 41 MODULE_START_TIME, 42 MODULE_END_TIME, 43 MODULE_COUNT, 44 MODULE_DURATION)); 45 46 /** The constructor for {@link DmesgModuleInfoItem}. */ DmesgModuleInfoItem()47 public DmesgModuleInfoItem() { 48 super(ATTRIBUTES); 49 } 50 51 /** Set the name of the Module */ setModuleName(String moduleName)52 public void setModuleName(String moduleName) { 53 setAttribute(MODULE_NAME, moduleName); 54 } 55 56 /** Get the name of the Module */ getModuleName()57 public String getModuleName() { 58 return (String) getAttribute(MODULE_NAME); 59 } 60 61 /** Get the count of modules */ getModuleCount()62 public String getModuleCount() { 63 return (String) getAttribute(MODULE_COUNT); 64 } 65 66 /** Set the count of modules */ setModuleCount(String moduleName)67 public void setModuleCount(String moduleName) { 68 setAttribute(MODULE_COUNT, moduleName); 69 } 70 71 /** Get the start time in msecs */ getStartTime()72 public Long getStartTime() { 73 return (Long) getAttribute(MODULE_START_TIME); 74 } 75 76 /** Set the start time in msecs */ setStartTime(Long startTime)77 public void setStartTime(Long startTime) { 78 setAttribute(MODULE_START_TIME, startTime); 79 } 80 81 /** Get the end time in msecs */ getEndTime()82 public Long getEndTime() { 83 return (Long) getAttribute(MODULE_END_TIME); 84 } 85 86 /** Set the end time in msecs */ setEndTime(Long endTime)87 public void setEndTime(Long endTime) { 88 setAttribute(MODULE_END_TIME, endTime); 89 } 90 91 /** 92 * Get the module loading time in msecs If the start or end time is not present then return -1 93 */ getModuleDuration()94 public Long getModuleDuration() { 95 if (null != getAttribute(MODULE_DURATION)) { 96 return (Long) getAttribute(MODULE_DURATION); 97 } 98 if (null != getAttribute(MODULE_END_TIME) && null != getAttribute(MODULE_START_TIME)) { 99 long duration = getEndTime() - getStartTime(); 100 setModuleDuration(duration); 101 return duration; 102 } 103 return -1L; 104 } 105 106 /** Get the duration in msec */ setModuleDuration(Long duration)107 public void setModuleDuration(Long duration) { 108 setAttribute(MODULE_DURATION, duration); 109 } 110 111 @Override toString()112 public String toString() { 113 return "ModuleInfoItem [" 114 + "getModuleName()=" 115 + getModuleName() 116 + ", getStartTime()=" 117 + getStartTime() 118 + ", getDuration()=" 119 + getModuleDuration() 120 + "]"; 121 } 122 } 123