-
Notifications
You must be signed in to change notification settings - Fork 350
host: trace: revert host traces to fprintf #548
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,205 +31,46 @@ | |
| * Ranjani Sridharan <[email protected]> | ||
| */ | ||
|
|
||
| #include <sof/preproc.h> | ||
| #include <stdint.h> | ||
| #include <stdio.h> | ||
| #include <string.h> | ||
| #include "host/common_test.h" | ||
| #include "host/trace.h" | ||
|
|
||
| #define MAX_TRACE_CLASSES 255 | ||
| /* testbench trace definition */ | ||
|
|
||
| /* enable trace by default in testbench */ | ||
| static int test_bench_trace = 1; | ||
| int num_trace_classes; | ||
|
|
||
| /* set up trace class identifier table based on SOF trace header file */ | ||
| int setup_trace_table(void) | ||
| { | ||
| char buffer[2048]; | ||
| char *trace = "uapi/logging.h"; | ||
| char *trace_filename = malloc(strlen(SOF_INC) + strlen(trace) + 2); | ||
| char *token; | ||
| int ret, i = 0; | ||
| size_t size; | ||
| FILE *fp; | ||
|
|
||
| /* set up trace file name using include directory prefix */ | ||
| sprintf(trace_filename, "%s/%s", SOF_INC, trace); | ||
|
|
||
| fp = fopen(trace_filename, "r"); | ||
| if (!fp) { | ||
| fprintf(stderr, "error: opening trace include file %s\n", | ||
| trace_filename); | ||
| return -EINVAL; | ||
| } | ||
|
|
||
| /* find number of trace classes defined */ | ||
| while (fgets(buffer, sizeof(buffer), fp)) { | ||
| char identifier[1024]; | ||
| int value = 0, shift = 0; | ||
|
|
||
| ret = sscanf(buffer, "#define %s (%d << %d)", identifier, | ||
| &value, &shift); | ||
| if (ret == 3) { | ||
| /* if TRACE_CLASS definition */ | ||
| if (strstr(identifier, "TRACE_CLASS")) | ||
| i++; | ||
| } | ||
| } | ||
|
|
||
| num_trace_classes = i; | ||
|
|
||
| /* allocate memory for trace table */ | ||
| size = sizeof(struct trace_class_table); | ||
| trace_table = (struct trace_class_table *)malloc(size * | ||
| num_trace_classes); | ||
| int test_bench_trace = 1; | ||
|
|
||
| /* rewind file pointer */ | ||
| fseek(fp, 0, SEEK_SET); | ||
|
|
||
| i = 0; | ||
|
|
||
| /* read lines from header */ | ||
| while (fgets(buffer, sizeof(buffer), fp)) { | ||
| char identifier[1024]; | ||
| int value = 0, shift = 0; | ||
|
|
||
| ret = sscanf(buffer, "#define %s (%d << %d)", identifier, | ||
| &value, &shift); | ||
| if (ret == 3) { | ||
| /* if TRACE_CLASS definition */ | ||
| if (strstr(identifier, "TRACE_CLASS")) { | ||
| /* extract subsystem name */ | ||
| token = strtok(identifier, "_"); | ||
| token = strtok(NULL, "_"); | ||
| token = strtok(NULL, "_"); | ||
|
|
||
| /* add trace class entry */ | ||
| trace_table[i].trace_class = value; | ||
| trace_table[i].class_name = strdup(token); | ||
| i++; | ||
| } | ||
| } | ||
| } | ||
| fclose(fp); | ||
| free(trace_filename); | ||
| return 0; | ||
| } | ||
|
|
||
| void free_trace_table(void) | ||
| { | ||
| int i; | ||
|
|
||
| for (i = 0; i < num_trace_classes; i++) | ||
| free(trace_table[i].class_name); | ||
|
|
||
| free(trace_table); | ||
| } | ||
| #define CASE(x) case TRACE_CLASS_##x: return #x | ||
|
|
||
| /* look up subsystem class name from table */ | ||
| static char *get_trace_class(uint32_t trace_class) | ||
| char *get_trace_class(uint32_t trace_class) | ||
| { | ||
| int i; | ||
|
|
||
| /* look up trace class table and return subsystem name */ | ||
| for (i = 0; i < num_trace_classes; i++) { | ||
| if (trace_table[i].trace_class == trace_class) | ||
| return trace_table[i].class_name; | ||
| switch (trace_class) { | ||
| CASE(IRQ); | ||
| CASE(IPC); | ||
| CASE(PIPE); | ||
| CASE(HOST); | ||
| CASE(DAI); | ||
| CASE(DMA); | ||
| CASE(SSP); | ||
| CASE(COMP); | ||
| CASE(WAIT); | ||
| CASE(LOCK); | ||
| CASE(MEM); | ||
| CASE(MIXER); | ||
| CASE(BUFFER); | ||
| CASE(VOLUME); | ||
| CASE(SWITCH); | ||
| CASE(MUX); | ||
| CASE(SRC); | ||
| CASE(TONE); | ||
| CASE(EQ_FIR); | ||
| CASE(EQ_IIR); | ||
| CASE(SA); | ||
| CASE(DMIC); | ||
| CASE(POWER); | ||
| default: return "unknown"; | ||
| } | ||
|
|
||
| return "value"; | ||
| } | ||
|
|
||
| #define META_SEQ_STEP_param_procU(i, _) META_CONCAT(param, i) %u | ||
|
|
||
| #define HOST_TRACE_EVENT_NTH_PARAMS(id_count, param_count) \ | ||
| uintptr_t event \ | ||
| META_SEQ_FROM_0_TO(id_count , META_SEQ_STEP_id_uint32_t) \ | ||
| META_SEQ_FROM_0_TO(param_count, META_SEQ_STEP_param_uint32_t) | ||
|
|
||
| #define HOST_TRACE_EVENT_NTH(postfix, param_count) \ | ||
| META_FUNC_WITH_VARARGS( \ | ||
| _trace_event, META_CONCAT(postfix, param_count), \ | ||
| void, HOST_TRACE_EVENT_NTH_PARAMS(2, param_count) \ | ||
| ) | ||
|
|
||
| /* print trace event */ | ||
| #define HOST_TRACE_EVENT_NTH_IMPL(arg_count) \ | ||
| HOST_TRACE_EVENT_NTH(, arg_count) \ | ||
| { \ | ||
| char a, b, c; \ | ||
| \ | ||
| if (test_bench_trace > 0) { \ | ||
| /* look up subsystem from trace class table */ \ | ||
| char *trace_class = strdup(get_trace_class(event >> 24));\ | ||
| \ | ||
| a = event & 0xff; \ | ||
| b = (event >> 8) & 0xff; \ | ||
| c = (event >> 16) & 0xff; \ | ||
| \ | ||
| /* print trace event stderr*/ \ | ||
| if (!strcmp(trace_class, "value")) \ | ||
| fprintf(stderr, \ | ||
| "Trace value %lu, "META_QUOTE( \ | ||
| META_SEQ_FROM_0_TO(arg_count, \ | ||
| META_SEQ_STEP_param_procU \ | ||
| ))"\n" \ | ||
| , event META_SEQ_FROM_0_TO(arg_count, \ | ||
| META_SEQ_STEP_param)); \ | ||
| else \ | ||
| fprintf(stderr, \ | ||
| "Trace %s %c%c%c\n" \ | ||
| , trace_class, c, b, a); \ | ||
| if (trace_class) \ | ||
| free(trace_class); \ | ||
| } \ | ||
| } \ | ||
| HOST_TRACE_EVENT_NTH(_mbox_atomic, arg_count) \ | ||
| { \ | ||
| META_CONCAT(_trace_event, arg_count) \ | ||
| (event META_SEQ_FROM_0_TO(2, META_SEQ_STEP_id) \ | ||
| META_SEQ_FROM_0_TO(arg_count, META_SEQ_STEP_param)); \ | ||
| } | ||
|
|
||
| /* Implementation of | ||
| * void _trace_event0( uint32_t log_entry, uint32_t params...) {...} | ||
| * void _trace_event_mbox_atomic0(uint32_t log_entry, uint32_t params...) {...} | ||
| */ | ||
| HOST_TRACE_EVENT_NTH_IMPL(0); | ||
|
|
||
| /* Implementation of | ||
| * void _trace_event1( uint32_t log_entry, uint32_t params...) {...} | ||
| * void _trace_event_mbox_atomic1(uint32_t log_entry, uint32_t params...) {...} | ||
| */ | ||
| HOST_TRACE_EVENT_NTH_IMPL(1); | ||
|
|
||
| /* Implementation of | ||
| * void _trace_event2( uint32_t log_entry, uint32_t params...) {...} | ||
| * void _trace_event_mbox_atomic2(uint32_t log_entry, uint32_t params...) {...} | ||
| */ | ||
| HOST_TRACE_EVENT_NTH_IMPL(2); | ||
|
|
||
| /* Implementation of | ||
| * void _trace_event3( uint32_t log_entry, uint32_t params...) {...} | ||
| * void _trace_event_mbox_atomic3(uint32_t log_entry, uint32_t params...) {...} | ||
| */ | ||
| HOST_TRACE_EVENT_NTH_IMPL(3); | ||
|
|
||
| /* Implementation of | ||
| * void _trace_event4( uint32_t log_entry, uint32_t params...) {...} | ||
| * void _trace_event_mbox_atomic4(uint32_t log_entry, uint32_t params...) {...} | ||
| */ | ||
| HOST_TRACE_EVENT_NTH_IMPL(4); | ||
|
|
||
| /* Implementation of | ||
| * void _trace_event5( uint32_t log_entry, uint32_t params...) {...} | ||
| * void _trace_event_mbox_atomic5(uint32_t log_entry, uint32_t params...) {...} | ||
| */ | ||
| HOST_TRACE_EVENT_NTH_IMPL(5); | ||
|
|
||
| /* enable trace in testbench */ | ||
| void tb_enable_trace(bool enable) | ||
| { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.