Skip to content

Commit ef3e87c

Browse files
ptxed, block: extract decoding and printing
This allows us to merge common code paths. Signed-off-by: Markus Metzger <markus.t.metzger@intel.com>
1 parent 9fa5e04 commit ef3e87c

File tree

1 file changed

+45
-41
lines changed

1 file changed

+45
-41
lines changed

ptxed/src/ptxed.c

Lines changed: 45 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1976,20 +1976,60 @@ static int drain_events_block(struct ptxed_decoder *decoder, uint64_t *time,
19761976
return status;
19771977
}
19781978

1979+
static int decode_one_block(struct ptxed_decoder *decoder,
1980+
const struct ptxed_options *options,
1981+
struct ptxed_stats *stats,
1982+
struct pt_block *block,
1983+
uint64_t time)
1984+
{
1985+
struct pt_block_decoder *ptdec;
1986+
uint64_t offset;
1987+
int status;
1988+
1989+
if (!decoder || !options || !block)
1990+
return -pte_internal;
1991+
1992+
ptdec = decoder->variant.block;
1993+
offset = 0ull;
1994+
1995+
if (options->print_offset || options->check) {
1996+
status = pt_blk_get_offset(ptdec, &offset);
1997+
if (status < 0)
1998+
return status;
1999+
}
2000+
2001+
status = pt_blk_next(ptdec, block, sizeof(*block));
2002+
2003+
/* Even in case of errors, we may have succeeded in decoding some
2004+
* instructions.
2005+
*/
2006+
if (stats) {
2007+
stats->insn += block->ninsn;
2008+
stats->blocks += 1;
2009+
}
2010+
2011+
if (!options->quiet)
2012+
print_block(decoder, block, options, stats, offset, time);
2013+
2014+
if (options->check)
2015+
check_block(decoder, block, offset);
2016+
2017+
return status;
2018+
}
2019+
19792020
static void decode_block(struct ptxed_decoder *decoder,
19802021
const struct ptxed_options *options,
19812022
struct ptxed_stats *stats)
19822023
{
19832024
struct pt_block_decoder *ptdec;
1984-
uint64_t offset, sync, time;
2025+
uint64_t sync, time;
19852026

19862027
if (!decoder || !options) {
19872028
printf("[internal error]\n");
19882029
return;
19892030
}
19902031

19912032
ptdec = decoder->variant.block;
1992-
offset = 0ull;
19932033
sync = 0ull;
19942034
time = 0ull;
19952035
for (;;) {
@@ -2039,46 +2079,10 @@ static void decode_block(struct ptxed_decoder *decoder,
20392079
break;
20402080
}
20412081

2042-
if (options->print_offset || options->check) {
2043-
status = pt_blk_get_offset(ptdec, &offset);
2044-
if (status < 0)
2045-
break;
2046-
}
2047-
2048-
status = pt_blk_next(ptdec, &block, sizeof(block));
2049-
if (status < 0) {
2050-
/* Even in case of errors, we may have succeeded
2051-
* in decoding some instructions.
2052-
*/
2053-
if (block.ninsn) {
2054-
if (stats) {
2055-
stats->insn += block.ninsn;
2056-
stats->blocks += 1;
2057-
}
2058-
2059-
if (!options->quiet)
2060-
print_block(decoder, &block,
2061-
options, stats,
2062-
offset, time);
2063-
2064-
if (options->check)
2065-
check_block(decoder, &block,
2066-
offset);
2067-
}
2082+
status = decode_one_block(decoder, options, stats,
2083+
&block, time);
2084+
if (status < 0)
20682085
break;
2069-
}
2070-
2071-
if (stats) {
2072-
stats->insn += block.ninsn;
2073-
stats->blocks += 1;
2074-
}
2075-
2076-
if (!options->quiet)
2077-
print_block(decoder, &block, options, stats,
2078-
offset, time);
2079-
2080-
if (options->check)
2081-
check_block(decoder, &block, offset);
20822086
}
20832087

20842088
/* We're done when we reach the end of the trace stream. */

0 commit comments

Comments
 (0)