⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 capture-cli.c

📁 RTEMS (Real-Time Executive for Multiprocessor Systems) is a free open source real-time operating sys
💻 C
📖 第 1 页 / 共 3 页
字号:
/*  ------------------------------------------------------------------------  $Id: capture-cli.c,v 1.3.2.2 2003/07/08 08:36:36 ralf Exp $  ------------------------------------------------------------------------    Copyright Objective Design Systems Pty Ltd, 2002  All rights reserved Objective Design Systems Pty Ltd, 2002  Chris Johns (ccj@acm.org)  COPYRIGHT (c) 1989-1998.  On-Line Applications Research Corporation (OAR).  The license and distribution terms for this file may be  found in the file LICENSE in this distribution.  This software with is provided ``as is'' and with NO WARRANTY.    ------------------------------------------------------------------------  RTEMS Performance Monitoring and Measurement Framework.  This is the Target Interface Command Line Interface. You need  start the RTEMS monitor.*/#ifdef HAVE_CONFIG_H#include "config.h"#endif#include <ctype.h>#include <stdlib.h>#include <stdio.h>#include <string.h>#include <rtems.h>#include <rtems/capture-cli.h>#include <rtems/monitor.h>#define RTEMS_CAPTURE_CLI_MAX_LOAD_TASKS (32)/* * The user capture timestamper. */static rtems_capture_timestamp capture_timestamp;/* * Common variable to sync the load monitor task. */static volatile int cli_load_thread_active;/* * rtems_capture_cli_open * *  DESCRIPTION: * * This function opens the capture engine. We need the size of the * capture buffer. * */static const char* open_usage = "usage: copen [-i] size\n";static voidrtems_capture_cli_open (  int argc,   char **argv,  unsigned32 command_arg,   boolean verbose ){  rtems_unsigned32  size = 0;  rtems_boolean     enable = 0;  rtems_status_code sc;  int               arg;  if (argc <= 1)  {    printf (open_usage);    return;  }  for (arg = 1; arg < argc; arg++)  {    if (argv[arg][0] == '-')    {      if (argv[arg][1] == 'i')        enable = 1;      else        printf ("warning: option -%c ignored\n", argv[arg][1]);    }    else    {      size = strtoul (argv[arg], 0, 0);      if (size < 100)      {        printf ("error: size must be greater than or equal to 100\n");        return;      }    }  }  sc = rtems_capture_open (size, capture_timestamp);  if (sc != RTEMS_SUCCESSFUL)  {    printf ("error: open failed: %s\n", rtems_status_text (sc));    return;  }  printf ("capture engine opened.\n");  if (!enable)    return;    sc = rtems_capture_control (enable);  if (sc != RTEMS_SUCCESSFUL)  {    printf ("error: open enable failed: %s\n", rtems_status_text (sc));    return;  }  printf ("capture engine enabled.\n");}/* * rtems_capture_cli_close * *  DESCRIPTION: * * This function closes the capture engine. * */static voidrtems_capture_cli_close (  int argc,   char **argv,  unsigned32 command_arg,   boolean verbose ){  rtems_status_code sc;  sc = rtems_capture_close ();  if (sc != RTEMS_SUCCESSFUL)  {    printf ("error: close failed: %s\n", rtems_status_text (sc));    return;  }  printf ("capture engine closed.\n");}/* * rtems_capture_cli_enable * *  DESCRIPTION: * * This function enables the capture engine. * */static voidrtems_capture_cli_enable (  int argc,   char **argv,  unsigned32 command_arg,   boolean verbose ){  rtems_status_code sc;  sc = rtems_capture_control (1);  if (sc != RTEMS_SUCCESSFUL)  {    printf ("error: enable failed: %s\n", rtems_status_text (sc));    return;  }  printf ("capture engine enabled.\n");}/* * rtems_capture_cli_disable * *  DESCRIPTION: * * This function disables the capture engine. * */static voidrtems_capture_cli_disable (  int argc,   char **argv,  unsigned32 command_arg,   boolean verbose ){  rtems_status_code sc;  sc = rtems_capture_control (0);  if (sc != RTEMS_SUCCESSFUL)  {    printf ("error: disable failed: %s\n", rtems_status_text (sc));    return;  }  printf ("capture engine disabled.\n");}/* * rtems_capture_cli_task_list * *  DESCRIPTION: * * This function lists the tasks the capture engine knows about. * */static voidrtems_capture_cli_task_list (  int argc,   char **argv,  unsigned32 command_arg,   boolean verbose ){  rtems_task_priority   ceiling = rtems_capture_watch_get_ceiling ();  rtems_task_priority   floor = rtems_capture_watch_get_floor ();  rtems_capture_task_t* task = rtems_capture_get_task_list ();  rtems_unsigned32      ticks;  rtems_unsigned32      tick_offset;  unsigned long long    total_time;  int                   count = rtems_capture_task_count ();  if (capture_timestamp)    capture_timestamp (&ticks, &tick_offset);  else  {    ticks = _Watchdog_Ticks_since_boot;    tick_offset = 0;  }  total_time = (ticks * rtems_capture_task_time (task)) + tick_offset;  printf ("total %i\n", count);  while (task)  {    rtems_task_priority priority;    int                 stack_used;    int                 time_used;    stack_used = rtems_capture_task_stack_usage (task) * 100;    stack_used /= rtems_capture_task_stack_size (task);    if (stack_used > 100)      stack_used = 100;    time_used = (rtems_capture_task_time (task) * 100) / total_time;    if (time_used > 100)      time_used = 100;    priority = rtems_capture_task_real_priority (task);    printf (" ");    rtems_monitor_dump_id (rtems_capture_task_id (task));    printf (" ");    rtems_monitor_dump_name (rtems_capture_task_name (task));    printf (" ");    rtems_monitor_dump_priority (rtems_capture_task_start_priority (task));    printf (" ");    rtems_monitor_dump_priority (rtems_capture_task_real_priority (task));    printf (" ");    rtems_monitor_dump_priority (rtems_capture_task_curr_priority (task));    printf (" ");    rtems_monitor_dump_state (rtems_capture_task_state (task));    printf (" %c%c%c%c%c",            rtems_capture_task_valid (task) ? 'a' : 'd',            rtems_capture_task_flags (task) & RTEMS_CAPTURE_TRACED ? 't' : '-',            rtems_capture_task_control_flags (task) & RTEMS_CAPTURE_TO_ANY ? 'F' : '-',            rtems_capture_task_control_flags (task) & RTEMS_CAPTURE_FROM_ANY ? 'T' : '-',            rtems_capture_task_control_flags (task) & RTEMS_CAPTURE_FROM_TO ? 'E' : '-');    if ((floor > ceiling) && (ceiling > priority))      printf ("--");    else      printf ("%c%c",              rtems_capture_task_control (task) ?              (rtems_capture_task_control_flags (task) & RTEMS_CAPTURE_WATCH ? 'w' : '+') : '-',              rtems_capture_watch_global_on () ? 'g' : '-');    printf (" %3i%% %3i%% (%i)\n",            stack_used, time_used, rtems_capture_task_ticks (task));    task = rtems_capture_next_task (task);  }}/* * rtems_capture_cli_task_load_thread * *  DESCRIPTION: * * This function displays the load of the tasks on an ANSI terminal. * */static voidrtems_capture_cli_task_load_thread (rtems_task_argument arg){  rtems_task_priority ceiling = rtems_capture_watch_get_ceiling ();  rtems_task_priority floor = rtems_capture_watch_get_floor ();  int                 last_count = 0;    printf ("\x1b[2J Press ENTER to exit.\n\n");  printf ("     PID NAME RPRI CPRI STATE  %%CPU     %%STK FLGS   EXEC TIME\n");  for (;;)  {     rtems_capture_task_t* tasks[RTEMS_CAPTURE_CLI_MAX_LOAD_TASKS + 1];    unsigned long long    load[RTEMS_CAPTURE_CLI_MAX_LOAD_TASKS + 1];    rtems_capture_task_t* task;    unsigned long long    total_time;    int                   count = 0;    int                   i;    int                   j;    cli_load_thread_active = 1;        /*     * Iterate over the tasks and sort the highest load tasks     * into our local arrays. We only handle a limited number of     * tasks.     */       memset (tasks, 0, sizeof (tasks));    memset (load, 0, sizeof (load));    task = rtems_capture_get_task_list ();      while (task)    {      if (rtems_capture_task_valid (task))      {        unsigned long long l = rtems_capture_task_delta_time (task);        count++;        for (i = 0; i < RTEMS_CAPTURE_CLI_MAX_LOAD_TASKS; i++)        {          if (tasks[i])          {            if ((l == 0) || (l < load[i]))              continue;            for (j = (RTEMS_CAPTURE_CLI_MAX_LOAD_TASKS - 1); j >= i; j--)            {              tasks[j + 1] = tasks[j];              load[j + 1]  = load[j];            }          }          tasks[i] = task;          load[i]  = l;          break;        }      }            task = rtems_capture_next_task (task);    }    printf ("\x1b[4;0H");    total_time = 0;        for (i = 0; i < RTEMS_CAPTURE_CLI_MAX_LOAD_TASKS; i++)      total_time += load[i];    if (count > last_count)      j = count;    else      j = last_count;    for (i = 0; i < RTEMS_CAPTURE_CLI_MAX_LOAD_TASKS; i++)    {      rtems_task_priority priority;      int                 stack_used;      int                 task_load;      int                 k;      if (!tasks[i])        break;            j--;      stack_used = rtems_capture_task_stack_usage (tasks[i]) * 100;      stack_used /= rtems_capture_task_stack_size (tasks[i]);      if (stack_used > 100)        stack_used = 100;      task_load = (int) ((load[i] * 100000) / total_time);      priority = rtems_capture_task_real_priority (tasks[i]);      printf ("\x1b[K");      rtems_monitor_dump_id (rtems_capture_task_id (tasks[i]));      printf (" ");      rtems_monitor_dump_name (rtems_capture_task_name (tasks[i]));      printf ("  ");      rtems_monitor_dump_priority (priority);      printf ("  ");      rtems_monitor_dump_priority (rtems_capture_task_curr_priority (tasks[i]));      printf (" ");      k = rtems_monitor_dump_state (rtems_capture_task_state (tasks[i]));      printf ("%*c %3i.%03i%% ", 6 - k, ' ', task_load / 1000, task_load % 1000);      printf ("%3i%% %c%c%c%c%c", stack_used,              rtems_capture_task_valid (tasks[i]) ? 'a' : 'd',              rtems_capture_task_flags (tasks[i]) & RTEMS_CAPTURE_TRACED ? 't' : '-',              rtems_capture_task_control_flags (tasks[i]) & RTEMS_CAPTURE_TO_ANY ? 'F' : '-',              rtems_capture_task_control_flags (tasks[i]) & RTEMS_CAPTURE_FROM_ANY ? 'T' : '-',              rtems_capture_task_control_flags (tasks[i]) & RTEMS_CAPTURE_FROM_TO ? 'E' : '-');      if ((floor > ceiling) && (ceiling > priority))        printf ("--");      else        printf ("%c%c",                rtems_capture_task_control (tasks[i]) ?                 (rtems_capture_task_control_flags (tasks[i]) &                 RTEMS_CAPTURE_WATCH ? 'w' : '+') : '-',                rtems_capture_watch_global_on () ? 'g' : '-');            printf ("   %qi\n", rtems_capture_task_time (tasks[i]));    }    while (j)    {      printf ("\x1b[K\n");      j--;    }    last_count = count;    cli_load_thread_active = 0;        rtems_task_wake_after (TOD_MICROSECONDS_TO_TICKS (5000000));  }}/* * rtems_capture_cli_task_load * *  DESCRIPTION: * * This function is a monitor command. * */static voidrtems_capture_cli_task_load (  int argc,   char **argv,  unsigned32 command_arg,   boolean verbose ){  rtems_status_code   sc;  rtems_task_priority priority;  rtems_name          name;  rtems_id            id;    sc = rtems_task_set_priority (RTEMS_SELF, RTEMS_CURRENT_PRIORITY, &priority);  if (sc != RTEMS_SUCCESSFUL)  {    printf ("error: cannot obtain the current priority: %s\n", rtems_status_text (sc));    return;  }    memcpy (&name, "CPlt", 4);    sc = rtems_task_create (name, priority, 1024,                          RTEMS_NO_FLOATING_POINT | RTEMS_LOCAL,                          RTEMS_PREEMPT | RTEMS_TIMESLICE | RTEMS_NO_ASR,                          &id);    if (sc != RTEMS_SUCCESSFUL)   {    printf ("error: cannot create helper thread: %s\n", rtems_status_text (sc));    return;  }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -