summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEugeni Dodonov <eugeni.dodonov@intel.com>2011-11-06 23:02:55 -0200
committerEugeni Dodonov <eugeni.dodonov@intel.com>2011-11-09 11:45:42 -0200
commit489b2ea4dd5f294a6650d1d42314d1fbeede174c (patch)
treeb9951ad17307e56fa19a6d53b9e38e0379130d1c
parentea23a4e0f3ecb16f04a1b0bf3b375dc47baa2cad (diff)
intel_gpu_top: allow recording perf stats
This allows to record perf statistics when using '-p' switch. Together with non-interactive monitoring, this allows for a much more fine-grained results analysis. Signed-off-by: Eugeni Dodonov <eugeni.dodonov@intel.com>
-rw-r--r--man/intel_gpu_top.15
-rw-r--r--tools/intel_gpu_top.c48
2 files changed, 51 insertions, 2 deletions
diff --git a/man/intel_gpu_top.1 b/man/intel_gpu_top.1
index 1a483fc..412604a 100644
--- a/man/intel_gpu_top.1
+++ b/man/intel_gpu_top.1
@@ -24,6 +24,11 @@ and output statistics to stdout.
execute a command, and leave when it is finished. Note that the entire command
with all parameters should be included as one parameter.
.TP
+.B -p
+record system-wide statistics during the monitoring via "perf record" facility.
+If an output file is specified, the results will be saved into "output_file.perf".
+Otherwise, results will be saved into "perf.data".
+.TP
.B -h
show usage notes
.SH EXAMPLES
diff --git a/tools/intel_gpu_top.c b/tools/intel_gpu_top.c
index eeff1fa..cdf40d3 100644
--- a/tools/intel_gpu_top.c
+++ b/tools/intel_gpu_top.c
@@ -497,6 +497,7 @@ usage(const char *appname)
"The following parameters apply:\n"
"[-s <samples>] samples per seconds (default %d)\n"
"[-e <command>] command to profile\n"
+ "[-p] profile with kperf (Linux-specific)\n"
"[-o <file>] output statistics to file. If file is '-',"
" run in batch mode and output statistics to stdio only \n"
"[-h] show this help screen\n"
@@ -537,10 +538,12 @@ int main(int argc, char **argv)
struct cpudata oldcpu, cpu;
struct powerdata power;
char *battery = BATTERY, *battery_file = NULL;
+ int do_perf=0;
+ char *perf_output=NULL;
#endif
/* Parse options? */
- while ((ch = getopt(argc, argv, "s:o:e:h")) != -1) {
+ while ((ch = getopt(argc, argv, "s:o:e:ph")) != -1) {
switch (ch) {
case 'e': cmd = strdup(optarg);
break;
@@ -556,14 +559,25 @@ int main(int argc, char **argv)
interactive = 0;
output = stdout;
}
- else
+ else {
output = fopen(optarg, "w");
+ perf_output = (char *)malloc(strlen(optarg) + 5);
+ sprintf(perf_output, "%s.perf", optarg);
+ }
if (!output)
{
perror("fopen");
exit(1);
}
break;
+ case 'p':
+#ifndef HAVE_LINUX_FEATURES
+ fprintf(stderr, "Error: Linux-specific bits not enabled\n");
+ exit(1);
+#else
+ do_perf=1;
+#endif
+ break;
case 'h':
usage(argv[0]);
exit(0);
@@ -583,6 +597,33 @@ int main(int argc, char **argv)
intel_get_mmio(pci_dev);
init_instdone_definitions(devid);
+#ifdef HAVE_LINUX_FEATURES
+ if (do_perf) {
+ int perf_pid = fork();
+ if (perf_pid < 0) {
+ perror("fork");
+ exit(1);
+ }
+ if (perf_pid > 0) {
+ const char *perf_cmd = "perf record -a";
+ int res;
+ if (perf_output) {
+ /* Output to a log file */
+ char *cmdline = (char *)malloc(strlen(perf_cmd) +
+ strlen(perf_output) + 4);
+ sprintf(cmdline, "%s -o %s", perf_cmd, perf_output);
+ res = system(cmdline);
+ free(cmdline);
+ } else {
+ res = system("perf record -a");
+ }
+ if (res < 0)
+ perror("Running perf");
+ exit(0);
+ }
+ }
+#endif
+
/* Do we have a command to run? */
if (cmd != NULL) {
if (output) {
@@ -843,5 +884,8 @@ int main(int argc, char **argv)
fclose(output);
intel_register_access_fini();
+ if (perf_output != NULL)
+ free(perf_output);
+
return 0;
}