src/LinuxTracing/SwitchesStatesNamesVisitor.cpp
std::optional<ThreadStateSlice::ThreadState> SwitchesStatesNamesVisitor::GetThreadStateFromChar(
    char c) {
  switch (c) {
    case 'R':
      return ThreadStateSlice::kRunnable;
    case 'S':
      return ThreadStateSlice::kInterruptibleSleep;
    case 'D':
      return ThreadStateSlice::kUninterruptibleSleep;
    case 'T':
      return ThreadStateSlice::kStopped;
    case 't':
      return ThreadStateSlice::kTraced;
    case 'X':
      return ThreadStateSlice::kDead;
    case 'Z':
      return ThreadStateSlice::kZombie;
    case 'P':
      // Note that 'P' (Parked) is only valid from Linux 3.9 to 3.13, but we still include it as it
      // is mentioned in /sys/kernel/debug/tracing/events/sched/sched_switch/format and in
      // https://github.com/torvalds/linux/blob/master/fs/proc/array.c.
      return ThreadStateSlice::kParked;
    case 'I':
      // 'I' (Idle) only applies to kernel threads. See
      // https://github.com/torvalds/linux/commit/06eb61844d841d0032a9950ce7f8e783ee49c0d0.
      return ThreadStateSlice::kIdle;
    default:
      return std::nullopt;
  }
}
// Associates a ThreadStateSlice::ThreadState to a thread state character retrieved from
// /proc/<pid>/stat or the `ps` command. The possible characters were manually obtained from
// /sys/kernel/debug/tracing/events/sched/sched_switch/format and compared with the ones listed in
// https://man7.org/linux/man-pages/man5/proc.5.html and
// https://www.man7.org/linux/man-pages/man1/ps.1.html#PROCESS_STATE_CODES to make sure we are not
// missing any additional valid one.
Associates a ThreadStateSlice::ThreadState to a thread state character retrieved from
proc//stat or the `ps` command.
Associates a ThreadStateSlice :: ThreadState to a thread state character retrieved from proc // stat or the ` ps ` command .
std::optional<ThreadStateSlice::ThreadState> SwitchesStatesNamesVisitor::GetThreadStateFromChar(
    char c) {
  switch (c) {
    case 'R':
      return ThreadStateSlice::kRunnable;
    case 'S':
      return ThreadStateSlice::kInterruptibleSleep;
    case 'D':
      return ThreadStateSlice::kUninterruptibleSleep;
    case 'T':
      return ThreadStateSlice::kStopped;
    case 't':
      return ThreadStateSlice::kTraced;
    case 'X':
      return ThreadStateSlice::kDead;
    case 'Z':
      return ThreadStateSlice::kZombie;
    case 'P':
      return ThreadStateSlice::kParked;
    case 'I':
      return ThreadStateSlice::kIdle;
    default:
      return std::nullopt;
  }
}
std :: optional < ThreadStateSlice :: ThreadState > SwitchesStatesNamesVisitor :: GetThreadStateFromChar ( char c ) { switch ( c ) { case ' ' : return ThreadStateSlice :: kRunnable ; case ' ' : return ThreadStateSlice :: kInterruptibleSleep ; case ' ' : return ThreadStateSlice :: kUninterruptibleSleep ; case ' ' : return ThreadStateSlice :: kStopped ; case ' ' : return ThreadStateSlice :: kTraced ; case ' ' : return ThreadStateSlice :: kDead ; case ' ' : return ThreadStateSlice :: kZombie ; case ' ' : return ThreadStateSlice :: kParked ; case ' ' : return ThreadStateSlice :: kIdle ; default : return std :: nullopt ; } }
Associates a ThreadStateSlice::ThreadState to a thread state character retrieved from
proc/<pid>/stat or the `ps` command.
Associates a ThreadStateSlice :: ThreadState to a thread state character retrieved from proc / <pid > / stat or the ` ps ` command .
// Note that 'P' (Parked) is only valid from Linux 3.9 to 3.13, but we still include it as it // is mentioned in /sys/kernel/debug/tracing/events/sched/sched_switch/format and in // https://github.com/torvalds/linux/blob/master/fs/proc/array.c. // 'I' (Idle) only applies to kernel threads. See // https://github.com/torvalds/linux/commit/06eb61844d841d0032a9950ce7f8e783ee49c0d0.