| 1 | /* Copyright (C) 2011 Ericsson AB, Nils Carlson <nils.carlson@ericsson.com> |
| 2 | * |
| 3 | * This library is free software; you can redistribute it and/or |
| 4 | * modify it under the terms of the GNU Lesser General Public |
| 5 | * License as published by the Free Software Foundation; either |
| 6 | * version 2.1 of the License, or (at your option) any later version. |
| 7 | * |
| 8 | * This library is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 11 | * Lesser General Public License for more details. |
| 12 | * |
| 13 | * You should have received a copy of the GNU Lesser General Public |
| 14 | * License along with this library; if not, write to the Free Software |
| 15 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 16 | */ |
| 17 | #include <stdio.h> |
| 18 | #include <sys/types.h> |
| 19 | #include <unistd.h> |
| 20 | #include <ust/ustctl.h> |
| 21 | #include "scanning_functions.h" |
| 22 | #include "usterr.h" |
| 23 | #include "cli.h" |
| 24 | |
| 25 | |
| 26 | static int create_trace(int argc, char *argv[]) |
| 27 | { |
| 28 | pid_t pid; |
| 29 | |
| 30 | pid = parse_pid(argv[1]); |
| 31 | |
| 32 | if (ustctl_create_trace(argv[2], pid)) { |
| 33 | ERR("Failed to create trace %s for PID %u\n", argv[2], pid); |
| 34 | return -1; |
| 35 | } |
| 36 | |
| 37 | return 0; |
| 38 | } |
| 39 | |
| 40 | static int alloc_trace(int argc, char *argv[]) |
| 41 | { |
| 42 | pid_t pid; |
| 43 | |
| 44 | pid = parse_pid(argv[1]); |
| 45 | |
| 46 | if (ustctl_alloc_trace(argv[2], pid)) { |
| 47 | ERR("Failed to allocate trace %s for PID %u\n", argv[2], pid); |
| 48 | return -1; |
| 49 | } |
| 50 | return 0; |
| 51 | } |
| 52 | |
| 53 | static int start_trace(int argc, char *argv[]) |
| 54 | { |
| 55 | pid_t pid; |
| 56 | |
| 57 | pid = parse_pid(argv[1]); |
| 58 | |
| 59 | if (ustctl_start_trace(argv[2], pid)) { |
| 60 | ERR("Failed to start trace %s for PID %u\n", argv[2], pid); |
| 61 | return -1; |
| 62 | } |
| 63 | return 0; |
| 64 | } |
| 65 | |
| 66 | static int stop_trace(int argc, char *argv[]) |
| 67 | { |
| 68 | pid_t pid; |
| 69 | |
| 70 | pid = parse_pid(argv[1]); |
| 71 | |
| 72 | if (ustctl_stop_trace(argv[2], pid)) { |
| 73 | ERR("Failed to stop trace %s for PID %u\n", argv[2], pid); |
| 74 | return -1; |
| 75 | } |
| 76 | return 0; |
| 77 | } |
| 78 | |
| 79 | static int destroy_trace(int argc, char *argv[]) |
| 80 | { |
| 81 | pid_t pid; |
| 82 | |
| 83 | pid = parse_pid(argv[1]); |
| 84 | |
| 85 | if (ustctl_destroy_trace(argv[2], pid)) { |
| 86 | ERR("Failed to destroy trace %s for PID %u\n", argv[2], pid); |
| 87 | return -1; |
| 88 | } |
| 89 | return 0; |
| 90 | } |
| 91 | |
| 92 | static int force_subbuf_switch(int argc, char *argv[]) |
| 93 | { |
| 94 | pid_t pid; |
| 95 | |
| 96 | pid = parse_pid(argv[1]); |
| 97 | |
| 98 | if (ustctl_force_switch(pid)) { |
| 99 | ERR("error while trying to force switch for PID %u\n", pid); |
| 100 | return -1; |
| 101 | } |
| 102 | |
| 103 | return 0; |
| 104 | } |
| 105 | |
| 106 | struct cli_cmd __cli_cmds trace_cmds[] = { |
| 107 | { |
| 108 | .name = "create-trace", |
| 109 | .description = "Create a trace for a process", |
| 110 | .help_text = "create-trace <pid> <trace>\n" |
| 111 | "Create a trace for a process\n", |
| 112 | .function = create_trace, |
| 113 | .desired_args = 2, |
| 114 | .desired_args_op = CLI_EQ, |
| 115 | }, |
| 116 | { |
| 117 | .name = "alloc-trace", |
| 118 | .description = "Allocate a trace for a process", |
| 119 | .help_text = "alloc-trace <pid> <trace>\n" |
| 120 | "Allocate a trace for a process\n", |
| 121 | .function = alloc_trace, |
| 122 | .desired_args = 2, |
| 123 | .desired_args_op = CLI_EQ, |
| 124 | }, |
| 125 | { |
| 126 | .name = "start-trace", |
| 127 | .description = "Start a trace for a process", |
| 128 | .help_text = "start-trace <pid> <trace>\n" |
| 129 | "Start a trace for a process\n", |
| 130 | .function = start_trace, |
| 131 | .desired_args = 2, |
| 132 | .desired_args_op = CLI_EQ, |
| 133 | }, |
| 134 | { |
| 135 | .name = "stop-trace", |
| 136 | .description = "Stop a trace for a process", |
| 137 | .help_text = "stop-trace <pid> <trace>\n" |
| 138 | "Stop a trace for a process\n", |
| 139 | .function = stop_trace, |
| 140 | .desired_args = 2, |
| 141 | .desired_args_op = CLI_EQ, |
| 142 | }, |
| 143 | { |
| 144 | .name = "destroy-trace", |
| 145 | .description = "Destroy a trace for a process", |
| 146 | .help_text = "destroy-trace <pid> <trace>\n" |
| 147 | "Destroy a trace for a process\n", |
| 148 | .function = destroy_trace, |
| 149 | .desired_args = 2, |
| 150 | .desired_args_op = CLI_EQ, |
| 151 | }, |
| 152 | { |
| 153 | .name = "force-subbuf-switch", |
| 154 | .description = "Force a subbuffer switch", |
| 155 | .help_text = "force-subbuf-switch <pid> <trace>\n" |
| 156 | "Force a subbuffer switch for a trace, currently this forces\n" |
| 157 | "a subbuffer switch for all traces in a process\n", |
| 158 | .function = force_subbuf_switch, |
| 159 | .desired_args = 2, |
| 160 | .desired_args_op = CLI_EQ, |
| 161 | }, |
| 162 | }; |