From: Amit Kucheria amit.kucheria@linaro.org
More cleanups to the command-line options to make idlestat easier to use and separate the two modes: tracing and reporting.
Regards, Amit
Amit Kucheria (6): Use the correct version in the log file Print more details when fopen fails kick the dump option off to use -z and release -m for later -o stands for output file when idlestat can take an input file as well Introduce --trace and --import mode Lots of changes related to usage, bump the version to 0.3
README | 10 ++++----- idlestat.c | 71 +++++++++++++++++++++++++++++++++++++++++++------------------- 2 files changed, 54 insertions(+), 27 deletions(-)
From: Amit Kucheria amit.kucheria@linaro.org
Signed-off-by: Amit Kucheria amit.kucheria@linaro.org --- idlestat.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/idlestat.c b/idlestat.c index 9228618..9d88ee9 100644 --- a/idlestat.c +++ b/idlestat.c @@ -1085,7 +1085,7 @@ static int idlestat_store(const char *path) return -1; }
- fprintf(f, "version = 1\n"); + fprintf(f, "version = %s\n", IDLESTAT_VERSION); fprintf(f, "cpus=%d\n", ret);
/* output topology information */
From: Amit Kucheria amit.kucheria@linaro.org
Useful for tracking down why the following command fails: sudo ./idlestat -o /tmp/newfile
where, newfile doesn't already exist
Signed-off-by: Amit Kucheria amit.kucheria@linaro.org --- idlestat.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/idlestat.c b/idlestat.c index 9d88ee9..998f62d 100644 --- a/idlestat.c +++ b/idlestat.c @@ -749,8 +749,10 @@ static struct cpuidle_datas *idlestat_load(const char *path) int ret;
f = fopen(path, "r"); - if (!f) - return ptrerror("fopen"); + if (!f) { + fprintf(stderr, "%s: failed to open '%s': %m\n", __func__, path); + return NULL; + }
/* version line */ fgets(buffer, BUFSIZE, f); @@ -1055,7 +1057,7 @@ static int idlestat_file_for_each_line(const char *path, void *data, f = fopen(path, "r");
if (!f) { - fprintf(stderr, "failed to open '%s': %m\n", path); + fprintf(stderr, "%s: failed to open '%s': %m\n", __func__, path); return -1; }
@@ -1080,8 +1082,9 @@ static int idlestat_store(const char *path) return -1;
f = fopen(path, "w+"); + if (!f) { - fprintf(f, "failed to open '%s': %m\n", path); + fprintf(f, "%s: failed to open '%s': %m\n", __func__, path); return -1; }
Hello Amit,
In the last section f should be 'stderr' in fprintf -
@@ -1080,8 +1082,9 @@ static int idlestat_store(const char *path) return -1;
f = fopen(path, "w+"); + if (!f) { - fprintf(f, "failed to open '%s': %m\n", path); + fprintf(f, "%s: failed to open '%s': %m\n", __func__, path); return -1; }
On Mon, Jun 2, 2014 at 6:49 PM, Amit Kucheria amit.kucheria@verdurent.com wrote:
From: Amit Kucheria amit.kucheria@linaro.org
Useful for tracking down why the following command fails: sudo ./idlestat -o /tmp/newfile
where, newfile doesn't already exist
Signed-off-by: Amit Kucheria amit.kucheria@linaro.org
idlestat.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/idlestat.c b/idlestat.c index 9d88ee9..998f62d 100644 --- a/idlestat.c +++ b/idlestat.c @@ -749,8 +749,10 @@ static struct cpuidle_datas *idlestat_load(const char *path) int ret;
f = fopen(path, "r");
if (!f)
return ptrerror("fopen");
if (!f) {
fprintf(stderr, "%s: failed to open '%s': %m\n", __func__, path);
return NULL;
} /* version line */ fgets(buffer, BUFSIZE, f);
@@ -1055,7 +1057,7 @@ static int idlestat_file_for_each_line(const char *path, void *data, f = fopen(path, "r");
if (!f) {
fprintf(stderr, "failed to open '%s': %m\n", path);
fprintf(stderr, "%s: failed to open '%s': %m\n", __func__, path); return -1; }
@@ -1080,8 +1082,9 @@ static int idlestat_store(const char *path) return -1;
f = fopen(path, "w+");
if (!f) {
fprintf(f, "failed to open '%s': %m\n", path);
fprintf(f, "%s: failed to open '%s': %m\n", __func__, path); return -1; }
-- 1.9.1
From: Amit Kucheria amit.kucheria@linaro.org
Signed-off-by: Amit Kucheria amit.kucheria@linaro.org --- idlestat.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/idlestat.c b/idlestat.c index 998f62d..233d554 100644 --- a/idlestat.c +++ b/idlestat.c @@ -948,7 +948,7 @@ struct cpuidle_cstates *physical_cluster_data(struct cpu_physical *s_phy) static void help(const char *cmd) { fprintf(stderr, - "\nUsage:\n%s -o|--output-file <file> [-m|--dump]" + "\nUsage:\n%s -o|--output-file <file> [-z|--dump]" " [-t|--duration <seconds>] [-i|--iterations <number>]" " [-d|--debug]\n", basename(cmd)); @@ -975,10 +975,10 @@ int getoptions(int argc, char *argv[], struct program_options *options) { "debug", no_argument, NULL, 'd' }, { "help", no_argument, NULL, 'h' }, { "iterations", required_argument, NULL, 'i' }, - { "dump", no_argument, NULL, 'm' }, { "output-file", required_argument, NULL, 'o' }, { "duration", required_argument, NULL, 't' }, { "version", no_argument, NULL, 'V' }, + { "dump", no_argument, NULL, 'z' }, { 0, 0, 0, 0 } }; int c; @@ -990,7 +990,7 @@ int getoptions(int argc, char *argv[], struct program_options *options)
int optindex = 0;
- c = getopt_long(argc, argv, ":dhi:mo:t:V", + c = getopt_long(argc, argv, ":dhi:o:t:Vz", long_options, &optindex); if (c == -1) break; @@ -1006,9 +1006,6 @@ int getoptions(int argc, char *argv[], struct program_options *options) case 'i': options->iterations = atoi(optarg); break; - case 'm': - options->dump = true; - break; case 'o': options->filename = optarg; break; @@ -1019,6 +1016,9 @@ int getoptions(int argc, char *argv[], struct program_options *options) version(argv[0]); exit(0); break; + case 'z': + options->dump = true; + break; case 0: /* getopt_long() set a variable, just keep going */ break; case ':': /* missing option argument */
From: Amit Kucheria amit.kucheria@linaro.org
idlestat can take a pre-created tracefile as input or create one itself. The -o option is confusing for an input file. Change it to -f in preparation for a new option to signify what the file name is to be used for.
Signed-off-by: Amit Kucheria amit.kucheria@linaro.org --- README | 4 ++-- idlestat.c | 16 ++++++++-------- 2 files changed, 10 insertions(+), 10 deletions(-)
diff --git a/README b/README index 24485c5..1a917b4 100644 --- a/README +++ b/README @@ -35,10 +35,10 @@ Help Example Usage -------------
-./idlestat -o /tmp/myoutput -t 10 +./idlestat -f /tmp/myoutput -t 10
where,
--o : output file to store the traces +-f : output file to store the traces -t : the duration in seconds
diff --git a/idlestat.c b/idlestat.c index 233d554..5320155 100644 --- a/idlestat.c +++ b/idlestat.c @@ -948,12 +948,12 @@ struct cpuidle_cstates *physical_cluster_data(struct cpu_physical *s_phy) static void help(const char *cmd) { fprintf(stderr, - "\nUsage:\n%s -o|--output-file <file> [-z|--dump]" + "\nUsage:\n%s -f|--trace-file <file> [-z|--dump]" " [-t|--duration <seconds>] [-i|--iterations <number>]" " [-d|--debug]\n", basename(cmd)); fprintf(stderr, - "\nExample:\n%s -o /tmp/myoutput -t 30\n", basename(cmd)); + "\nExample:\n%s -f /tmp/myoutput -t 30\n", basename(cmd)); }
static void version(const char *cmd) @@ -973,9 +973,9 @@ int getoptions(int argc, char *argv[], struct program_options *options) { struct option long_options[] = { { "debug", no_argument, NULL, 'd' }, + { "trace-file", required_argument, NULL, 'f' }, { "help", no_argument, NULL, 'h' }, { "iterations", required_argument, NULL, 'i' }, - { "output-file", required_argument, NULL, 'o' }, { "duration", required_argument, NULL, 't' }, { "version", no_argument, NULL, 'V' }, { "dump", no_argument, NULL, 'z' }, @@ -990,7 +990,7 @@ int getoptions(int argc, char *argv[], struct program_options *options)
int optindex = 0;
- c = getopt_long(argc, argv, ":dhi:o:t:Vz", + c = getopt_long(argc, argv, ":df:hi:t:Vz", long_options, &optindex); if (c == -1) break; @@ -999,6 +999,9 @@ int getoptions(int argc, char *argv[], struct program_options *options) case 'd': options->debug = true; break; + case 'f': + options->filename = optarg; + break; case 'h': help(argv[0]); exit(0); @@ -1006,9 +1009,6 @@ int getoptions(int argc, char *argv[], struct program_options *options) case 'i': options->iterations = atoi(optarg); break; - case 'o': - options->filename = optarg; - break; case 't': options->duration = atoi(optarg); break; @@ -1038,7 +1038,7 @@ int getoptions(int argc, char *argv[], struct program_options *options) fprintf(stderr, "dump values must be a positive value\n");
if (NULL == options->filename) { - fprintf(stderr, "expected -o <filename>\n"); + fprintf(stderr, "expected -f <trace filename>\n"); return -1; }
From: Amit Kucheria amit.kucheria@linaro.org
--trace will create a local trace and use that for the report --import will import an existing trace
Signed-off-by: Amit Kucheria amit.kucheria@linaro.org --- README | 10 ++++------ idlestat.c | 36 +++++++++++++++++++++++++++++++----- 2 files changed, 35 insertions(+), 11 deletions(-)
diff --git a/README b/README index 1a917b4..3bd48ed 100644 --- a/README +++ b/README @@ -35,10 +35,8 @@ Help Example Usage -------------
-./idlestat -f /tmp/myoutput -t 10 - -where, - --f : output file to store the traces --t : the duration in seconds +Trace mode: +sudo ./idlestat --trace -f /tmp/myoutput -t 10
+Reporing mode (/tmp/mytrace already contains traces): +sudo ./idlestat --import -f /tmp/mytrace diff --git a/idlestat.c b/idlestat.c index 5320155..a5619a9 100644 --- a/idlestat.c +++ b/idlestat.c @@ -948,12 +948,18 @@ struct cpuidle_cstates *physical_cluster_data(struct cpu_physical *s_phy) static void help(const char *cmd) { fprintf(stderr, - "\nUsage:\n%s -f|--trace-file <file> [-z|--dump]" - " [-t|--duration <seconds>] [-i|--iterations <number>]" - " [-d|--debug]\n", + "\nUsage:\nTrace mode: %s --trace -f|--trace-file <filename>" + " -t|--duration <seconds> " + "[-z|--dump] [-i|--iterations <number>] [-d|--debug]\n", basename(cmd)); fprintf(stderr, - "\nExample:\n%s -f /tmp/myoutput -t 30\n", basename(cmd)); + "\nReporting mode: %s --import -f|--trace-file <filename>" + "[-z|--dump] [-i|--iterations <number>] [-d|--debug]\n", + basename(cmd)); + fprintf(stderr, + "\nExample:\n%s --trace -f /tmp/myoutput -t 30\n", basename(cmd)); + fprintf(stderr, + "\nExample:\n%s --import -f /tmp/mytrace\n", basename(cmd)); }
static void version(const char *cmd) @@ -961,10 +967,16 @@ static void version(const char *cmd) printf("%s version %s\n", basename(cmd), IDLESTAT_VERSION); }
+enum modes { + TRACE=1, + IMPORT +}; + struct program_options { bool debug; bool dump; int iterations; + int mode; unsigned int duration; char *filename; }; @@ -972,6 +984,8 @@ struct program_options { int getoptions(int argc, char *argv[], struct program_options *options) { struct option long_options[] = { + { "trace", no_argument, &options->mode, TRACE }, + { "import", no_argument, &options->mode, IMPORT }, { "debug", no_argument, NULL, 'd' }, { "trace-file", required_argument, NULL, 'f' }, { "help", no_argument, NULL, 'h' }, @@ -1037,11 +1051,23 @@ int getoptions(int argc, char *argv[], struct program_options *options) if (options->iterations < 0) fprintf(stderr, "dump values must be a positive value\n");
+ if (options->mode <= 0) { + fprintf(stderr, "select a mode: --trace or --import\n"); + return -1; + } + if (NULL == options->filename) { fprintf(stderr, "expected -f <trace filename>\n"); return -1; }
+ if (options->mode == TRACE) { + if (options->duration <= 0) { + fprintf(stderr, "expected -t <seconds>\n"); + return -1; + } + } + return optind; }
@@ -1213,7 +1239,7 @@ int main(int argc, char *argv[], char *const envp[]) init_cpu_topo_info();
/* Acquisition time specified means we will get the traces */ - if (options.duration || args < argc) { + if ((options.mode == TRACE) || args < argc) {
/* Read cpu topology info from sysfs */ read_sysfs_cpu_topo();
From: Amit Kucheria amit.kucheria@linaro.org
Signed-off-by: Amit Kucheria amit.kucheria@linaro.org --- idlestat.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/idlestat.c b/idlestat.c index a5619a9..787d7b0 100644 --- a/idlestat.c +++ b/idlestat.c @@ -46,7 +46,7 @@ #include "list.h" #include "topology.h"
-#define IDLESTAT_VERSION "0.3-rc2" +#define IDLESTAT_VERSION "0.3"
static char irq_type_name[][8] = { "irq",
On 06/02/2014 02:49 PM, Amit Kucheria wrote:
From: Amit Kucheria amit.kucheria@linaro.org
More cleanups to the command-line options to make idlestat easier to use and separate the two modes: tracing and reporting.
Regards, Amit
Amit Kucheria (6): Use the correct version in the log file Print more details when fopen fails kick the dump option off to use -z and release -m for later -o stands for output file when idlestat can take an input file as well Introduce --trace and --import mode Lots of changes related to usage, bump the version to 0.3
README | 10 ++++----- idlestat.c | 71 +++++++++++++++++++++++++++++++++++++++++++------------------- 2 files changed, 54 insertions(+), 27 deletions(-)
For the whole series:
Acked-by: Daniel Lezcano daniel.lezcano@linaro.org
Thanks. Pushed out to git.
On Tue, Jun 3, 2014 at 6:08 PM, Daniel Lezcano daniel.lezcano@linaro.org wrote:
On 06/02/2014 02:49 PM, Amit Kucheria wrote:
From: Amit Kucheria amit.kucheria@linaro.org
More cleanups to the command-line options to make idlestat easier to use and separate the two modes: tracing and reporting.
Regards, Amit
Amit Kucheria (6): Use the correct version in the log file Print more details when fopen fails kick the dump option off to use -z and release -m for later -o stands for output file when idlestat can take an input file as well Introduce --trace and --import mode Lots of changes related to usage, bump the version to 0.3
README | 10 ++++----- idlestat.c | 71 +++++++++++++++++++++++++++++++++++++++++++------------------- 2 files changed, 54 insertions(+), 27 deletions(-)
For the whole series:
Acked-by: Daniel Lezcano daniel.lezcano@linaro.org
-- http://www.linaro.org/ Linaro.org │ Open source software for ARM SoCs
Follow Linaro: http://www.facebook.com/pages/Linaro Facebook | http://twitter.com/#!/linaroorg Twitter | http://www.linaro.org/linaro-blog/ Blog