mirror of https://github.com/thesofproject/sof.git
logger: (cosmetic) fix the return value, use pointers
1. Programs shouldn't exit with negative return values, strictly speaking only EXIT_SUCCESS and EXIT_FAILURE should be used, however it is also valid to return 0 for success and any number from 1 to 125 for a failure. 2. Avoid passing complete structs as function parameters where an additional copy of one isn't needed, use const pointers instead. 3. Remove a left-over unused argument. Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
This commit is contained in:
parent
9ef3826a05
commit
28039d3024
|
@ -100,57 +100,58 @@ static const char * get_component_name(uint32_t component_id) {
|
|||
}
|
||||
}
|
||||
|
||||
static void print_entry_params(FILE *out_fd, struct log_entry_header dma_log,
|
||||
struct ldc_entry entry, uint64_t last_timestamp, double clock,
|
||||
int use_colors)
|
||||
static void print_entry_params(FILE *out_fd,
|
||||
const struct log_entry_header *dma_log, const struct ldc_entry *entry,
|
||||
uint64_t last_timestamp, double clock, int use_colors)
|
||||
{
|
||||
char ids[TRACE_MAX_IDS_STR];
|
||||
float dt = to_usecs(dma_log.timestamp - last_timestamp, clock);
|
||||
float dt = to_usecs(dma_log->timestamp - last_timestamp, clock);
|
||||
|
||||
if (dt < 0 || dt > 1000.0 * 1000.0 * 1000.0)
|
||||
dt = NAN;
|
||||
|
||||
if (entry.header.has_ids)
|
||||
sprintf(ids, "%d.%d", (dma_log.id_0 & TRACE_IDS_MASK),
|
||||
(dma_log.id_1 & TRACE_IDS_MASK));
|
||||
if (entry->header.has_ids)
|
||||
sprintf(ids, "%d.%d", (dma_log->id_0 & TRACE_IDS_MASK),
|
||||
(dma_log->id_1 & TRACE_IDS_MASK));
|
||||
|
||||
fprintf(out_fd, "%s%5u %6u %12s %-7s %16.6f %16.6f %20s:%-4u\t",
|
||||
entry.header.level == use_colors ?
|
||||
entry->header.level == use_colors ?
|
||||
(LOG_LEVEL_CRITICAL ? KRED : KNRM) : "",
|
||||
dma_log.core_id,
|
||||
entry.header.level,
|
||||
get_component_name(entry.header.component_class),
|
||||
entry.header.has_ids ? ids : "",
|
||||
to_usecs(dma_log.timestamp, clock),
|
||||
dma_log->core_id,
|
||||
entry->header.level,
|
||||
get_component_name(entry->header.component_class),
|
||||
entry->header.has_ids ? ids : "",
|
||||
to_usecs(dma_log->timestamp, clock),
|
||||
dt,
|
||||
entry.file_name,
|
||||
entry.header.line_idx);
|
||||
entry->file_name,
|
||||
entry->header.line_idx);
|
||||
|
||||
switch (entry.header.params_num) {
|
||||
switch (entry->header.params_num) {
|
||||
case 0:
|
||||
fprintf(out_fd, "%s", entry.text);
|
||||
fprintf(out_fd, "%s", entry->text);
|
||||
break;
|
||||
case 1:
|
||||
fprintf(out_fd, entry.text, entry.params[0]);
|
||||
fprintf(out_fd, entry->text, entry->params[0]);
|
||||
break;
|
||||
case 2:
|
||||
fprintf(out_fd, entry.text, entry.params[0], entry.params[1]);
|
||||
fprintf(out_fd, entry->text, entry->params[0], entry->params[1]);
|
||||
break;
|
||||
case 3:
|
||||
fprintf(out_fd, entry.text, entry.params[0], entry.params[1],
|
||||
entry.params[2]);
|
||||
fprintf(out_fd, entry->text, entry->params[0], entry->params[1],
|
||||
entry->params[2]);
|
||||
break;
|
||||
case 4:
|
||||
fprintf(out_fd, entry.text, entry.params[0], entry.params[1],
|
||||
entry.params[2], entry.params[3]);
|
||||
fprintf(out_fd, entry->text, entry->params[0], entry->params[1],
|
||||
entry->params[2], entry->params[3]);
|
||||
break;
|
||||
}
|
||||
fprintf(out_fd, "%s\n", use_colors ? KNRM : "");
|
||||
fflush(out_fd);
|
||||
}
|
||||
|
||||
static int fetch_entry(struct convert_config *config, uint32_t base_address,
|
||||
uint32_t data_offset, struct log_entry_header dma_log, uint64_t *last_timestamp)
|
||||
static int fetch_entry(const struct convert_config *config,
|
||||
uint32_t base_address, uint32_t data_offset,
|
||||
const struct log_entry_header *dma_log, uint64_t *last_timestamp)
|
||||
{
|
||||
struct ldc_entry entry;
|
||||
uint32_t entry_offset;
|
||||
|
@ -162,7 +163,7 @@ static int fetch_entry(struct convert_config *config, uint32_t base_address,
|
|||
entry.params = NULL;
|
||||
|
||||
/* evaluate entry offset in input file */
|
||||
entry_offset = dma_log.log_entry_address - base_address;
|
||||
entry_offset = dma_log->log_entry_address - base_address;
|
||||
|
||||
/* set file position to beginning of processed entry */
|
||||
fseek(config->ldc_fd, entry_offset + data_offset, SEEK_SET);
|
||||
|
@ -236,9 +237,9 @@ static int fetch_entry(struct convert_config *config, uint32_t base_address,
|
|||
}
|
||||
|
||||
/* printing entry content */
|
||||
print_entry_params(config->out_fd, dma_log, entry, *last_timestamp,
|
||||
print_entry_params(config->out_fd, dma_log, &entry, *last_timestamp,
|
||||
config->clock, config->use_colors);
|
||||
*last_timestamp = dma_log.timestamp;
|
||||
*last_timestamp = dma_log->timestamp;
|
||||
|
||||
/* set f_ldc file position to the beginning */
|
||||
rewind(config->ldc_fd);
|
||||
|
@ -253,7 +254,7 @@ out:
|
|||
return ret;
|
||||
}
|
||||
|
||||
static int logger_read(struct convert_config *config,
|
||||
static int logger_read(const struct convert_config *config,
|
||||
struct snd_sof_logs_header *snd)
|
||||
{
|
||||
struct log_entry_header dma_log;
|
||||
|
@ -282,7 +283,7 @@ static int logger_read(struct convert_config *config,
|
|||
|
||||
/* fetching entry from elf dump */
|
||||
ret = fetch_entry(config, snd->base_address, snd->data_offset,
|
||||
dma_log, &last_timestamp);
|
||||
&dma_log, &last_timestamp);
|
||||
if (ret)
|
||||
break;
|
||||
}
|
||||
|
@ -290,7 +291,7 @@ static int logger_read(struct convert_config *config,
|
|||
return ret;
|
||||
}
|
||||
|
||||
int convert(struct convert_config *config) {
|
||||
int convert(const struct convert_config *config) {
|
||||
struct snd_sof_logs_header snd;
|
||||
int count, ret = 0;
|
||||
|
||||
|
|
|
@ -36,4 +36,4 @@ struct convert_config {
|
|||
int use_colors;
|
||||
};
|
||||
|
||||
int convert(struct convert_config *config);
|
||||
int convert(const struct convert_config *config);
|
||||
|
|
|
@ -122,7 +122,7 @@ int main(int argc, char *argv[])
|
|||
config.version_fw = 0;
|
||||
config.use_colors = 1;
|
||||
|
||||
while ((opt = getopt(argc, argv, "ho:i:l:ps:m:c:tev:")) != -1) {
|
||||
while ((opt = getopt(argc, argv, "ho:i:l:ps:c:tev:")) != -1) {
|
||||
switch (opt) {
|
||||
case 'o':
|
||||
config.out_file = optarg;
|
||||
|
@ -171,7 +171,7 @@ int main(int argc, char *argv[])
|
|||
if (!config.ldc_fd) {
|
||||
fprintf(stderr, "error: Unable to open ldc file %s\n",
|
||||
config.ldc_file);
|
||||
ret = -errno;
|
||||
ret = errno;
|
||||
goto out;
|
||||
}
|
||||
|
||||
|
@ -180,7 +180,7 @@ int main(int argc, char *argv[])
|
|||
if (!config.version_fd) {
|
||||
fprintf(stderr, "error: Unable to open ver file %s\n",
|
||||
config.version_file);
|
||||
ret = -errno;
|
||||
ret = errno;
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
|
@ -190,7 +190,7 @@ int main(int argc, char *argv[])
|
|||
if (!config.out_fd) {
|
||||
fprintf(stderr, "error: Unable to open out file %s\n",
|
||||
config.out_file);
|
||||
ret = -errno;
|
||||
ret = errno;
|
||||
goto out;
|
||||
}
|
||||
} else {
|
||||
|
@ -212,14 +212,14 @@ int main(int argc, char *argv[])
|
|||
if (!config.in_fd) {
|
||||
fprintf(stderr, "error: Unable to open in file %s\n",
|
||||
config.in_file);
|
||||
ret = -errno;
|
||||
ret = errno;
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
if (isatty(fileno(config.out_fd)) != 1)
|
||||
config.use_colors = 0;
|
||||
|
||||
convert(&config);
|
||||
ret = -convert(&config);
|
||||
|
||||
out:
|
||||
/* close files */
|
||||
|
|
Loading…
Reference in New Issue