From patchwork Mon Oct 12 13:35:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yordan Karadzhov X-Patchwork-Id: 11832793 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 03BED109B for ; Mon, 12 Oct 2020 14:04:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D678C2074D for ; Mon, 12 Oct 2020 14:04:46 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="hLnwIwgg" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730983AbgJLOEp (ORCPT ); Mon, 12 Oct 2020 10:04:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58590 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730967AbgJLNgG (ORCPT ); Mon, 12 Oct 2020 09:36:06 -0400 Received: from mail-wr1-x444.google.com (mail-wr1-x444.google.com [IPv6:2a00:1450:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 04E7BC0613D0 for ; Mon, 12 Oct 2020 06:36:06 -0700 (PDT) Received: by mail-wr1-x444.google.com with SMTP id s9so7131824wro.8 for ; Mon, 12 Oct 2020 06:36:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=OwtSLj7I8f/64psYLH3fd6P0TG/AuHXoRS4W45a7JkQ=; b=hLnwIwggxCUQYZ4PL7ghA9XRxEuQRPJf/yrg9uF52RmGxiHD72qx+esM5U3fS+crYp aqP57n/ekc0b/iZMdvDFs+Qn1Kz8egJgWS3Fhod4epXeEUSpbySUk04qNoCT/x83e81Q cAH7M58TpDt9HMQbkM+gOHsVGT3yPV7oFA9rVf7J++ea05U/XEwq63bZPuICMtOYNw0A 2zKQF14dCy8A/QZ8tYSgCHKGyZ2I9EVl8qCFYL4fFsAH9vnGP6tYohi6GrHIs7u4UlMQ rbJ0cnV25mgEvnxXD2IDRlcVVdOXfnNdt/Pqga5T356NaqbIBmiGWzSz5g2yBCsL8FUm T1Wg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=OwtSLj7I8f/64psYLH3fd6P0TG/AuHXoRS4W45a7JkQ=; b=tYXeYbp3uVwmFkSLsgIvg0cuFlreshWrIZlc3F2RHsFSHzJEB1OwaMTg59NrYxa6tM Nt0qy2dY5RJ4WuxRuG7WppSWC8m/EuviP69SQu/6hp8yc1gXPYPdv535cYdAQ0xwz/q7 OZxV1M75yrA+QLZa5+Balaycg7vQbPxrLIJjD+yF7BQOhjfAeTDSepexjbYZ80NrcwWb iLgT1u3iM+ZbqUAccroEl0pH5udfEwzYhyDmCYekRTf5nfj2fLDZ8WcArO1d6u763jbU 9Y5EMz1udY/iHKJuoRkkP9AlG2lWvaRQ7blwuhhKXpP08/9DkWqfupZsKMMUFniaCvkS xEZA== X-Gm-Message-State: AOAM531awF/xBDLIidp/AiBVQpxKGv0Pyx2dXJrcxPqf0BQ+kl6WyMFD Cbc7Pjtyals4mEUDryeGhfE= X-Google-Smtp-Source: ABdhPJy11UuZNmj92KbpOdqF4A73MxYUpron6wuQDF6CYj9C5+KcLGjKJ9cJTvQ7xixB16BnnzZ/ow== X-Received: by 2002:adf:cd0c:: with SMTP id w12mr29529069wrm.305.1602509764598; Mon, 12 Oct 2020 06:36:04 -0700 (PDT) Received: from localhost.localdomain ([84.40.93.41]) by smtp.gmail.com with ESMTPSA id k5sm23145388wmb.19.2020.10.12.06.36.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Oct 2020 06:36:04 -0700 (PDT) From: "Yordan Karadzhov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org, "Yordan Karadzhov (VMware)" Subject: [PATCH v2 04/20] kernel-shark: Introduce Data streams Date: Mon, 12 Oct 2020 16:35:07 +0300 Message-Id: <20201012133523.469040-5-y.karadz@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201012133523.469040-1-y.karadz@gmail.com> References: <20201012133523.469040-1-y.karadz@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org With the help of Data stream, KernelShark will be able to load and merge multiple trace files (streams). Each stream can have different plugins or filters, registered for it, which means that the raw trace data of the streams can have different formats, and will allow for a great degree of customization of the provided data visualization. In this patch we only provide the basic definitions. The actual integration of the Data streams into the C API of KernelShark will happen in the following patches. Signed-off-by: Yordan Karadzhov (VMware) --- src/libkshark.h | 201 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 201 insertions(+) diff --git a/src/libkshark.h b/src/libkshark.h index 0182cf6d..1165c512 100644 --- a/src/libkshark.h +++ b/src/libkshark.h @@ -118,6 +118,207 @@ void kshark_hash_id_free(struct kshark_hash_id *hash); int *kshark_hash_ids(struct kshark_hash_id *hash); +struct kshark_data_stream; + +/** A function type to be used to initialize the interface of the data stream. */ +typedef int (*interface_init_func) (struct kshark_data_stream *, + const char *); + +/** A function type to be used to initialize the interface of the data stream. */ +typedef int (*interface_close_func) (struct kshark_data_stream *, + const char *); + +/** A function type to be used by the method interface of the data stream. */ +typedef char *(*stream_get_str_func) (struct kshark_data_stream *, + const struct kshark_entry *); + +/** A function type to be used by the method interface of the data stream. */ +typedef const int (*stream_get_int_func) (struct kshark_data_stream *, + const struct kshark_entry *); + +/** A function type to be used by the method interface of the data stream. */ +typedef int (*stream_find_id_func) (struct kshark_data_stream *, + const char *); + +/** A function type to be used by the method interface of the data stream. */ +typedef int *(*stream_get_ids_func) (struct kshark_data_stream *); + +/** A function type to be used by the method interface of the data stream. */ +typedef int (*stream_get_names_func) (struct kshark_data_stream *, + const struct kshark_entry *, + char ***); + +/** Event field format identifier. */ +typedef enum kshark_event_field_format { + /** A field of unknown type. */ + KS_INVALIDE_FIELD, + + /** Integer number */ + KS_INTEGER_FIELD, + + /** Floating-point number */ + KS_FLOAT_FIELD +} kshark_event_field_format; + +/** A function type to be used by the method interface of the data stream. */ +typedef kshark_event_field_format +(*stream_event_field_type) (struct kshark_data_stream *, + const struct kshark_entry *, + const char *); + +/** A function type to be used by the method interface of the data stream. */ +typedef const int (*stream_read_event_field) (struct kshark_data_stream *, + const struct kshark_entry *, + const char *, + int64_t *); + +/** A function type to be used by the method interface of the data stream. */ +typedef const int (*stream_read_record_field) (struct kshark_data_stream *, + void *, + const char *, + int64_t *); + +struct kshark_context; + +/** A function type to be used by the method interface of the data stream. */ +typedef ssize_t (*load_entries_func) (struct kshark_data_stream *, + struct kshark_context *, + struct kshark_entry ***); + +/** A function type to be used by the method interface of the data stream. */ +typedef ssize_t (*load_matrix_func) (struct kshark_data_stream *, + struct kshark_context *, + int16_t **cpu_array, + int32_t **pid_array, + int32_t **event_array, + int64_t **offset_array, + int64_t **ts_array); + +/** Data format identifier. */ +typedef enum kshark_data_format { + /** A data of unknown type. */ + KS_INVALIDE_DATA, + + /** Ftrace data. */ + KS_TEP_DATA, + + /** VMware SchedTrace data. */ + KS_VMW_ST_DATA, +} kshark_data_format; + +/** + * Structure representing the interface of methods used to operate over + * the data from a given stream. + */ +struct kshark_data_stream_interface { + /** 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; + + /** Method used to retrieve the Event name of the entry. */ + stream_get_str_func get_event_name; + + /** Method used to retrieve the Task name of the entry. */ + stream_get_str_func get_task; + + /** Method used to retrieve the Latency of the entry. */ + stream_get_str_func get_latency; + + /** Method used to retrieve the Info string of the entry. */ + stream_get_str_func get_info; + + /** Method used to retrieve Id of the Event from its name. */ + stream_find_id_func find_event_id; + + /** Method used to retrieve the array of Ids of all Events. */ + stream_get_ids_func get_all_event_ids; + + /** Method used to dump the entry's content to string. */ + stream_get_str_func dump_entry; + + /** + * Method used to retrieve the array of all field names of a given + * event. + */ + stream_get_names_func get_all_field_names; + + /** Method used to access the type of an event's data field. */ + stream_event_field_type get_event_field_type; + + /** Method used to access the value of an event's data field. */ + stream_read_event_field read_event_field_int64; + + /** Method used to access the value of an event's data field. */ + stream_read_record_field read_record_field_int64; + + /** Method used to load the data in the form of entries. */ + load_entries_func load_entries; + + /** Method used to load the data in matrix form. */ + load_matrix_func load_matrix; + + /** Generic data handle. */ + void *handle; +}; + +/** Structure representing a stream of trace data. */ +struct kshark_data_stream { + /** Data stream identifier. */ + uint8_t stream_id; + + /** The number of CPUs presented in this data stream. */ + int n_cpus; + + /** + * The number of distinct event types presented in this data stream. + */ + int n_events; + + /** The Process Id of the Idle task. */ + int idle_pid; + + /** Trace data file pathname. */ + char *file; + + /** Stream name. */ + char *name; + + /** Hash table of task PIDs. */ + struct kshark_hash_id *tasks; + + /** A mutex, used to protect the access to the input file. */ + pthread_mutex_t input_mutex; + + /** Hash of tasks to filter on. */ + struct kshark_hash_id *show_task_filter; + + /** Hash of tasks to not display. */ + struct kshark_hash_id *hide_task_filter; + + /** Hash of events to filter on. */ + struct kshark_hash_id *show_event_filter; + + /** Hash of events to not display. */ + struct kshark_hash_id *hide_event_filter; + + /** Hash of CPUs to filter on. */ + struct kshark_hash_id *show_cpu_filter; + + /** Hash of CPUs to not display. */ + struct kshark_hash_id *hide_cpu_filter; + + /** The type of the data. */ + enum kshark_data_format format; + + /** + * The interface of methods used to operate over the data from a given + * stream. + */ + struct kshark_data_stream_interface interface; +}; + /** Size of the task's hash table. */ #define KS_TASK_HASH_SHIFT 16 #define KS_TASK_HASH_SIZE (1 << KS_TASK_HASH_SHIFT)