1// Copyright (C) 2019 The Android Open Source Project 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); 4// you may not use this file except in compliance with the License. 5// You may obtain a copy of the License at 6// 7// http://www.apache.org/licenses/LICENSE-2.0 8// 9// Unless required by applicable law or agreed to in writing, software 10// distributed under the License is distributed on an "AS IS" BASIS, 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12// See the License for the specific language governing permissions and 13// limitations under the License. 14 15const states: {[key: string]: string} = { 16 'R': 'Runnable', 17 'S': 'Sleeping', 18 'D': 'Uninterruptible Sleep', 19 'T': 'Stopped', 20 't': 'Traced', 21 'X': 'Exit (Dead)', 22 'Z': 'Exit (Zombie)', 23 'x': 'Task Dead', 24 'I': 'Idle', 25 'K': 'Wake Kill', 26 'W': 'Waking', 27 'P': 'Parked', 28 'N': 'No Load', 29 '+': '(Preempted)', 30}; 31 32export function translateState( 33 state: string | undefined | null, 34 ioWait: boolean | undefined = undefined, 35) { 36 if (state === undefined) return ''; 37 38 // Self describing states 39 switch (state) { 40 case 'Running': 41 case 'Initialized': 42 case 'Deferred Ready': 43 case 'Transition': 44 case 'Stand By': 45 case 'Waiting': 46 return state; 47 } 48 49 if (state === null) { 50 return 'Unknown'; 51 } 52 let result = states[state[0]]; 53 if (ioWait === true) { 54 result += ' (IO)'; 55 } else if (ioWait === false) { 56 result += ' (non-IO)'; 57 } 58 for (let i = 1; i < state.length; i++) { 59 result += state[i] === '+' ? ' ' : ' + '; 60 result += states[state[i]]; 61 } 62 // state is some string we don't know how to translate. 63 if (result === undefined) return state; 64 65 return result; 66} 67