diff options
author | Li Zefan <lizf@cn.fujitsu.com> | 2009-03-26 22:21:23 -0400 |
---|---|---|
committer | Ingo Molnar <mingo@elte.hu> | 2009-03-31 11:28:59 -0400 |
commit | b6a4b0c3ad4c09c1d37b1040ac8e3ebd1016e10b (patch) | |
tree | 95025e5a1b49056bdadf9bbb3e96417430d1830a /kernel/trace/blktrace.c | |
parent | ad5dd5493a55e462796e42e50a49e76df76fdb05 (diff) |
blktrace: extract duplidate code
Impact: cleanup
blk_trace_event_print() and blk_tracer_print_line() share most of the code.
text data bss dec hex filename
8605 393 12 9010 2332 kernel/trace/blktrace.o.orig
text data bss dec hex filename
8555 393 12 8960 2300 kernel/trace/blktrace.o
This patch also prepares for the next patch, that prints out BLK_TN_MESSAGE.
Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
Acked-by: Jens Axboe <jens.axboe@oracle.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'kernel/trace/blktrace.c')
-rw-r--r-- | kernel/trace/blktrace.c | 62 |
1 files changed, 30 insertions, 32 deletions
diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c index 2f21d7761600..c103b0c20022 100644 --- a/kernel/trace/blktrace.c +++ b/kernel/trace/blktrace.c | |||
@@ -986,29 +986,31 @@ static void get_pdu_remap(const struct trace_entry *ent, | |||
986 | r->sector = be64_to_cpu(sector); | 986 | r->sector = be64_to_cpu(sector); |
987 | } | 987 | } |
988 | 988 | ||
989 | static int blk_log_action_iter(struct trace_iterator *iter, const char *act) | 989 | typedef int (blk_log_action_t) (struct trace_iterator *iter, const char *act); |
990 | |||
991 | static int blk_log_action_classic(struct trace_iterator *iter, const char *act) | ||
990 | { | 992 | { |
991 | char rwbs[6]; | 993 | char rwbs[6]; |
992 | unsigned long long ts = iter->ts; | 994 | unsigned long long ts = iter->ts; |
993 | unsigned long nsec_rem = do_div(ts, NSEC_PER_SEC); | 995 | unsigned long nsec_rem = do_div(ts, NSEC_PER_SEC); |
994 | unsigned secs = (unsigned long)ts; | 996 | unsigned secs = (unsigned long)ts; |
995 | const struct trace_entry *ent = iter->ent; | 997 | const struct blk_io_trace *t = te_blk_io_trace(iter->ent); |
996 | const struct blk_io_trace *t = (const struct blk_io_trace *)ent; | ||
997 | 998 | ||
998 | fill_rwbs(rwbs, t); | 999 | fill_rwbs(rwbs, t); |
999 | 1000 | ||
1000 | return trace_seq_printf(&iter->seq, | 1001 | return trace_seq_printf(&iter->seq, |
1001 | "%3d,%-3d %2d %5d.%09lu %5u %2s %3s ", | 1002 | "%3d,%-3d %2d %5d.%09lu %5u %2s %3s ", |
1002 | MAJOR(t->device), MINOR(t->device), iter->cpu, | 1003 | MAJOR(t->device), MINOR(t->device), iter->cpu, |
1003 | secs, nsec_rem, ent->pid, act, rwbs); | 1004 | secs, nsec_rem, iter->ent->pid, act, rwbs); |
1004 | } | 1005 | } |
1005 | 1006 | ||
1006 | static int blk_log_action_seq(struct trace_seq *s, const struct blk_io_trace *t, | 1007 | static int blk_log_action(struct trace_iterator *iter, const char *act) |
1007 | const char *act) | ||
1008 | { | 1008 | { |
1009 | char rwbs[6]; | 1009 | char rwbs[6]; |
1010 | const struct blk_io_trace *t = te_blk_io_trace(iter->ent); | ||
1011 | |||
1010 | fill_rwbs(rwbs, t); | 1012 | fill_rwbs(rwbs, t); |
1011 | return trace_seq_printf(s, "%3d,%-3d %2s %3s ", | 1013 | return trace_seq_printf(&iter->seq, "%3d,%-3d %2s %3s ", |
1012 | MAJOR(t->device), MINOR(t->device), act, rwbs); | 1014 | MAJOR(t->device), MINOR(t->device), act, rwbs); |
1013 | } | 1015 | } |
1014 | 1016 | ||
@@ -1129,22 +1131,25 @@ static const struct { | |||
1129 | [__BLK_TA_REMAP] = {{ "A", "remap" }, blk_log_remap }, | 1131 | [__BLK_TA_REMAP] = {{ "A", "remap" }, blk_log_remap }, |
1130 | }; | 1132 | }; |
1131 | 1133 | ||
1132 | static enum print_line_t blk_trace_event_print(struct trace_iterator *iter, | 1134 | static enum print_line_t print_one_line(struct trace_iterator *iter, |
1133 | int flags) | 1135 | bool classic) |
1134 | { | 1136 | { |
1135 | struct trace_seq *s = &iter->seq; | 1137 | struct trace_seq *s = &iter->seq; |
1136 | const struct blk_io_trace *t = (struct blk_io_trace *)iter->ent; | 1138 | const struct blk_io_trace *t; |
1137 | const u16 what = t->action & ((1 << BLK_TC_SHIFT) - 1); | 1139 | u16 what; |
1138 | int ret; | 1140 | int ret; |
1141 | bool long_act; | ||
1142 | blk_log_action_t *log_action; | ||
1139 | 1143 | ||
1140 | if (!trace_print_context(iter)) | 1144 | t = te_blk_io_trace(iter->ent); |
1141 | return TRACE_TYPE_PARTIAL_LINE; | 1145 | what = t->action & ((1 << BLK_TC_SHIFT) - 1); |
1146 | long_act = !!(trace_flags & TRACE_ITER_VERBOSE); | ||
1147 | log_action = classic ? &blk_log_action_classic : &blk_log_action; | ||
1142 | 1148 | ||
1143 | if (unlikely(what == 0 || what >= ARRAY_SIZE(what2act))) | 1149 | if (unlikely(what == 0 || what >= ARRAY_SIZE(what2act))) |
1144 | ret = trace_seq_printf(s, "Bad pc action %x\n", what); | 1150 | ret = trace_seq_printf(s, "Bad pc action %x\n", what); |
1145 | else { | 1151 | else { |
1146 | const bool long_act = !!(trace_flags & TRACE_ITER_VERBOSE); | 1152 | ret = log_action(iter, what2act[what].act[long_act]); |
1147 | ret = blk_log_action_seq(s, t, what2act[what].act[long_act]); | ||
1148 | if (ret) | 1153 | if (ret) |
1149 | ret = what2act[what].print(s, iter->ent); | 1154 | ret = what2act[what].print(s, iter->ent); |
1150 | } | 1155 | } |
@@ -1152,6 +1157,15 @@ static enum print_line_t blk_trace_event_print(struct trace_iterator *iter, | |||
1152 | return ret ? TRACE_TYPE_HANDLED : TRACE_TYPE_PARTIAL_LINE; | 1157 | return ret ? TRACE_TYPE_HANDLED : TRACE_TYPE_PARTIAL_LINE; |
1153 | } | 1158 | } |
1154 | 1159 | ||
1160 | static enum print_line_t blk_trace_event_print(struct trace_iterator *iter, | ||
1161 | int flags) | ||
1162 | { | ||
1163 | if (!trace_print_context(iter)) | ||
1164 | return TRACE_TYPE_PARTIAL_LINE; | ||
1165 | |||
1166 | return print_one_line(iter, false); | ||
1167 | } | ||
1168 | |||
1155 | static int blk_trace_synthesize_old_trace(struct trace_iterator *iter) | 1169 | static int blk_trace_synthesize_old_trace(struct trace_iterator *iter) |
1156 | { | 1170 | { |
1157 | struct trace_seq *s = &iter->seq; | 1171 | struct trace_seq *s = &iter->seq; |
@@ -1177,26 +1191,10 @@ blk_trace_event_print_binary(struct trace_iterator *iter, int flags) | |||
1177 | 1191 | ||
1178 | static enum print_line_t blk_tracer_print_line(struct trace_iterator *iter) | 1192 | static enum print_line_t blk_tracer_print_line(struct trace_iterator *iter) |
1179 | { | 1193 | { |
1180 | const struct blk_io_trace *t; | ||
1181 | u16 what; | ||
1182 | int ret; | ||
1183 | |||
1184 | if (!(blk_tracer_flags.val & TRACE_BLK_OPT_CLASSIC)) | 1194 | if (!(blk_tracer_flags.val & TRACE_BLK_OPT_CLASSIC)) |
1185 | return TRACE_TYPE_UNHANDLED; | 1195 | return TRACE_TYPE_UNHANDLED; |
1186 | 1196 | ||
1187 | t = (const struct blk_io_trace *)iter->ent; | 1197 | return print_one_line(iter, true); |
1188 | what = t->action & ((1 << BLK_TC_SHIFT) - 1); | ||
1189 | |||
1190 | if (unlikely(what == 0 || what >= ARRAY_SIZE(what2act))) | ||
1191 | ret = trace_seq_printf(&iter->seq, "Bad pc action %x\n", what); | ||
1192 | else { | ||
1193 | const bool long_act = !!(trace_flags & TRACE_ITER_VERBOSE); | ||
1194 | ret = blk_log_action_iter(iter, what2act[what].act[long_act]); | ||
1195 | if (ret) | ||
1196 | ret = what2act[what].print(&iter->seq, iter->ent); | ||
1197 | } | ||
1198 | |||
1199 | return ret ? TRACE_TYPE_HANDLED : TRACE_TYPE_PARTIAL_LINE; | ||
1200 | } | 1198 | } |
1201 | 1199 | ||
1202 | static struct tracer blk_tracer __read_mostly = { | 1200 | static struct tracer blk_tracer __read_mostly = { |