source: rtems/cpukit/libmisc/shell/main_top.c @ a7817010

4.115
Last change on this file since a7817010 was a7817010, checked in by Jennifer Averett <jennifer.averett@…>, on 09/29/14 at 15:21:00

libmisc: Add top to shell.

  • Property mode set to 100644
File size: 1.4 KB
Line 
1/*
2 *  TOP Command Implementation
3 *
4 *  COPYRIGHT (c) 2014.
5 *  On-Line Applications Research Corporation (OAR).
6 *
7 *  The license and distribution terms for this file may be
8 *  found in the file LICENSE in this distribution or at
9 *  http://www.rtems.org/license/LICENSE.
10 */
11
12#ifdef HAVE_CONFIG_H
13#include "config.h"
14#endif
15
16#include <stdio.h>
17#include <string.h>
18
19#include <rtems.h>
20#include <rtems/cpuuse.h>
21#include <rtems/shell.h>
22#include "internal.h"
23
24static int rtems_shell_main_top(
25  int   argc,
26  char *argv[]
27)
28{
29  /*
30   *  When invoked with no arguments, print the report.
31   */
32  if ( argc == 1 ) {
33    rtems_cpu_usage_top_with_plugin(stdout, (rtems_printk_plugin_t)fprintf);
34    return 0;
35  }
36
37  /*
38   *  When invoked with the single argument -r, reset the statistics.
39   */
40  if ( argc == 2 && !strcmp( argv[1], "-r" ) ) {
41    printf( "Resetting CPU Usage information\n" );
42    rtems_cpu_usage_reset();
43    return 0;
44  }
45
46  /*
47   *  OK.  The user did something wrong.
48   */
49  fprintf( stderr, "%s: [-r]\n", argv[0] );
50  return -1;
51}
52
53rtems_shell_cmd_t rtems_shell_TOP_Command = {
54  "top",                                      /* name */
55  "[-r] print or reset per thread cpu usage", /* usage */
56  "rtems",                                    /* topic */
57  rtems_shell_main_top,                       /* command */
58  NULL,                                       /* alias */
59  NULL                                        /* next */
60};
Note: See TracBrowser for help on using the repository browser.