[PATCH 09/10] ss: symmetrical formatter extension example
This commit shall show shortly where to place changes when one wants to extend an ss output formatter with a new handler (format print procedure). The extension is done symmetrically. That means, every up to now existing formatter is extended with a semantically equivalent handler (hr and json formatter). Signed-off-by: Matthias Tafelmeier matthias.tafelme...@gmx.net Suggested-by: Hagen Paul Pfeifer ha...@jauu.net --- misc/ss_hr_fmt.c | 61 ++ misc/ss_json_fmt.c | 65 ++ misc/ss_out_fmt.c | 10 + misc/ss_out_fmt.h | 10 + 4 files changed, 146 insertions(+) diff --git a/misc/ss_hr_fmt.c b/misc/ss_hr_fmt.c index 40b6b7c..ca73dda 100644 --- a/misc/ss_hr_fmt.c +++ b/misc/ss_hr_fmt.c @@ -242,6 +242,66 @@ static void packet_show_ring_hr_fmt(struct packet_diag_ring *ring) printf(,features:0x%x, ring-pdr_features); } +static void packet_details_hr_fmt(struct packet_diag_info *pinfo, + struct packet_diag_ring *ring_rx, + struct packet_diag_ring *ring_tx, + uint32_t fanout, + bool has_fanout) +{ + if (pinfo) { + printf(\n\tver:%d, pinfo-pdi_version); + printf( cpy_thresh:%d, pinfo-pdi_copy_thresh); + printf( flags( ); + if (pinfo-pdi_flags PDI_RUNNING) + printf(running); + if (pinfo-pdi_flags PDI_AUXDATA) + printf( auxdata); + if (pinfo-pdi_flags PDI_ORIGDEV) + printf( origdev); + if (pinfo-pdi_flags PDI_VNETHDR) + printf( vnethdr); + if (pinfo-pdi_flags PDI_LOSS) + printf( loss); + if (!pinfo-pdi_flags) + printf(0); + printf( )); + } + if (ring_rx) { + printf(\n\tring_rx(); + packet_show_ring_fmt(ring_rx); + printf()); + } + if (ring_tx) { + printf(\n\tring_tx(); + packet_show_ring_fmt(ring_tx); + printf()); + } + if (has_fanout) { + uint16_t type = (fanout 16) 0x; + + printf(\n\tfanout(); + printf(id:%d,, fanout 0x); + printf(type:); + + if (type == 0) + printf(hash); + else if (type == 1) + printf(lb); + else if (type == 2) + printf(cpu); + else if (type == 3) + printf(roll); + else if (type == 4) + printf(random); + else if (type == 5) + printf(qm); + else + printf(0x%x, type); + + printf()); + } +} + const struct fmt_op_hub hr_output_op = { .tcp_stats_fmt = tcp_stats_hr_fmt, .tcp_timer_fmt = tcp_timer_hr_fmt, @@ -257,4 +317,5 @@ const struct fmt_op_hub hr_output_op = { .opt_fmt = opt_hr_fmt, .proc_fmt = proc_hr_fmt, .packet_show_ring_fmt = packet_show_ring_hr_fmt, + .packet_details_fmt = packet_details_hr_fmt }; diff --git a/misc/ss_json_fmt.c b/misc/ss_json_fmt.c index d7dfce9..3d10220 100644 --- a/misc/ss_json_fmt.c +++ b/misc/ss_json_fmt.c @@ -355,6 +355,70 @@ static void packet_show_ring_json_fmt(struct packet_diag_ring *ring) printf(\features_0x\ : \%x\\n, ring-pdr_features); } +static void packet_details_json_fmt(struct packet_diag_info *pinfo, + struct packet_diag_ring *ring_rx, + struct packet_diag_ring *ring_tx, + uint32_t fanout, + bool has_fanout) +{ + printf(,\n); + if (pinfo) { + printf(\t\ver\: \%d\,\n, pinfo-pdi_version); + printf(\t\cpy_thresh\: \%d\,\n, pinfo-pdi_copy_thresh); + printf(\t\flags\: \); + if (pinfo-pdi_flags PDI_RUNNING) + printf(running); + if (pinfo-pdi_flags PDI_AUXDATA) + printf(_auxdata); + if (pinfo-pdi_flags PDI_ORIGDEV) + printf(_origdev); + if (pinfo-pdi_flags PDI_VNETHDR) + printf(_vnethdr); + if (pinfo-pdi_flags PDI_LOSS) + printf(_loss); + if (!pinfo-pdi_flags) + printf(0); + printf(\); + res_json_fmt_branch(ring_rx || ring_tx || has_fanout, ' '); + } + if (ring_rx) { + printf(\t\ring_rx\: {); + packet_show_ring_fmt(ring_rx); + printf(}); + res_json_fmt_branch(ring_tx || has_fanout, ' '); + } + if (ring_tx) { + printf(\t\ring_tx\: {); +
[PATCH 09/10] ss: symmetrical formatter extension example
This commit shall show shortly where to place changes when one wants to extend an ss output formatter with a new handler (format print procedure). The extension is done symmetrically. That means, every up to now existing formatter is extended with a semantically equivalent handler (hr and json formatter). Signed-off-by: Matthias Tafelmeier matthias.tafelme...@gmx.net Suggested-by: Hagen Paul Pfeifer ha...@jauu.net --- misc/ss_hr_fmt.c | 61 ++ misc/ss_json_fmt.c | 65 ++ misc/ss_out_fmt.c | 10 + misc/ss_out_fmt.h | 10 + 4 files changed, 146 insertions(+) diff --git a/misc/ss_hr_fmt.c b/misc/ss_hr_fmt.c index 40b6b7c..ca73dda 100644 --- a/misc/ss_hr_fmt.c +++ b/misc/ss_hr_fmt.c @@ -242,6 +242,66 @@ static void packet_show_ring_hr_fmt(struct packet_diag_ring *ring) printf(,features:0x%x, ring-pdr_features); } +static void packet_details_hr_fmt(struct packet_diag_info *pinfo, + struct packet_diag_ring *ring_rx, + struct packet_diag_ring *ring_tx, + uint32_t fanout, + bool has_fanout) +{ + if (pinfo) { + printf(\n\tver:%d, pinfo-pdi_version); + printf( cpy_thresh:%d, pinfo-pdi_copy_thresh); + printf( flags( ); + if (pinfo-pdi_flags PDI_RUNNING) + printf(running); + if (pinfo-pdi_flags PDI_AUXDATA) + printf( auxdata); + if (pinfo-pdi_flags PDI_ORIGDEV) + printf( origdev); + if (pinfo-pdi_flags PDI_VNETHDR) + printf( vnethdr); + if (pinfo-pdi_flags PDI_LOSS) + printf( loss); + if (!pinfo-pdi_flags) + printf(0); + printf( )); + } + if (ring_rx) { + printf(\n\tring_rx(); + packet_show_ring_fmt(ring_rx); + printf()); + } + if (ring_tx) { + printf(\n\tring_tx(); + packet_show_ring_fmt(ring_tx); + printf()); + } + if (has_fanout) { + uint16_t type = (fanout 16) 0x; + + printf(\n\tfanout(); + printf(id:%d,, fanout 0x); + printf(type:); + + if (type == 0) + printf(hash); + else if (type == 1) + printf(lb); + else if (type == 2) + printf(cpu); + else if (type == 3) + printf(roll); + else if (type == 4) + printf(random); + else if (type == 5) + printf(qm); + else + printf(0x%x, type); + + printf()); + } +} + const struct fmt_op_hub hr_output_op = { .tcp_stats_fmt = tcp_stats_hr_fmt, .tcp_timer_fmt = tcp_timer_hr_fmt, @@ -257,4 +317,5 @@ const struct fmt_op_hub hr_output_op = { .opt_fmt = opt_hr_fmt, .proc_fmt = proc_hr_fmt, .packet_show_ring_fmt = packet_show_ring_hr_fmt, + .packet_details_fmt = packet_details_hr_fmt }; diff --git a/misc/ss_json_fmt.c b/misc/ss_json_fmt.c index e80f063..e7a1270 100644 --- a/misc/ss_json_fmt.c +++ b/misc/ss_json_fmt.c @@ -383,6 +383,70 @@ static void packet_show_ring_json_fmt(struct packet_diag_ring *ring) printf(\features_0x\ : \%x\\n, ring-pdr_features); } +static void packet_details_json_fmt(struct packet_diag_info *pinfo, + struct packet_diag_ring *ring_rx, + struct packet_diag_ring *ring_tx, + uint32_t fanout, + bool has_fanout) +{ + printf(,\n); + if (pinfo) { + printf(\t\ver\: \%d\,\n, pinfo-pdi_version); + printf(\t\cpy_thresh\: \%d\,\n, pinfo-pdi_copy_thresh); + printf(\t\flags\: \); + if (pinfo-pdi_flags PDI_RUNNING) + printf(running); + if (pinfo-pdi_flags PDI_AUXDATA) + printf(_auxdata); + if (pinfo-pdi_flags PDI_ORIGDEV) + printf(_origdev); + if (pinfo-pdi_flags PDI_VNETHDR) + printf(_vnethdr); + if (pinfo-pdi_flags PDI_LOSS) + printf(_loss); + if (!pinfo-pdi_flags) + printf(0); + printf(\); + res_json_fmt_branch(ring_rx || ring_tx || has_fanout, ' '); + } + if (ring_rx) { + printf(\t\ring_rx\: {); + packet_show_ring_fmt(ring_rx); + printf(}); + res_json_fmt_branch(ring_tx || has_fanout, ' '); + } + if (ring_tx) { + printf(\t\ring_tx\: {); +