1 /*
2  * Copyright (C) 2013 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.internal.app.procstats;
18 
19 /**
20  * Sparse mapping table to store durations of processes, etc running in different
21  * states.
22  */
23 public class DurationsTable extends SparseMappingTable.Table {
DurationsTable(SparseMappingTable tableData)24     public DurationsTable(SparseMappingTable tableData) {
25         super(tableData);
26     }
27 
28     /**
29      * Add all of the durations from the other table into this one.
30      * Resultant durations will be the sum of what is currently in the table
31      * and the new value.
32      */
addDurations(DurationsTable from)33     public void addDurations(DurationsTable from) {
34         final int N = from.getKeyCount();
35         for (int i=0; i<N; i++) {
36             final int key = from.getKeyAt(i);
37             this.addDuration(SparseMappingTable.getIdFromKey(key), from.getValue(key));
38         }
39     }
40 
41     /**
42      * Add the value into the value stored for the state.
43      *
44      * Resultant duration will be the sum of what is currently in the table
45      * and the new value.
46      */
addDuration(int state, long value)47     public void addDuration(int state, long value) {
48         final int key = getOrAddKey((byte)state, 1);
49         setValue(key, getValue(key) + value);
50     }
51 
52     /*
53     public long getDuration(int state, long now) {
54         final int key = getKey((byte)state);
55         if (key != SparseMappingTable.INVALID_KEY) {
56             return getValue(key);
57         } else {
58             return 0;
59         }
60     }
61     */
62 }
63 
64 
65