perf env: Adopt perf_header__set_cmdline
Move this from two globals to perf_env global, that eventually will be just perf_header->env or something else, to ease the refactoring series, leave it as a global and go on reading more of its fields, not as part of the header writing process but as a perf_env init one that will be used for perf.data-less situations. Tested-by: Wang Nan <wangnan0@huawei.com> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Borislav Petkov <bp@suse.de> Cc: David Ahern <dsahern@gmail.com> Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: Jiri Olsa <jolsa@redhat.com> Cc: Kan Liang <kan.liang@intel.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Stephane Eranian <eranian@google.com> Link: http://lkml.kernel.org/n/tip-2j78tdf8zn1ci0y6ji15bifj@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
parent
eebd0bfca5
commit
b699869285
4 changed files with 49 additions and 40 deletions
|
@ -1,6 +1,8 @@
|
||||||
#include "env.h"
|
#include "env.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
|
struct perf_env perf_env;
|
||||||
|
|
||||||
void perf_env__exit(struct perf_env *env)
|
void perf_env__exit(struct perf_env *env)
|
||||||
{
|
{
|
||||||
zfree(&env->hostname);
|
zfree(&env->hostname);
|
||||||
|
@ -17,3 +19,40 @@ void perf_env__exit(struct perf_env *env)
|
||||||
zfree(&env->pmu_mappings);
|
zfree(&env->pmu_mappings);
|
||||||
zfree(&env->cpu);
|
zfree(&env->cpu);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int perf_env__set_cmdline(struct perf_env *env, int argc, const char *argv[])
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* If env->cmdline_argv has already been set, do not override it. This allows
|
||||||
|
* a command to set the cmdline, parse args and then call another
|
||||||
|
* builtin function that implements a command -- e.g, cmd_kvm calling
|
||||||
|
* cmd_record.
|
||||||
|
*/
|
||||||
|
if (env->cmdline_argv != NULL)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
/* do not include NULL termination */
|
||||||
|
env->cmdline_argv = calloc(argc, sizeof(char *));
|
||||||
|
if (env->cmdline_argv == NULL)
|
||||||
|
goto out_enomem;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Must copy argv contents because it gets moved around during option
|
||||||
|
* parsing:
|
||||||
|
*/
|
||||||
|
for (i = 0; i < argc ; i++) {
|
||||||
|
env->cmdline_argv[i] = argv[i];
|
||||||
|
if (env->cmdline_argv[i] == NULL)
|
||||||
|
goto out_free;
|
||||||
|
}
|
||||||
|
|
||||||
|
env->nr_cmdline = argc;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
out_free:
|
||||||
|
zfree(&env->cmdline_argv);
|
||||||
|
out_enomem:
|
||||||
|
return -ENOMEM;
|
||||||
|
}
|
||||||
|
|
|
@ -32,6 +32,10 @@ struct perf_env {
|
||||||
struct cpu_topology_map *cpu;
|
struct cpu_topology_map *cpu;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
extern struct perf_env perf_env;
|
||||||
|
|
||||||
void perf_env__exit(struct perf_env *env);
|
void perf_env__exit(struct perf_env *env);
|
||||||
|
|
||||||
|
int perf_env__set_cmdline(struct perf_env *env, int argc, const char *argv[]);
|
||||||
|
|
||||||
#endif /* __PERF_ENV_H */
|
#endif /* __PERF_ENV_H */
|
||||||
|
|
|
@ -24,9 +24,6 @@
|
||||||
#include "build-id.h"
|
#include "build-id.h"
|
||||||
#include "data.h"
|
#include "data.h"
|
||||||
|
|
||||||
static u32 header_argc;
|
|
||||||
static const char **header_argv;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* magic2 = "PERFILE2"
|
* magic2 = "PERFILE2"
|
||||||
* must be a numerical value to let the endianness
|
* must be a numerical value to let the endianness
|
||||||
|
@ -138,37 +135,6 @@ static char *do_read_string(int fd, struct perf_header *ph)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
|
||||||
perf_header__set_cmdline(int argc, const char **argv)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* If header_argv has already been set, do not override it.
|
|
||||||
* This allows a command to set the cmdline, parse args and
|
|
||||||
* then call another builtin function that implements a
|
|
||||||
* command -- e.g, cmd_kvm calling cmd_record.
|
|
||||||
*/
|
|
||||||
if (header_argv)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
header_argc = (u32)argc;
|
|
||||||
|
|
||||||
/* do not include NULL termination */
|
|
||||||
header_argv = calloc(argc, sizeof(char *));
|
|
||||||
if (!header_argv)
|
|
||||||
return -ENOMEM;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* must copy argv contents because it gets moved
|
|
||||||
* around during option parsing
|
|
||||||
*/
|
|
||||||
for (i = 0; i < argc ; i++)
|
|
||||||
header_argv[i] = argv[i];
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int write_tracing_data(int fd, struct perf_header *h __maybe_unused,
|
static int write_tracing_data(int fd, struct perf_header *h __maybe_unused,
|
||||||
struct perf_evlist *evlist)
|
struct perf_evlist *evlist)
|
||||||
{
|
{
|
||||||
|
@ -405,8 +371,8 @@ static int write_cmdline(int fd, struct perf_header *h __maybe_unused,
|
||||||
{
|
{
|
||||||
char buf[MAXPATHLEN];
|
char buf[MAXPATHLEN];
|
||||||
char proc[32];
|
char proc[32];
|
||||||
u32 i, n;
|
u32 n;
|
||||||
int ret;
|
int i, ret;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* actual atual path to perf binary
|
* actual atual path to perf binary
|
||||||
|
@ -420,7 +386,7 @@ static int write_cmdline(int fd, struct perf_header *h __maybe_unused,
|
||||||
buf[ret] = '\0';
|
buf[ret] = '\0';
|
||||||
|
|
||||||
/* account for binary path */
|
/* account for binary path */
|
||||||
n = header_argc + 1;
|
n = perf_env.nr_cmdline + 1;
|
||||||
|
|
||||||
ret = do_write(fd, &n, sizeof(n));
|
ret = do_write(fd, &n, sizeof(n));
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
|
@ -430,8 +396,8 @@ static int write_cmdline(int fd, struct perf_header *h __maybe_unused,
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
for (i = 0 ; i < header_argc; i++) {
|
for (i = 0 ; i < perf_env.nr_cmdline; i++) {
|
||||||
ret = do_write_string(fd, header_argv[i]);
|
ret = do_write_string(fd, perf_env.cmdline_argv[i]);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
|
@ -496,7 +496,7 @@ int parse_options_subcommand(int argc, const char **argv, const struct option *o
|
||||||
{
|
{
|
||||||
struct parse_opt_ctx_t ctx;
|
struct parse_opt_ctx_t ctx;
|
||||||
|
|
||||||
perf_header__set_cmdline(argc, argv);
|
perf_env__set_cmdline(&perf_env, argc, argv);
|
||||||
|
|
||||||
/* build usage string if it's not provided */
|
/* build usage string if it's not provided */
|
||||||
if (subcommands && !usagestr[0]) {
|
if (subcommands && !usagestr[0]) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue