# shellcheck shell=dash disable=SC2120,SC2034
# ___x_cmd_pwsh_mem(){
#     ___x_cmd_pwsh___exec_to_result <<A
# Get-Counter -Counter "\Memory\Available Bytes", "\Memory\Committed Bytes", "\Memory\Page Faults/sec" | ConvertTo-Csv -NoTypeInformation | Out-File -Encoding UTF8 -FilePath "result"
# A
# }

___x_cmd_pwsh_perf(){
    local cmd=; local x_output_mode=; local x_output=
    case "$1" in
        cpu)        cmd="Get-Counter '\Processor(_Total)\% Processor Time'"; shift ;;
        mem|memory) cmd='Get-Counter -Counter "\Memory\Available Bytes", "\Memory\Committed Bytes", "\Memory\Page Faults/sec"'; shift ;;
        disk)       cmd='Get-Counter "\LogicalDisk(C:)\Disk Reads/sec", "\LogicalDisk(C:)\Disk Writes/sec"'; shift ;;
        net)        cmd='Get-Counter "\Network Interface(*)\Bytes Sent/sec", "\Network Interface(*)\Bytes Received/sec"'; shift ;;
        -h|--help)  ___x_cmd help -m pwsh perf; return ;;
        *)          N=pwsh M="Unsupported subcmd => $1" log:ret:64  ;;
    esac

    pwsh:arg:null

    while [ $# -gt 0 ]; do
        pwsh:output:mode
        case "$1" in
            -s|-sampleinterval)     cmd="${cmd} -SampleInterval $2";   shift 2 ;;
            -m|-maxsamples)         cmd="${cmd} -MaxSamples $2";       shift 2 ;;
            # -continuous|-cont)       cmd="${cmd} -Continuous";          shift 1 ;;
            *)                      N=pwsh M="Unsupported option => $1" log:ret:64  ;;
        esac
    done

    [ "$x_output_mode" != app ] || {
        ___x_cmd_pwsh___exec "$x_output_mode" "$cmd" "$x_output" | ___x_cmd csv --app
        return
    }

    ___x_cmd_pwsh___exec "$x_output_mode" "$cmd" "$x_output"
}
