On 4.11.20 г. 17:41 ч., Steven Rostedt wrote:
On Tue, 3 Nov 2020 15:38:33 +0200 "Yordan Karadzhov (VMware)" <y.karadz@xxxxxxxxx> wrote:What if we define the interface to start with an integer identifier? /** Data interface identifier. */ typedef enum kshark_data_interface_id { /** An interface with unknown type. */ KS_INVALIDE_INTERFACE, /** Generic interface suitable Ftrace data. */ KS_GENERIC_DATA_INTERFACE, } kshark_data_interface_id; /** * Structure representing the interface of methods used to operate over * the data from a given stream. */ struct kshark_generic_stream_interface { /** Interface version identifier. */ int type; /* MUST BE FIRST ENTRY */ /** Method used to retrieve the Process Id of the entry. */ stream_get_int_func get_pid; /** Method used to retrieve the Event Id of the entry. */ stream_get_int_func get_event_id; .... and it can be used like this: char *kshark_get_aux_field(const struct kshark_entry *entry) { struct kshark_generic_stream_interface *interface; struct kshark_data_stream *stream = kshark_get_stream_from_entry(entry); .... interface = stream->interface; if (interface->type == KS_GENERIC_DATA_INTERFACE && interface->aux_field) return interface->aux_field(stream, entry); return NULL; } What do you think?This was actually what I was getting at ;-) That is a common practice in the Linux kernel.
OK, thanks a lot! Will be implemented in v3. cheers, Yordan
-- Steve