Re: [PATCH v2 07/20] kernel-shark: Add basic methods for Data streams

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.

-- Steve



[Index of Archives]     [Linux USB Development]     [Linux USB Development]     [Linux Audio Users]     [Yosemite Hiking]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux