1 /**
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements.  See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership.  The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License.  You may obtain a copy of the License at
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 
19 package org.apache.hadoop.mapred;
20 
21 import org.apache.hadoop.classification.InterfaceAudience.Private;
22 import org.apache.hadoop.classification.InterfaceStability.Unstable;
23 
24 /*
25  * This object gathers the [currently four] PeriodStatset's that we
26  * are gathering for a particular task attempt for packaging and
27  * handling as a single object.
28  */
29 @Private
30 @Unstable
31 public class ProgressSplitsBlock {
32   final PeriodicStatsAccumulator progressWallclockTime;
33   final PeriodicStatsAccumulator progressCPUTime;
34   final PeriodicStatsAccumulator progressVirtualMemoryKbytes;
35   final PeriodicStatsAccumulator progressPhysicalMemoryKbytes;
36 
37   static final int[] NULL_ARRAY = new int[0];
38 
39   static final int WALLCLOCK_TIME_INDEX = 0;
40   static final int CPU_TIME_INDEX = 1;
41   static final int VIRTUAL_MEMORY_KBYTES_INDEX = 2;
42   static final int PHYSICAL_MEMORY_KBYTES_INDEX = 3;
43 
44   static final int DEFAULT_NUMBER_PROGRESS_SPLITS = 12;
45 
ProgressSplitsBlock(int numberSplits)46   ProgressSplitsBlock(int numberSplits) {
47     progressWallclockTime
48       = new CumulativePeriodicStats(numberSplits);
49     progressCPUTime
50       = new CumulativePeriodicStats(numberSplits);
51     progressVirtualMemoryKbytes
52       = new StatePeriodicStats(numberSplits);
53     progressPhysicalMemoryKbytes
54       = new StatePeriodicStats(numberSplits);
55   }
56 
57   // this coordinates with LoggedTaskAttempt.SplitVectorKind
burst()58   int[][] burst() {
59     int[][] result = new int[4][];
60 
61     result[WALLCLOCK_TIME_INDEX] = progressWallclockTime.getValues();
62     result[CPU_TIME_INDEX] = progressCPUTime.getValues();
63     result[VIRTUAL_MEMORY_KBYTES_INDEX] = progressVirtualMemoryKbytes.getValues();
64     result[PHYSICAL_MEMORY_KBYTES_INDEX] = progressPhysicalMemoryKbytes.getValues();
65 
66     return result;
67   }
68 
arrayGet(int[][] burstedBlock, int index)69   static public int[] arrayGet(int[][] burstedBlock, int index) {
70     return burstedBlock == null ? NULL_ARRAY : burstedBlock[index];
71   }
72 
arrayGetWallclockTime(int[][] burstedBlock)73   static public int[] arrayGetWallclockTime(int[][] burstedBlock) {
74     return arrayGet(burstedBlock, WALLCLOCK_TIME_INDEX);
75   }
76 
arrayGetCPUTime(int[][] burstedBlock)77   static public int[] arrayGetCPUTime(int[][] burstedBlock) {
78     return arrayGet(burstedBlock, CPU_TIME_INDEX);
79   }
80 
arrayGetVMemKbytes(int[][] burstedBlock)81   static public int[] arrayGetVMemKbytes(int[][] burstedBlock) {
82     return arrayGet(burstedBlock, VIRTUAL_MEMORY_KBYTES_INDEX);
83   }
84 
arrayGetPhysMemKbytes(int[][] burstedBlock)85   static public int[] arrayGetPhysMemKbytes(int[][] burstedBlock) {
86     return arrayGet(burstedBlock, PHYSICAL_MEMORY_KBYTES_INDEX);
87   }
88 }
89 
90