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': 'Interruptible Sleep',
18  'D': 'Uninterruptible (Disk) Sleep',
19  'T': 'Stopped',
20  't': 'Traced',
21  'X': 'Exit (Dead)',
22  'Z': 'Exit (Zombie)',
23  'x': 'Task Dead',
24  'K': 'Wake Kill',
25  'W': 'Waking',
26  'P': 'Parked',
27  'N': 'No Load',
28  '+': '(Preempted)'
29};
30
31export function translateState(state: string|undefined) {
32  if (state === undefined) return '';
33  if (state === 'Running' || state === 'Runnable' || state === 'Busy') {
34    return state;
35  }
36  let result = states[state[0]];
37  for (let i = 1; i < state.length; i++) {
38    result += state[i] === '+' ? ' ' : ' + ';
39    result += states[state[i]];
40  }
41  return result;
42}
43