From patchwork Fri May 4 13:46:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Smythies X-Patchwork-Id: 10380471 X-Patchwork-Delegate: rjw@sisk.pl Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id C9938603B4 for ; Fri, 4 May 2018 13:46:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B08D322380 for ; Fri, 4 May 2018 13:46:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A4EF229309; Fri, 4 May 2018 13:46:47 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 19F3122380 for ; Fri, 4 May 2018 13:46:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751308AbeEDNqq (ORCPT ); Fri, 4 May 2018 09:46:46 -0400 Received: from mail-pf0-f196.google.com ([209.85.192.196]:46983 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751114AbeEDNqp (ORCPT ); Fri, 4 May 2018 09:46:45 -0400 Received: by mail-pf0-f196.google.com with SMTP id p12so17469620pff.13; Fri, 04 May 2018 06:46:44 -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; bh=eOsgsRe+ImVRs4JEeEqAv56ZQ2oQh0Ye31H0TA1Y6KM=; b=EZqUzpy26vgbwfFnBizJhl4qxTWkRY778bSBytQaHa4R/3GS3uU+hvom+jjXRKIaC1 RQkTdjERC5SZTNAtEvI9gNV/49Ud4lA20A+SPM1PAI4K3wimKRa7KA7NUIn9WohcUtud smojDsJwh9uXVSmFX5GiAhMPaijgTA1bKqFhF4Elzn5MY1M3x64xB2p3bKzCGmqjtjNb 0DmUL8mSavRqChB22zdliRpcijTtxSFR6Ihl6Qvkfen2EulAzXxjZfM2VuXQ5A6WXRz0 cGpHC9Thhwwc2u8Iq/GcJL5MZx/BrZWX6L2mbiehT2cx4fXTgtPHUmhvMKGUkp3D0mp3 rIHQ== 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; bh=eOsgsRe+ImVRs4JEeEqAv56ZQ2oQh0Ye31H0TA1Y6KM=; b=f0HVFp3WKULd/dcykUpCI75DBvZqSk53TPO+tPWUdWvDGX13NItKthfMsQB8ppTHmg A61VHVyaB834OoRB694l0001auLQ0dtTPQzfGx9O772IvUtgMtEIgQjTqt59hClotu2E lTHZZ672YXT5/kT1rmpXCuDC4zbtOwME/WfByvLq5d9XyyqkQBbl0Qg/PNM4EfxERugP Nh21PExlcYQf7xpW5Xwe3BP0u2LEOBh4QEbnK6SDcE5kjstNttyGu+OZ6+3b6sdgqmJA +D71rfkyPEuGrgZfg/TNlUy+7nr2mFFx+Acjpb3HCSKpdxdlc1J5+lWLB9+4vNeTvpsW F+Bw== X-Gm-Message-State: ALQs6tC+qMXa+ajeAa8rEvjkwUVqpcTYykaOQR5Y3uLGC6FyhohNj3ak QBHF4CXy3huIAujutXzG/whfNw== X-Google-Smtp-Source: AB8JxZo22GgcSsf47a87bDCSoK0OLFjI9Rjx6/3xzL9mPlgU3UUpEg6JHLv3kAjL27q+cyCOL5Txbw== X-Received: by 2002:a63:2c13:: with SMTP id s19-v6mr8247446pgs.427.1525441604455; Fri, 04 May 2018 06:46:44 -0700 (PDT) Received: from s15.smythies.com (mail.smythies.com. [173.180.45.4]) by smtp.gmail.com with ESMTPSA id e6sm25427762pff.185.2018.05.04.06.46.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 04 May 2018 06:46:44 -0700 (PDT) From: Doug Smythies X-Google-Original-From: Doug Smythies To: srinivas.pandruvada@linux.intel.com Cc: dsmythies@telus.net, rjw@rjwysocki.net, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org Subject: [PATCH] tools/power/x86/intel_pstate_tracer: Add optional setting of trace buffer memory allocation Date: Fri, 4 May 2018 06:46:22 -0700 Message-Id: <1525441582-23855-1-git-send-email-dsmythies@telus.net> X-Mailer: git-send-email 2.7.4 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Allow the user to override the default trace buffer memory allocation by adding a command line option to override the default. The patch also: Adds a SIGINT (i.e. CTRL C exit) handler, so that things can be cleaned up before exit. Moves the postion of some other cleanup from after to before the potential "No valid data to plot" exit. Replaces all quit() calls with sys.exit, because quit() is not supposed to be used in scripts. Signed-off-by: Doug Smythies --- .../x86/intel_pstate_tracer/intel_pstate_tracer.py | 54 ++++++++++++++-------- 1 file changed, 35 insertions(+), 19 deletions(-) diff --git a/tools/power/x86/intel_pstate_tracer/intel_pstate_tracer.py b/tools/power/x86/intel_pstate_tracer/intel_pstate_tracer.py index 29f50d4..84e2b64 100755 --- a/tools/power/x86/intel_pstate_tracer/intel_pstate_tracer.py +++ b/tools/power/x86/intel_pstate_tracer/intel_pstate_tracer.py @@ -28,6 +28,7 @@ import subprocess import os import time import re +import signal import sys import getopt import Gnuplot @@ -78,11 +79,12 @@ def print_help(): print(' Or') print(' ./intel_pstate_tracer.py [--cpu cpus] ---trace_file --name ') print(' To generate trace file, parse and plot, use (sudo required):') - print(' sudo ./intel_pstate_tracer.py [-c cpus] -i -n ') + print(' sudo ./intel_pstate_tracer.py [-c cpus] -i -n -m ') print(' Or') - print(' sudo ./intel_pstate_tracer.py [--cpu cpus] --interval --name ') + print(' sudo ./intel_pstate_tracer.py [--cpu cpus] --interval --name --memory ') print(' Optional argument:') - print(' cpus: comma separated list of CPUs') + print(' cpus: comma separated list of CPUs') + print(' kbytes: Kilo bytes of memory per CPU to allocate to the trace buffer. Default: 10240') print(' Output:') print(' If not already present, creates a "results/test_name" folder in the current working directory with:') print(' cpu.csv - comma seperated values file with trace contents and some additional calculations.') @@ -379,7 +381,7 @@ def clear_trace_file(): f_handle.close() except: print('IO error clearing trace file ') - quit() + sys.exit(2) def enable_trace(): """ Enable trace """ @@ -389,7 +391,7 @@ def enable_trace(): , 'w').write("1") except: print('IO error enabling trace ') - quit() + sys.exit(2) def disable_trace(): """ Disable trace """ @@ -399,17 +401,17 @@ def disable_trace(): , 'w').write("0") except: print('IO error disabling trace ') - quit() + sys.exit(2) def set_trace_buffer_size(): """ Set trace buffer size """ try: - open('/sys/kernel/debug/tracing/buffer_size_kb' - , 'w').write("10240") + with open('/sys/kernel/debug/tracing/buffer_size_kb', 'w') as fp: + fp.write(memory) except: - print('IO error setting trace buffer size ') - quit() + print('IO error setting trace buffer size ') + sys.exit(2) def free_trace_buffer(): """ Free the trace buffer memory """ @@ -418,8 +420,8 @@ def free_trace_buffer(): open('/sys/kernel/debug/tracing/buffer_size_kb' , 'w').write("1") except: - print('IO error setting trace buffer size ') - quit() + print('IO error freeing trace buffer ') + sys.exit(2) def read_trace_data(filename): """ Read and parse trace data """ @@ -431,7 +433,7 @@ def read_trace_data(filename): data = open(filename, 'r').read() except: print('Error opening ', filename) - quit() + sys.exit(2) for line in data.splitlines(): search_obj = \ @@ -489,10 +491,22 @@ def read_trace_data(filename): # Now seperate the main overall csv file into per CPU csv files. split_csv() +def signal_handler(signal, frame): + print(' SIGINT: Forcing cleanup before exit.') + if interval: + disable_trace() + clear_trace_file() + # Free the memory + free_trace_buffer() + sys.exit(0) + +signal.signal(signal.SIGINT, signal_handler) + interval = "" filename = "" cpu_list = "" testname = "" +memory = "10240" graph_data_present = False; valid1 = False @@ -501,7 +515,7 @@ valid2 = False cpu_mask = zeros((MAX_CPUS,), dtype=int) try: - opts, args = getopt.getopt(sys.argv[1:],"ht:i:c:n:",["help","trace_file=","interval=","cpu=","name="]) + opts, args = getopt.getopt(sys.argv[1:],"ht:i:c:n:m:",["help","trace_file=","interval=","cpu=","name=","memory="]) except getopt.GetoptError: print_help() sys.exit(2) @@ -521,6 +535,8 @@ for opt, arg in opts: elif opt in ("-n", "--name"): valid2 = True testname = arg + elif opt in ("-m", "--memory"): + memory = arg if not (valid1 and valid2): print_help() @@ -569,6 +585,11 @@ current_max_cpu = 0 read_trace_data(filename) +clear_trace_file() +# Free the memory +if interval: + free_trace_buffer() + if graph_data_present == False: print('No valid data to plot') sys.exit(2) @@ -593,9 +614,4 @@ for root, dirs, files in os.walk('.'): for f in files: fix_ownership(f) -clear_trace_file() -# Free the memory -if interval: - free_trace_buffer() - os.chdir('../../')