#!/pkg/bin/ksh
# show tech-support evm command
#
# Nov. 2019  Douglas Wooff
#
# Copyright (c) 2019 by cisco Systems, Inc.
# All rights reserved.
#----------------------------------------------------------------------------

. /pkg/bin/show_tech_main_fragment

__cardtype="unspecified";
procname="unspecified"
ins_id=1

while [ "$#" -gt "0" ]; do
    case "$1" in
       -P) procname="$2"; shift 2;;
       -I) ins_id="$2"; shift 2;;
       -t) __cardtype="$2"; shift 2;;
       -l) location="$2"; shift 2;;
        *) default_parser_function $@; shift $#;;
    esac
done

if [ "$__cardtype" == "unspecified" ]; then
    __cardtype=`node_type`
fi

# System specifc commands
sys_exec[1]='show version'
sys__ksh[1]='ng_show_version'
sys_exec[2]='show redundancy summary'
sys__ksh[2]='redcon_show -s'
sys__ksh[3]=''

# Node specific commands
current_location_cmds_exec[1]='show log local'
current_location_cmds__ksh[1]='show_local_log'
current_location_cmds_exec[2]='show processes blocked'
current_location_cmds__ksh[2]='sh_proc_ng_blocked'

# Process specific commands

current_location_cmds_exec[3]='show processes $procname'
current_location_cmds__ksh[3]='sysmgr_show -o -p $procname'

# First, collect ctrace without -g, in case there are traces dumped to
# disk from a recent crash of the process in question.
# (they would be erased using -g)
current_location_cmds_exec[4]="run ctracedec -tkwGpsTHd $procname"
current_location_cmds__ksh[4]="ctracedec -tkwGpsTHd $procname"

# Then, with -g, to "grab" (dump) current in-memory traces.
current_location_cmds_exec[5]="run ctracedec -gtkwGpsTHd $procname"
current_location_cmds__ksh[5]="ctracedec -gtkwGpsTHd $procname"

current_location_cmds_exec[6]=""
current_location_cmds__ksh[6]=""

display() {

    print_main_heading "show tech-support evm for $procname"

    if [ "$__cardtype" == "SYS" ]; then
        exec_commands sys
    else 
        exec_commands current_location_cmds
    fi	 

    print_main_heading "show tech-support evm complete"

}

. /pkg/bin/show_tech_file_fragment
