1 /* Copyright (C) 2021-2024 Free Software Foundation, Inc.
4 This file is part of GNU Binutils.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3, or (at your option)
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, 51 Franklin Street - Fifth Floor, Boston,
19 MA 02110-1301, USA. */
29 #include "Application.h"
33 static int verbose
= 0;
35 class Gprofng
: Application
38 Gprofng (int _argc
, char *_argv
[]);
44 void exec_cmd(char *tool_name
, int argc
, char **argv
);
50 main (int argc
, char *argv
[])
52 xmalloc_set_program_name (argv
[0]);
53 Gprofng
*gprofng
= new Gprofng (argc
, argv
);
59 Gprofng::Gprofng (int _argc
, char *_argv
[]) : Application(_argc
, _argv
, NULL
)
65 Gprofng::~Gprofng () { }
71 * Isolate the first line because it has an argument.
72 * Otherwise it would be at the end of this long list.
75 "Usage: %s [OPTION(S)] COMMAND [KEYWORD] [ARGUMENTS]\n"), whoami
);
79 "This is the driver for the GPROFNG tools suite to gather and analyze performance data.\n"
83 " --version print the version number and exit.\n"
84 " --help print usage information and exit.\n"
85 " --check verify if the hardware and software environment is supported.\n"
86 " --verbose {on|off} enable (on) or disable (off) verbose mode; the default is \"off\".\n"
90 "The driver supports various commands. These are listed below.\n"
92 "It is also possible to invoke the lower level commands directly, but since these \n"
93 "are subject to change, in particular the options, we recommend to use the driver.\n"
95 "The man pages for the commands below can be viewed using the command name with\n"
96 "\"gprofng\" replaced by \"gp\" and the spaces replaced by a dash (\"-\"). For\n"
97 "example the man page name for \"gprofng collect app\" is \"gp-collect-app\".\n"
99 "The following combination of commands and keywords are supported:\n"
101 "Collect performance data\n"
103 " gprofng collect app collect application performance data.\n"
105 "Display the performance results\n"
107 " gprofng display text display the performance data in ASCII format.\n"
108 " gprofng display html generate an HTML file from one or more experiments.\n"
110 " gprofng display gui invoke the GUI to graphically analyze the results.\n"
112 " gprofng display src display source or disassembly with compiler annotations.\n"
114 "Miscellaneous commands\n"
116 " gprofng archive include binaries and source code in an experiment directory.\n"
120 "The following environment variables are supported:\n"
122 " GPROFNG_MAX_CALL_STACK_DEPTH set the depth of the call stack (default is 256).\n"
124 " GPROFNG_USE_JAVA_OPTIONS may be set when profiling a C/C++ application\n"
125 " that uses dlopen() to execute Java code.\n"
127 " GPROFNG_SSH_REMOTE_DISPLAY use this variable to define the ssh command\n"
128 " executed by the remote display tool.\n"
130 " GPROFNG_SKIP_VALIDATION set this variable to disable checking hardware,\n"
131 " system, and Java versions.\n"
133 " GPROFNG_ALLOW_CORE_DUMP set this variable to allow a core file to be\n"
134 " generated; otherwise an error report is created on /tmp.\n"
136 " GPROFNG_ARCHIVE use this variable to define the settings for automatic\n"
137 " archiving upon experiment recording completion.\n"
139 " GPROFNG_ARCHIVE_COMMON_DIR set this variable to the location of the common archive.\n"
141 " GPROFNG_JAVA_MAX_CALL_STACK_DEPTH set the depth of the Java call stack; the default\n"
142 " is 256; set to 0 to disable capturing of call stacks.\n"
144 " GPROFNG_JAVA_NATIVE_MAX_CALL_STACK_DEPTH set the depth of the Java native call stack;\n"
145 " the default is 256; set to 0 to disable capturing\n"
146 " of call stacks (JNI and assembly call stacks\n"
147 " are not captured).\n"
151 "A getting started guide for gprofng is maintained as a Texinfo manual. If the info and\n"
152 "gprofng programs are properly installed at your site, the command \"info gprofng\"\n"
153 "should give you access to this document.\n"
157 "gp-archive(1), gp-collect-app(1), gp-display-html(1), gp-display-src(1), gp-display-text(1)\n"));
161 "Usage: %s [--verbose] [--version] [--help] <tool-name> [<keyword>] <args>\n"
163 " archive Archive binaries and sources\n"
164 " collect [app] Collect performance data\n"
165 " display [text] Print an ASCII report\n"
166 " display gui Graphical tool for analyzing an experiment\n"
167 " display html Generate an HTML file from an experiment\n"
168 " display src Print source or dissasembly\n"),
169 whoami, getenv ("_BUILDING_MANPAGE")
170 ? "*Available subcommands*"
171 : "Available Subcommands");
176 Gprofng::exec_cmd (char *tool_name
, int argc
, char **argv
)
180 const char *tool_name
;
182 const char *app_name
;
184 { "archive", NULL
, "gp-archive"},
185 { "collect", "app", "gp-collect-app"},
186 { "collect", "kernel", "gp-collect-kernel"},
187 { "display", "text", "gp-display-text"},
188 { "display", "gui", "gp-display-gui"},
189 { "display", "html", "gp-display-html"},
190 { "display", "src", "gp-display-src"},
194 const char *keyword
= argc
> 1 ? argv
[1] : "";
196 int find_tool_name
= -1;
197 for (int i
= 0; app_names
[i
].tool_name
; i
++)
198 if (!strcmp (tool_name
, app_names
[i
].tool_name
))
200 if (app_names
[i
].keyword
== NULL
)
205 if (!strcmp (keyword
, app_names
[i
].keyword
))
212 if (find_tool_name
== -1)
218 if (find_tool_name
== -1)
219 fprintf (stderr
, GTXT ("%s: error: keyword '%s' is not supported\n"),
220 get_basename (get_name ()), tool_name
);
221 else if (*keyword
== 0)
222 fprintf (stderr
, GTXT ("%s %s: error: no qualifier\n"),
223 get_basename (get_name ()), tool_name
);
225 fprintf (stderr
, GTXT ("%s %s: error: qualifier '%s' is not supported\n"),
226 get_basename (get_name ()), tool_name
, keyword
);
230 const char *aname
= app_names
[first
].app_name
;
232 char **arr
= (char **) xmalloc ((argc
+ 5) * sizeof (char *));
233 char *pname
= get_name ();
234 char *exe_name
= dbe_sprintf ("%.*s%s",
235 (int) (get_basename (pname
) - pname
), pname
, aname
);
237 if (app_names
[first
].keyword
)
238 arr
[n
++] = dbe_sprintf ("--whoami=%s %s %s", whoami
, tool_name
,
239 app_names
[first
].keyword
);
241 arr
[n
++] = dbe_sprintf ("--whoami=%s %s", whoami
, tool_name
);
242 if (strcmp (aname
, "gp-display-gui") == 0)
244 if (access (exe_name
, X_OK
| F_OK
) != 0)
245 { // gprofng GUI can be installed to the other directory.
247 printf ("gprofng: Cannot find '%s'\n", exe_name
);
249 exe_name
= get_realpath (aname
); // Use $PATH to find gprofng GUI
251 arr
[n
++] = dbe_sprintf ("--gprofngdir=%.*s",
252 (int) (get_basename (pname
) - pname
), pname
);
254 for (int i
= 1; i
< argc
; i
++)
260 printf ("gprofng::exec\n");
261 for (int i
= 0; arr
[i
]; i
++)
262 printf ("%5d: %s\n", i
, arr
[i
]);
267 // If execv returns, it must have failed.
268 fprintf (stderr
, GTXT ("%s failed: %s\n"), arr
[0], STR (strerror (errno
)));
280 for (int i
= 1; i
< argc
; i
++)
285 exec_cmd(s
, argc
- i
, argv
+ i
);
288 else if (!strcmp (s
, "--help"))
293 else if (!strcmp (s
, "--version") || !strcmp (s
, "-v"))
295 Application::print_version_info ();
298 else if (!strcmp (s
, "--verbose"))
300 else if (!strcmp (s
, "--check"))
302 fprintf (stderr
, GTXT ("%s: error: --check is not implemented yet\n"),
303 get_basename (get_name ()));
308 fprintf (stderr
, GTXT ("%s: error: unknown option %s\n"),
309 get_basename (get_name ()), s
);
313 fprintf (stderr
, GTXT ("%s: error: expected argument after options\n"),
314 get_basename (get_name ()));