2 * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; only version 2
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
28 static int opt_channels
;
39 static struct poptOption long_options
[] = {
40 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
41 {"help", 'h', POPT_ARG_NONE
, 0, OPT_HELP
, 0, 0},
42 {"events", 'e', POPT_ARG_NONE
, 0, OPT_EVENTS
, 0, 0},
43 {"kernel", 'k', POPT_ARG_NONE
, 0, OPT_KERNEL
, 0, 0},
44 {"pid", 'p', POPT_ARG_INT
, &opt_pid
, 0, 0, 0},
45 {"apps", 'a', POPT_ARG_NONE
, 0, OPT_APPS
, 0, 0},
46 {"session", 's', POPT_ARG_NONE
, 0, OPT_SESSIONS
, 0, 0},
47 {"channel", 'c', POPT_ARG_VAL
, &opt_channels
, 1, 0, 0},
54 static void usage(FILE *ofp
)
56 fprintf(ofp
, "usage: lttng list [options] [<executable>]\n");
58 fprintf(ofp
, " -h, --help Show this help\n");
59 fprintf(ofp
, " -e, --events List all available instrumentation\n");
60 fprintf(ofp
, " -k, --kernel List kernel instrumentation\n");
61 fprintf(ofp
, " -p, --pid PID List user-space instrumentation by PID\n");
62 fprintf(ofp
, " -a, --apps List traceable user-space applications/pids\n");
63 fprintf(ofp
, " -s, --sessions List tracing session\n");
70 * Get command line from /proc for a specific pid.
72 * On success, return an allocated string pointer pointing to the proc
74 * On error, return NULL.
76 static char *get_cmdline_by_pid(pid_t pid
)
81 char path
[24]; /* Can't go bigger than /proc/65535/cmdline */
83 snprintf(path
, sizeof(path
), "/proc/%d/cmdline", pid
);
84 fp
= fopen(path
, "r");
89 /* Caller must free() *cmdline */
90 cmdline
= malloc(PATH_MAX
);
91 ret
= fread(cmdline
, 1, PATH_MAX
, fp
);
101 * Ask for all trace events in the kernel and pretty print them.
103 static int list_kernel(void)
106 char *event_list
, *event
, *ptr
;
107 struct lttng_domain dom
;
109 DBG("Getting all tracing events");
111 dom
.type
= LTTNG_DOMAIN_KERNEL
;
113 ret
= lttng_list_events(&dom
, &event_list
);
115 ERR("Unable to list kernel instrumentation");
119 MSG("Kernel tracepoints:\n-------------");
122 while ((size
= sscanf(ptr
, "event { name = %m[^;]; };%n\n", &event
, &pos
)) == 1) {
124 /* Move pointer to the next line */
137 * Get the list of available sessions from the session daemon and print it to
140 static int list_sessions(void)
143 struct lttng_session
*sessions
;
145 count
= lttng_list_sessions(&sessions
);
146 DBG("Session count %d", count
);
152 MSG("Available sessions:");
153 for (i
= 0; i
< count
; i
++) {
154 MSG(" %d) %s (%s)", i
+1, sessions
[i
].name
, sessions
[i
].path
);
168 * Get the UST traceable pid list and print them to the user.
170 static int list_apps(void)
177 //count = lttng_ust_list_traceable_apps(&pids);
183 MSG("LTTng UST traceable application [name (pid)]:");
184 for (i
=0; i
< count
; i
++) {
185 cmdline
= get_cmdline_by_pid(pids
[i
]);
186 if (cmdline
== NULL
) {
187 MSG("\t(not running) (%d)", pids
[i
]);
190 MSG("\t%s (%d)", cmdline
, pids
[i
]);
194 /* Allocated by lttng_ust_list_apps() */
206 * List all instrumentation for a specific pid
209 static int list_pid(int pid)
223 * List all instrumentation for an executable on the system
226 static int list_executable(char *name)
234 * The 'list <options>' first level command
236 int cmd_list(int argc
, const char **argv
)
238 int opt
, ret
= CMD_SUCCESS
;
239 const char *command_name
;
240 static poptContext pc
;
247 pc
= poptGetContext(NULL
, argc
, argv
, long_options
, 0);
248 poptReadDefaultConfig(pc
, 0);
250 while ((opt
= poptGetNextOpt(pc
)) != -1) {
256 ret
= CMD_NOT_IMPLEMENTED
;
265 ret
= list_sessions();
275 //ret = list_pid(pid);
276 ret
= CMD_NOT_IMPLEMENTED
;
279 command_name
= poptGetArg(pc
);
280 if (command_name
!= NULL
) {
281 // ret = list_executable(command_name);
282 ret
= CMD_NOT_IMPLEMENTED
;
This page took 0.034425 seconds and 4 git commands to generate.