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': 'Task Dead', 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, ioWait: boolean|undefined = undefined) { 34 if (state === undefined) return ''; 35 if (state === 'Running') { 36 return state; 37 } 38 let result = states[state[0]]; 39 if (ioWait === true) { 40 result += ' (IO)'; 41 } else if (ioWait === false) { 42 result += ' (non-IO)'; 43 } 44 for (let i = 1; i < state.length; i++) { 45 result += state[i] === '+' ? ' ' : ' + '; 46 result += states[state[i]]; 47 } 48 // state is some string we don't know how to translate. 49 if (result === undefined) return state; 50 51 return result; 52} 53