Received: by 2002:ac0:aed5:0:0:0:0:0 with SMTP id t21csp4434282imb; Wed, 6 Mar 2019 13:20:01 -0800 (PST) X-Google-Smtp-Source: APXvYqzEUzCg5eBdt/EeQCtChLgXUPA5S0LxLA28OgbNepZMOgRzTDDgT9F/x2meTZ16FnyT46m0 X-Received: by 2002:a63:35ce:: with SMTP id c197mr8090457pga.281.1551907201284; Wed, 06 Mar 2019 13:20:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551907201; cv=none; d=google.com; s=arc-20160816; b=ksRs+HhcGexjKyz5L2Ky+70TXbpXoGHICxfTBpBVCDx5Bttk/JycYyduPyv1HGBOfn Gtpz+6IRf74ISf7D/LKxJyn4C1JpT2ibpUIYsY21iliHHSUVKe2pJUH6OAWoWRngeTQB 1GZrII17JsQbhJzYRVhniXTYWFtrI3Bzym2zmIqYODopNjS82LJY6uxPXQ7lTGQ5+CKl eVNmtXSST6UerST5EUseBob8pBgTvhGD17HqxOHexsH2E+n6fPouXWYYsRqzDZtrW9NM 7FvawXuk06yFt7MgLNY9mKfr9UYMFwOjHs74ol7ecBNroOOQeYC1cL8IIrRnxwh1yxLZ a0zQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:date:from:dkim-signature; bh=6FzZwtkKGi82EwutdTnCMBrcinoMkS3faUusUIZQGWo=; b=fgICXLry9JuXKGC/uMWZ66alhhDvuj9k4dSQ8/QkagQsW4hjMZup6q3F7ZJC6cN7U6 Eap/qGfdtymB3jwgiT1Grth0AfjsF/97tfv27ti4/bH+rQMcNIyyfDDIDNfjolHtl9a4 I9nOVpZylHm9CLGjBsx5AkZuAQu1PWOuSf0rGp6UDx1gHTiC+mZupbA3w6X/iyMhkrZt EYss+E+fDftSkZq7fgoS/ljSNLQpwkl+8hB0g8sxMjjwB2r3niQMhZjrG0jqNkDJnsek ySXixyE+1FAMMbdPBYZI0oZd/zCQh+ZuT/CdAre4k9vS5+a1ShJ6T3lfvbkoz9TqAqI6 kUig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=TtbBLnn8; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 89si2407779pld.153.2019.03.06.13.19.43; Wed, 06 Mar 2019 13:20:01 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=TtbBLnn8; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726620AbfCFVOE (ORCPT + 99 others); Wed, 6 Mar 2019 16:14:04 -0500 Received: from mail-qk1-f193.google.com ([209.85.222.193]:34426 "EHLO mail-qk1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726556AbfCFVOD (ORCPT ); Wed, 6 Mar 2019 16:14:03 -0500 Received: by mail-qk1-f193.google.com with SMTP id a15so7745678qkc.1; Wed, 06 Mar 2019 13:14:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:date:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=6FzZwtkKGi82EwutdTnCMBrcinoMkS3faUusUIZQGWo=; b=TtbBLnn8J1lvwEtLFWmVglJuusQTsOy82OCH/4rfkBM9NYGPm74EyPyUGGjqRnTg0D QhVXuRNIxzJV2koa8VKXvf+ASw3NMXMSxdxygVlN/LANmCGAplJfvTcC8zZvgzMKU2a+ vDav+x2M5JjKFwSkW8Ze8Nk8hj5i0eruL4VnDDmT2Oe+Y7F9CJa99cBhSr4A7IFOsEZq a4JctA6AsYQBLX/voSdHLzUdxeMB3FiAygHrYpO4OuMBTP5WriNDHb0mKKEHq6omYjKp 69Vg4bVYIHTYT54CK1zOR18B1+1ke+OI3TajpDgOpjKyWZyUNd3qcfeWaBgyArtwU2EC usiw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:date:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=6FzZwtkKGi82EwutdTnCMBrcinoMkS3faUusUIZQGWo=; b=KgvoeBGz3tJr7qItxRmsXG0CxjJ6AkfUZ1NzEtsw7PfMfDIkvLJ6zjxRnmoN7RhvPN eGCtNvSpAKKKy6mnV8zkMqkJM+XEzVsFq81J2GINLpVFfTRpwezo+X3ao1/iB6q6S1vw s+OQlkY7+IlEZBH6PdjR3qCkX0sFDPzeINfcxCIo2ojHaqyglmLuhcBw2Qn3wnUx2rih WPbEZZwU1DZPfPu0vsMTzr/Ie7bi43lm42i1HN+MYXaC95kuGjqRnFlEvLmQ6Nj2gU6k NZW9C68CoY9aGzyJTmptjAw9v6UUX0jZIxwgjS1c6kv1bYJ0k+N+3CApO8YCXP9vFkKk wMSw== X-Gm-Message-State: APjAAAUGyqlNdTCkU3mzDhvbj8mitNIgyKK7HzcKEwIhmoq1fLcFT6wJ VSZeKzHjo0nG/PLp7+uAc9BCAcc5 X-Received: by 2002:a05:620a:12b3:: with SMTP id x19mr7289267qki.204.1551906841972; Wed, 06 Mar 2019 13:14:01 -0800 (PST) Received: from quaco.ghostprotocols.net ([179.97.35.11]) by smtp.gmail.com with ESMTPSA id j9sm1305636qtb.30.2019.03.06.13.14.00 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 06 Mar 2019 13:14:01 -0800 (PST) From: Arnaldo Carvalho de Melo X-Google-Original-From: Arnaldo Carvalho de Melo Received: by quaco.ghostprotocols.net (Postfix, from userid 1000) id 5C5CF4039C; Wed, 6 Mar 2019 18:13:59 -0300 (-03) Date: Wed, 6 Mar 2019 18:13:59 -0300 To: Tony Jones Cc: linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Adrian Hunter Subject: Re: [PATCH v2 7/7] perf script python: add printdate function to SQL exporters Message-ID: <20190306211359.GR30734@kernel.org> References: <20190302011903.2416-1-tonyj@suse.de> <20190302011903.2416-8-tonyj@suse.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190302011903.2416-8-tonyj@suse.de> X-Url: http://acmel.wordpress.com User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Em Fri, Mar 01, 2019 at 05:19:03PM -0800, Tony Jones escreveu: > Introduce a printdate function to eliminate the repetitive use of > datetime.datetime.today() in the SQL exporting scripts. Seems easy enough, but since Adrian provided the Acked-by to the other patch, can this be done this time again? Thanks, - Arnaldo > Signed-off-by: Tony Jones > Cc: Adrian Hunter > --- > tools/perf/scripts/python/export-to-postgresql.py | 19 +++++++++++-------- > tools/perf/scripts/python/export-to-sqlite.py | 13 ++++++++----- > 2 files changed, 19 insertions(+), 13 deletions(-) > > diff --git a/tools/perf/scripts/python/export-to-postgresql.py b/tools/perf/scripts/python/export-to-postgresql.py > index 439bbbf1e036..515dc5506427 100644 > --- a/tools/perf/scripts/python/export-to-postgresql.py > +++ b/tools/perf/scripts/python/export-to-postgresql.py > @@ -249,6 +249,9 @@ perf_db_export_callchains = False > def printerr(*args, **kw_args): > print(*args, file=sys.stderr, **kw_args) > > +def printdate(*args, **kw_args): > + print(datetime.datetime.today(), *args, sep=' ', **kw_args) > + > def usage(): > printerr("Usage is: export-to-postgresql.py [] [] []") > printerr("where: columns 'all' or 'branches'") > @@ -287,7 +290,7 @@ def do_query(q, s): > return > raise Exception("Query failed: " + q.lastError().text()) > > -print(datetime.datetime.today(), "Creating database...") > +printdate("Creating database...") > > db = QSqlDatabase.addDatabase('QPSQL') > query = QSqlQuery(db) > @@ -580,7 +583,7 @@ if perf_db_export_calls: > call_file = open_output_file("call_table.bin") > > def trace_begin(): > - print(datetime.datetime.today(), "Writing to intermediate files...") > + printdate("Writing to intermediate files...") > # id == 0 means unknown. It is easier to create records for them than replace the zeroes with NULLs > evsel_table(0, "unknown") > machine_table(0, 0, "unknown") > @@ -596,7 +599,7 @@ def trace_begin(): > unhandled_count = 0 > > def trace_end(): > - print(datetime.datetime.today(), "Copying to database...") > + printdate("Copying to database...") > copy_output_file(evsel_file, "selected_events") > copy_output_file(machine_file, "machines") > copy_output_file(thread_file, "threads") > @@ -611,7 +614,7 @@ def trace_end(): > if perf_db_export_calls: > copy_output_file(call_file, "calls") > > - print(datetime.datetime.today(), "Removing intermediate files...") > + printdate("Removing intermediate files...") > remove_output_file(evsel_file) > remove_output_file(machine_file) > remove_output_file(thread_file) > @@ -626,7 +629,7 @@ def trace_end(): > if perf_db_export_calls: > remove_output_file(call_file) > os.rmdir(output_dir_name) > - print(datetime.datetime.today(), "Adding primary keys") > + printdate("Adding primary keys") > do_query(query, 'ALTER TABLE selected_events ADD PRIMARY KEY (id)') > do_query(query, 'ALTER TABLE machines ADD PRIMARY KEY (id)') > do_query(query, 'ALTER TABLE threads ADD PRIMARY KEY (id)') > @@ -641,7 +644,7 @@ def trace_end(): > if perf_db_export_calls: > do_query(query, 'ALTER TABLE calls ADD PRIMARY KEY (id)') > > - print(datetime.datetime.today(), "Adding foreign keys") > + printdate("Adding foreign keys") > do_query(query, 'ALTER TABLE threads ' > 'ADD CONSTRAINT machinefk FOREIGN KEY (machine_id) REFERENCES machines (id),' > 'ADD CONSTRAINT processfk FOREIGN KEY (process_id) REFERENCES threads (id)') > @@ -677,8 +680,8 @@ def trace_end(): > do_query(query, 'CREATE INDEX pid_idx ON calls (parent_id)') > > if (unhandled_count): > - print(datetime.datetime.today(), "Warning: ", unhandled_count, " unhandled events") > - print(datetime.datetime.today(), "Done") > + printdate("Warning: ", unhandled_count, " unhandled events") > + printdate("Done") > > def trace_unhandled(event_name, context, event_fields_dict): > global unhandled_count > diff --git a/tools/perf/scripts/python/export-to-sqlite.py b/tools/perf/scripts/python/export-to-sqlite.py > index 3da338243aed..3b71902a5a21 100644 > --- a/tools/perf/scripts/python/export-to-sqlite.py > +++ b/tools/perf/scripts/python/export-to-sqlite.py > @@ -65,6 +65,9 @@ perf_db_export_callchains = False > def printerr(*args, **keyword_args): > print(*args, file=sys.stderr, **keyword_args) > > +def printdate(*args, **kw_args): > + print(datetime.datetime.today(), *args, sep=' ', **kw_args) > + > def usage(): > printerr("Usage is: export-to-sqlite.py [] [] []"); > printerr("where: columns 'all' or 'branches'"); > @@ -105,7 +108,7 @@ def do_query_(q): > return > raise Exception("Query failed: " + q.lastError().text()) > > -print(datetime.datetime.today(), "Creating database ...") > +printdate("Creating database ...") > > db_exists = False > try: > @@ -383,7 +386,7 @@ if perf_db_export_calls: > call_query.prepare("INSERT INTO calls VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)") > > def trace_begin(): > - print(datetime.datetime.today(), "Writing records...") > + printdate("Writing records...") > do_query(query, 'BEGIN TRANSACTION') > # id == 0 means unknown. It is easier to create records for them than replace the zeroes with NULLs > evsel_table(0, "unknown") > @@ -402,14 +405,14 @@ unhandled_count = 0 > def trace_end(): > do_query(query, 'END TRANSACTION') > > - print(datetime.datetime.today(), "Adding indexes") > + printdate("Adding indexes") > if perf_db_export_calls: > do_query(query, 'CREATE INDEX pcpid_idx ON calls (parent_call_path_id)') > do_query(query, 'CREATE INDEX pid_idx ON calls (parent_id)') > > if (unhandled_count): > - print(datetime.datetime.today(), "Warning: ", unhandled_count, " unhandled events") > - print(datetime.datetime.today(), "Done") > + printdate("Warning: ", unhandled_count, " unhandled events") > + printdate("Done") > > def trace_unhandled(event_name, context, event_fields_dict): > global unhandled_count > -- > 2.16.4 -- - Arnaldo