1 /* Copyright (C) 2021-2023 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 Gprofng
*gprofng
= new Gprofng (argc
, argv
);
58 Gprofng::Gprofng (int _argc
, char *_argv
[]) : Application(_argc
, _argv
, NULL
)
64 Gprofng::~Gprofng () { }
70 * Isolate the first line because it has an argument.
71 * Otherwise it would be at the end of this long list.
74 "Usage: %s [OPTION(S)] COMMAND [KEYWORD] [ARGUMENTS]\n"), whoami
);
78 "This is the driver for the GPROFNG tools suite to gather and analyze performance data.\n"
82 " --version print the version number and exit.\n"
83 " --help print usage information and exit.\n"
84 " --check verify if the hardware and software environment is supported.\n"
85 " --verbose {on|off} enable (on) or disable (off) verbose mode; the default is \"off\".\n"
89 "The driver supports various commands. These are listed below.\n"
91 "It is also possible to invoke the lower level commands directly, but since these \n"
92 "are subject to change, in particular the options, we recommend to use the driver.\n"
94 "The man pages for the commands below can be viewed using the command name with\n"
95 "\"gprofng\" replaced by \"gp\" and the spaces replaced by a dash (\"-\"). For\n"
96 "example the man page name for \"gprofng collect app\" is \"gp-collect-app\".\n"
98 "The following combination of commands and keywords are supported:\n"
100 "Collect performance data\n"
102 " gprofng collect app collect application performance data.\n"
104 "Display the performance results\n"
106 " gprofng display text display the performance data in ASCII format.\n"
107 " gprofng display html generate an HTML file from one or more experiments.\n"
109 " gprofng display gui invoke the GUI to graphically analyze the results.\n"
111 " gprofng display src display source or disassembly with compiler annotations.\n"
113 "Miscellaneous commands\n"
115 " gprofng archive include binaries and source code in an experiment directory.\n"
119 "The following environment variables are supported:\n"
121 " GPROFNG_MAX_CALL_STACK_DEPTH set the depth of the call stack (default is 256).\n"
123 " GPROFNG_USE_JAVA_OPTIONS may be set when profiling a C/C++ application\n"
124 " that uses dlopen() to execute Java code.\n"
126 " GPROFNG_SSH_REMOTE_DISPLAY use this variable to define the ssh command\n"
127 " executed by the remote display tool.\n"
129 " GPROFNG_SKIP_VALIDATION set this variable to disable checking hardware,\n"
130 " system, and Java versions.\n"
132 " GPROFNG_ALLOW_CORE_DUMP set this variable to allow a core file to be\n"
133 " generated; otherwise an error report is created on /tmp.\n"
135 " GPROFNG_ARCHIVE use this variable to define the settings for automatic\n"
136 " archiving upon experiment recording completion.\n"
138 " GPROFNG_ARCHIVE_COMMON_DIR set this variable to the location of the common archive.\n"
140 " GPROFNG_JAVA_MAX_CALL_STACK_DEPTH set the depth of the Java call stack; the default\n"
141 " is 256; set to 0 to disable capturing of call stacks.\n"
143 " GPROFNG_JAVA_NATIVE_MAX_CALL_STACK_DEPTH set the depth of the Java native call stack;\n"
144 " the default is 256; set to 0 to disable capturing\n"
145 " of call stacks (JNI and assembly call stacks\n"
146 " are not captured).\n"
150 "A getting started guide for gprofng is maintained as a Texinfo manual. If the info and\n"
151 "gprofng programs are properly installed at your site, the command \"info gprofng\"\n"
152 "should give you access to this document.\n"
156 "gp-archive(1), gp-collect-app(1), gp-display-html(1), gp-display-src(1), gp-display-text(1)\n"));
160 "Usage: %s [--verbose] [--version] [--help] <tool-name> [<keyword>] <args>\n"
162 " archive Archive binaries and sources\n"
163 " collect [app] Collect performance data\n"
164 " display [text] Print an ASCII report\n"
165 " display gui Graphical tool for analyzing an experiment\n"
166 " display html Generate an HTML file from an experiment\n"
167 " display src Print source or dissasembly\n"),
168 whoami, getenv ("_BUILDING_MANPAGE")
169 ? "*Available subcommands*"
170 : "Available Subcommands");
175 Gprofng::exec_cmd (char *tool_name
, int argc
, char **argv
)
179 const char *tool_name
;
181 const char *app_name
;
183 { "archive", NULL
, "gp-archive"},
184 { "collect", "app", "gp-collect-app"},
185 { "collect", "kernel", "gp-collect-kernel"},
186 { "display", "text", "gp-display-text"},
187 { "display", "gui", "gp-display-gui"},
188 { "display", "html", "gp-display-html"},
189 { "display", "src", "gp-display-src"},
193 const char *keyword
= argc
> 1 ? argv
[1] : "";
195 int find_tool_name
= -1;
196 for (int i
= 0; app_names
[i
].tool_name
; i
++)
197 if (!strcmp (tool_name
, app_names
[i
].tool_name
))
199 if (app_names
[i
].keyword
== NULL
)
204 if (!strcmp (keyword
, app_names
[i
].keyword
))
211 if (find_tool_name
== -1)
217 if (find_tool_name
== -1)
218 fprintf (stderr
, GTXT ("%s: error: keyword '%s' is not supported\n"),
219 get_basename (get_name ()), tool_name
);
220 else if (*keyword
== 0)
221 fprintf (stderr
, GTXT ("%s %s: error: no qualifier\n"),
222 get_basename (get_name ()), tool_name
);
224 fprintf (stderr
, GTXT ("%s %s: error: qualifier '%s' is not supported\n"),
225 get_basename (get_name ()), tool_name
, keyword
);
229 const char *aname
= app_names
[first
].app_name
;;
231 char **arr
= (char **) malloc ((argc
+ 3) * sizeof (char *));
233 char *pname
= get_name ();
234 arr
[n
++] = dbe_sprintf ("%.*s%s", (int) (get_basename (pname
) - pname
),
236 if (app_names
[first
].keyword
)
237 arr
[n
++] = dbe_sprintf ("--whoami=%s %s %s", whoami
, tool_name
,
238 app_names
[first
].keyword
);
240 arr
[n
++] = dbe_sprintf ("--whoami=%s %s", whoami
, tool_name
);
241 for (int i
= 1; i
< argc
; i
++)
246 printf ("gprofng::exec\n");
247 for (int i
= 0; arr
[i
]; i
++)
248 printf ("%5d: %s\n", i
, arr
[i
]);
253 // If execv returns, it must have failed.
254 fprintf (stderr
, GTXT ("%s failed: %s\n"), arr
[0], STR (strerror (errno
)));
266 for (int i
= 1; i
< argc
; i
++)
271 exec_cmd(s
, argc
- i
, argv
+ i
);
274 else if (!strcmp (s
, "--help"))
279 else if (!strcmp (s
, "--version") || !strcmp (s
, "-v"))
281 Application::print_version_info ();
284 else if (!strcmp (s
, "--verbose"))
286 else if (!strcmp (s
, "--check"))
288 fprintf (stderr
, GTXT ("%s: error: --check is not implemented yet\n"),
289 get_basename (get_name ()));
294 fprintf (stderr
, GTXT ("%s: error: unknown option %s\n"),
295 get_basename (get_name ()), s
);
299 fprintf (stderr
, GTXT ("%s: error: expected argument after options\n"),
300 get_basename (get_name ()));