Received: by 2002:a05:6a10:7420:0:0:0:0 with SMTP id hk32csp4401774pxb; Mon, 21 Feb 2022 20:23:48 -0800 (PST) X-Google-Smtp-Source: ABdhPJybwYvPerZ90SU3Rxmndbj3V2D8fCWwEtZcV3jKFRsTh9ul4SuoQjLeIdUHgOkWpDwOKjKV X-Received: by 2002:a17:902:d2d1:b0:14f:e2ce:cca6 with SMTP id n17-20020a170902d2d100b0014fe2cecca6mr617643plc.83.1645503828500; Mon, 21 Feb 2022 20:23:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645503828; cv=none; d=google.com; s=arc-20160816; b=k4BlxqrgBcozgajFqe84lzAvIxVjcWo1mc5p9M5F2kbPFGoTcuHYc0UzHrQhzvCjpL uJRdusl0GO5mG0zfQyj8fDeCij9X3E2SfXLhaMEpv8So9CCxzcn28yWEwxPGLSMG223R 3n+S7cnSJMwtEn+Bp2mgG2nQChwmhpNdFIKO019iCrouKRARNeN+459PkQgUFTcbJxjf 4Sq1F/Tol0X6dAQv0sKs9le4LUW8Kll1kJgu43KyU5Gv+KSxTbToyr16/XDpc+9prB43 OEPN/q+1zzeluWZiVBVCv+pXEZUmO9UMTVcrWSZ0ewBfdHU3uQBsmTfs3S/pV5kVk/M7 0Svw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=GJfEqxqEWvAW6Q3rlZQ5qYVgykX2CSYJFIpVF/Vj3Zo=; b=LAvGNK2m/qi+tfQn0pALiK5mzE46dAHkNOEWOMH6UYFG1365FxiXMppBps42b/1MRR LIHdQPI+88iTwTgM3BEt+I5ucd6Vf1eLSphgNxrAECEQ6bLse9IEyd9DBJewxQ71IE97 5BZBoM58eyowtCuSce4qWHTgHJWBK+w4BNYB44AJvUcjk+zjkXlR7PRw4xfNpkeEzIGK AT45H4CkgNQLScEMqgiitBBGVci/BGUmf9WHnCm4N0KKNRBYmvRrQUaeCzpuIp71+XIM +TIGqe7+jRCV93qVpJYKVsVDIc8PRomTkc1B0WE9jQw3Gv3RgoqQLR623MPVgLhkDYcb Y7Qw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id p1si9819118pff.223.2022.02.21.20.23.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Feb 2022 20:23:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id BCF876E346; Mon, 21 Feb 2022 20:18:46 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235525AbiBUWSa convert rfc822-to-8bit (ORCPT + 99 others); Mon, 21 Feb 2022 17:18:30 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:40474 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235477AbiBUWSY (ORCPT ); Mon, 21 Feb 2022 17:18:24 -0500 Received: from us-smtp-delivery-44.mimecast.com (us-smtp-delivery-44.mimecast.com [207.211.30.44]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 46171237F6 for ; Mon, 21 Feb 2022 14:17:59 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-99-m9qPKYq2OQeeZSWgQGeZTw-1; Mon, 21 Feb 2022 17:17:55 -0500 X-MC-Unique: m9qPKYq2OQeeZSWgQGeZTw-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id DD69B1091DA1; Mon, 21 Feb 2022 22:17:53 +0000 (UTC) Received: from x1.com (unknown [10.22.16.159]) by smtp.corp.redhat.com (Postfix) with ESMTP id 57EA55DB8F; Mon, 21 Feb 2022 22:17:40 +0000 (UTC) From: Daniel Bristot de Oliveira To: Steven Rostedt Cc: Daniel Bristot de Oliveira , Jonathan Corbet , Clark Williams , Juri Lelli , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-trace-devel@vger.kernel.org Subject: [PATCH V2 11/11] rtla/trace: Save event histogram output to a file Date: Mon, 21 Feb 2022 23:16:56 +0100 Message-Id: <2ec469fef0afa5b51d741d334268e2dc3ce60672.1645481500.git.bristot@kernel.org> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: kernel.org Content-Transfer-Encoding: 8BIT Content-Type: text/plain; charset=WINDOWS-1252 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI, RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The hist: trigger generates a histogram in the file sys/event/hist. If the hist: trigger is used, automatically save the histogram output of the event sys:event in the sys_event_hist.txt file. Cc: Daniel Bristot de Oliveira Cc: Steven Rostedt Cc: Jonathan Corbet Signed-off-by: Daniel Bristot de Oliveira --- Documentation/tools/rtla/common_options.rst | 10 +++- tools/tracing/rtla/src/trace.c | 53 +++++++++++++++++++++ 2 files changed, 62 insertions(+), 1 deletion(-) diff --git a/Documentation/tools/rtla/common_options.rst b/Documentation/tools/rtla/common_options.rst index afd45bae821f..af76df6205d4 100644 --- a/Documentation/tools/rtla/common_options.rst +++ b/Documentation/tools/rtla/common_options.rst @@ -23,7 +23,15 @@ Filter the previous **-e** *sys:event* event with **. For further information about event filtering see https://www.kernel.org/doc/html/latest/trace/events.html#event-filtering. **--trigger** ** - Enable a trace event trigger to the previous **-e** *sys:event*. For further information about event trigger see https://www.kernel.org/doc/html/latest/trace/events.html#event-triggers. + Enable a trace event trigger to the previous **-e** *sys:event*. + If the *hist:* trigger is activated, the output histogram will be automatically saved to a file named *system_event_hist.txt*. + For example, the command: + + rtla -t -e osnoise:irq_noise --trigger="hist:key=desc,duration/1000:sort=desc,duration/1000:vals=hitcount" + + Will automatically save the content of the histogram associated to *osnoise:irq_noise* event in *osnoise_irq_noise_hist.txt*. + + For further information about event trigger see https://www.kernel.org/doc/html/latest/trace/events.html#event-triggers. **-P**, **--priority** *o:prio|r:prio|f:prio|d:runtime:period* diff --git a/tools/tracing/rtla/src/trace.c b/tools/tracing/rtla/src/trace.c index ef44bab0c404..8249ec4d77cc 100644 --- a/tools/tracing/rtla/src/trace.c +++ b/tools/tracing/rtla/src/trace.c @@ -296,6 +296,57 @@ static void trace_event_disable_filter(struct trace_instance *instance, tevent->event ? : "*", tevent->filter); } +/* + * trace_event_save_hist - save the content of an event hist + * + * If the trigger is a hist: one, save the content of the hist file. + */ +static void trace_event_save_hist(struct trace_instance *instance, + struct trace_events *tevent) +{ + int retval, index, out_fd; + mode_t mode = 0644; + char path[1024]; + char *hist; + + if (!tevent) + return; + + /* trigger enables hist */ + if (!tevent->trigger) + return; + + /* is this a hist: trigger? */ + retval = strncmp(tevent->trigger, "hist:", strlen("hist:")); + if (retval) + return; + + snprintf(path, 1024, "%s_%s_hist.txt", tevent->system, tevent->event); + + printf(" Saving event %s:%s hist to %s\n", tevent->system, tevent->event, path); + + out_fd = creat(path, mode); + if (out_fd < 0) { + err_msg(" Failed to create %s output file\n", path); + return; + } + + hist = tracefs_event_file_read(instance->inst, tevent->system, tevent->event, "hist", 0); + if (!hist) { + err_msg(" Failed to read %s:%s hist file\n", tevent->system, tevent->event); + goto out_close; + } + + index = 0; + do { + index += write(out_fd, &hist[index], strlen(hist) - index); + } while (index < strlen(hist)); + + free(hist); +out_close: + close(out_fd); +} + /* * trace_event_disable_trigger - disable an event trigger */ @@ -314,6 +365,8 @@ static void trace_event_disable_trigger(struct trace_instance *instance, debug_msg("Disabling %s:%s trigger %s\n", tevent->system, tevent->event ? : "*", tevent->trigger); + trace_event_save_hist(instance, tevent); + snprintf(trigger, 1024, "!%s\n", tevent->trigger); retval = tracefs_event_file_write(instance->inst, tevent->system, -- 2.34.1