aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWang Nan <wangnan0@huawei.com>2016-04-20 14:59:49 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2016-04-28 08:58:58 -0400
commit5f9cf5992cfb9d9763fb92f755642dda8f9e844f (patch)
tree2bdd6c72dc0f8dd3f6df3633d591767254978886
parent3dcc4436fa6f09ce093ff59bf8477c3059dc46df (diff)
perf tools: Derive trigger class from auxtrace_snapshot
auxtrace_snapshot_state matches the trigger model. Use trigger to implement it. auxtrace_snapshot_state and auxtrace_snapshot_err are absorbed. Signed-off-by: Wang Nan <wangnan0@huawei.com> Acked-by: Adrian Hunter <adrian.hunter@intel.com> Cc: He Kuang <hekuang@huawei.com> Cc: Jiri Olsa <jolsa@redhat.com> Cc: Masami Hiramatsu <mhiramat@kernel.org> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Zefan Li <lizefan@huawei.com> Cc: pi3orama@163.com Link: http://lkml.kernel.org/r/1461178794-40467-3-git-send-email-wangnan0@huawei.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r--tools/perf/builtin-record.c73
1 files changed, 20 insertions, 53 deletions
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index bd9593346bb2..f4710c82980f 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -34,6 +34,7 @@
34#include "util/parse-regs-options.h" 34#include "util/parse-regs-options.h"
35#include "util/llvm-utils.h" 35#include "util/llvm-utils.h"
36#include "util/bpf-loader.h" 36#include "util/bpf-loader.h"
37#include "util/trigger.h"
37#include "asm/bug.h" 38#include "asm/bug.h"
38 39
39#include <unistd.h> 40#include <unistd.h>
@@ -127,44 +128,8 @@ static volatile int done;
127static volatile int signr = -1; 128static volatile int signr = -1;
128static volatile int child_finished; 129static volatile int child_finished;
129 130
130static volatile enum {
131 AUXTRACE_SNAPSHOT_OFF = -1,
132 AUXTRACE_SNAPSHOT_DISABLED = 0,
133 AUXTRACE_SNAPSHOT_ENABLED = 1,
134} auxtrace_snapshot_state = AUXTRACE_SNAPSHOT_OFF;
135
136static inline void
137auxtrace_snapshot_on(void)
138{
139 auxtrace_snapshot_state = AUXTRACE_SNAPSHOT_DISABLED;
140}
141
142static inline void
143auxtrace_snapshot_enable(void)
144{
145 if (auxtrace_snapshot_state == AUXTRACE_SNAPSHOT_OFF)
146 return;
147 auxtrace_snapshot_state = AUXTRACE_SNAPSHOT_ENABLED;
148}
149
150static inline void
151auxtrace_snapshot_disable(void)
152{
153 if (auxtrace_snapshot_state == AUXTRACE_SNAPSHOT_OFF)
154 return;
155 auxtrace_snapshot_state = AUXTRACE_SNAPSHOT_DISABLED;
156}
157
158static inline bool
159auxtrace_snapshot_is_enabled(void)
160{
161 if (auxtrace_snapshot_state == AUXTRACE_SNAPSHOT_OFF)
162 return false;
163 return auxtrace_snapshot_state == AUXTRACE_SNAPSHOT_ENABLED;
164}
165
166static volatile int auxtrace_snapshot_err;
167static volatile int auxtrace_record__snapshot_started; 131static volatile int auxtrace_record__snapshot_started;
132static DEFINE_TRIGGER(auxtrace_snapshot_trigger);
168 133
169static void sig_handler(int sig) 134static void sig_handler(int sig)
170{ 135{
@@ -282,11 +247,12 @@ static void record__read_auxtrace_snapshot(struct record *rec)
282{ 247{
283 pr_debug("Recording AUX area tracing snapshot\n"); 248 pr_debug("Recording AUX area tracing snapshot\n");
284 if (record__auxtrace_read_snapshot_all(rec) < 0) { 249 if (record__auxtrace_read_snapshot_all(rec) < 0) {
285 auxtrace_snapshot_err = -1; 250 trigger_error(&auxtrace_snapshot_trigger);
286 } else { 251 } else {
287 auxtrace_snapshot_err = auxtrace_record__snapshot_finish(rec->itr); 252 if (auxtrace_record__snapshot_finish(rec->itr))
288 if (!auxtrace_snapshot_err) 253 trigger_error(&auxtrace_snapshot_trigger);
289 auxtrace_snapshot_enable(); 254 else
255 trigger_ready(&auxtrace_snapshot_trigger);
290 } 256 }
291} 257}
292 258
@@ -686,7 +652,7 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)
686 652
687 if (rec->opts.auxtrace_snapshot_mode) { 653 if (rec->opts.auxtrace_snapshot_mode) {
688 signal(SIGUSR2, snapshot_sig_handler); 654 signal(SIGUSR2, snapshot_sig_handler);
689 auxtrace_snapshot_on(); 655 trigger_on(&auxtrace_snapshot_trigger);
690 } else { 656 } else {
691 signal(SIGUSR2, SIG_IGN); 657 signal(SIGUSR2, SIG_IGN);
692 } 658 }
@@ -815,21 +781,21 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)
815 perf_evlist__enable(rec->evlist); 781 perf_evlist__enable(rec->evlist);
816 } 782 }
817 783
818 auxtrace_snapshot_enable(); 784 trigger_ready(&auxtrace_snapshot_trigger);
819 for (;;) { 785 for (;;) {
820 unsigned long long hits = rec->samples; 786 unsigned long long hits = rec->samples;
821 787
822 if (record__mmap_read_all(rec) < 0) { 788 if (record__mmap_read_all(rec) < 0) {
823 auxtrace_snapshot_disable(); 789 trigger_error(&auxtrace_snapshot_trigger);
824 err = -1; 790 err = -1;
825 goto out_child; 791 goto out_child;
826 } 792 }
827 793
828 if (auxtrace_record__snapshot_started) { 794 if (auxtrace_record__snapshot_started) {
829 auxtrace_record__snapshot_started = 0; 795 auxtrace_record__snapshot_started = 0;
830 if (!auxtrace_snapshot_err) 796 if (!trigger_is_error(&auxtrace_snapshot_trigger))
831 record__read_auxtrace_snapshot(rec); 797 record__read_auxtrace_snapshot(rec);
832 if (auxtrace_snapshot_err) { 798 if (trigger_is_error(&auxtrace_snapshot_trigger)) {
833 pr_err("AUX area tracing snapshot failed\n"); 799 pr_err("AUX area tracing snapshot failed\n");
834 err = -1; 800 err = -1;
835 goto out_child; 801 goto out_child;
@@ -858,12 +824,12 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)
858 * disable events in this case. 824 * disable events in this case.
859 */ 825 */
860 if (done && !disabled && !target__none(&opts->target)) { 826 if (done && !disabled && !target__none(&opts->target)) {
861 auxtrace_snapshot_disable(); 827 trigger_off(&auxtrace_snapshot_trigger);
862 perf_evlist__disable(rec->evlist); 828 perf_evlist__disable(rec->evlist);
863 disabled = true; 829 disabled = true;
864 } 830 }
865 } 831 }
866 auxtrace_snapshot_disable(); 832 trigger_off(&auxtrace_snapshot_trigger);
867 833
868 if (forks && workload_exec_errno) { 834 if (forks && workload_exec_errno) {
869 char msg[STRERR_BUFSIZE]; 835 char msg[STRERR_BUFSIZE];
@@ -1445,9 +1411,10 @@ out_symbol_exit:
1445 1411
1446static void snapshot_sig_handler(int sig __maybe_unused) 1412static void snapshot_sig_handler(int sig __maybe_unused)
1447{ 1413{
1448 if (!auxtrace_snapshot_is_enabled()) 1414 if (trigger_is_ready(&auxtrace_snapshot_trigger)) {
1449 return; 1415 trigger_hit(&auxtrace_snapshot_trigger);
1450 auxtrace_snapshot_disable(); 1416 auxtrace_record__snapshot_started = 1;
1451 auxtrace_snapshot_err = auxtrace_record__snapshot_start(record.itr); 1417 if (auxtrace_record__snapshot_start(record.itr))
1452 auxtrace_record__snapshot_started = 1; 1418 trigger_error(&auxtrace_snapshot_trigger);
1419 }
1453} 1420}