# List perf subcommands or long options
        if [ $cword -eq 1 ]; then
                if [[ $cur == --* ]]; then
-                       __perfcomp '--help --version \
-                       --exec-path --html-path --paginate --no-pager \
-                       --perf-dir --work-tree --debugfs-dir' -- "$cur"
+                       cmds=$($cmd --list-opts)
                else
                        cmds=$($cmd --list-cmds)
-                       __perfcomp "$cmds" "$cur"
                fi
+               __perfcomp "$cmds" "$cur"
        # List possible events for -e option
        elif [[ $prev == "-e" && "${words[1]}" == @(record|stat|top) ]]; then
                evts=$($cmd list --raw-dump)
 
 #include "util/quote.h"
 #include "util/run-command.h"
 #include "util/parse-events.h"
+#include "util/parse-options.h"
 #include "util/debug.h"
 #include <api/fs/debugfs.h>
 #include <pthread.h>
        }
 }
 
+struct option options[] = {
+       OPT_ARGUMENT("help", "help"),
+       OPT_ARGUMENT("version", "version"),
+       OPT_ARGUMENT("exec-path", "exec-path"),
+       OPT_ARGUMENT("html-path", "html-path"),
+       OPT_ARGUMENT("paginate", "paginate"),
+       OPT_ARGUMENT("no-pager", "no-pager"),
+       OPT_ARGUMENT("perf-dir", "perf-dir"),
+       OPT_ARGUMENT("work-tree", "work-tree"),
+       OPT_ARGUMENT("debugfs-dir", "debugfs-dir"),
+       OPT_ARGUMENT("buildid-dir", "buildid-dir"),
+       OPT_ARGUMENT("list-cmds", "list-cmds"),
+       OPT_ARGUMENT("list-opts", "list-opts"),
+       OPT_ARGUMENT("debug", "debug"),
+       OPT_END()
+};
+
 static int handle_options(const char ***argv, int *argc, int *envchanged)
 {
        int handled = 0;
                        }
                        putchar('\n');
                        exit(0);
+               } else if (!strcmp(cmd, "--list-opts")) {
+                       unsigned int i;
+
+                       for (i = 0; i < ARRAY_SIZE(options)-1; i++) {
+                               struct option *p = options+i;
+                               printf("--%s ", p->long_name);
+                       }
+                       putchar('\n');
+                       exit(0);
                } else if (!strcmp(cmd, "--debug")) {
                        if (*argc < 2) {
                                fprintf(stderr, "No variable specified for --debug.\n");