[LNT] r307804 - lnttool: Import things lazily
Matthias Braun via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 12 09:14:57 PDT 2017
Author: matze
Date: Wed Jul 12 09:14:56 2017
New Revision: 307804
URL: http://llvm.org/viewvc/llvm-project?rev=307804&view=rev
Log:
lnttool: Import things lazily
Import most python modules (except for some used by pretty much all
actions) lazily inside the action method. This cuts 300-400ms startup
time from `lnt --help` and hence from simple lnt commands as we don't
have to import all of sqlalchemy, flask etc.
= 5% time saved running the unit tests
Modified:
lnt/trunk/lnt/lnttool/convert.py
lnt/trunk/lnt/lnttool/create.py
lnt/trunk/lnt/lnttool/import_data.py
lnt/trunk/lnt/lnttool/import_report.py
lnt/trunk/lnt/lnttool/main.py
lnt/trunk/lnt/lnttool/updatedb.py
lnt/trunk/lnt/lnttool/viewcomparison.py
Modified: lnt/trunk/lnt/lnttool/convert.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/lnttool/convert.py?rev=307804&r1=307803&r2=307804&view=diff
==============================================================================
--- lnt/trunk/lnt/lnttool/convert.py (original)
+++ lnt/trunk/lnt/lnttool/convert.py Wed Jul 12 09:14:56 2017
@@ -1,13 +1,8 @@
-import os
-import sys
-
-import click
from lnt import formats
+import click
-def convert_data(input, output, inFormat, outFormat):
- from lnt import formats
-
+def _convert_data(input, output, inFormat, outFormat):
out = formats.get_format(outFormat)
if out is None or not out.get('write'):
raise SystemExit("unknown output format: %r" % outFormat)
@@ -29,10 +24,12 @@ def convert_data(input, output, inFormat
default='plist', help="output format")
def action_convert(input, output, input_format, output_format):
"""convert between input formats"""
+ import os
+ import sys
try:
try:
- convert_data(input, output, input_format, output_format)
+ _convert_data(input, output, input_format, output_format)
finally:
if output != sys.stdout:
output.close()
Modified: lnt/trunk/lnt/lnttool/create.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/lnttool/create.py?rev=307804&r1=307803&r2=307804&view=diff
==============================================================================
--- lnt/trunk/lnt/lnttool/create.py (original)
+++ lnt/trunk/lnt/lnttool/create.py Wed Jul 12 09:14:56 2017
@@ -1,15 +1,6 @@
-import hashlib
-import logging
-import os
-import platform
-import random
-import sys
-
import click
+import platform
-import lnt.testing
-import lnt.server.db.migrate
-from .common import init_logger
kConfigVersion = (0, 1, 0)
kConfigTemplate = """\
@@ -119,6 +110,14 @@ def action_create(instance_path, name, c
* INSTANCE_PATH should point to a directory that will keep
LNT configuration.
"""
+ from .common import init_logger
+ import hashlib
+ import lnt.server.db.migrate
+ import lnt.testing
+ import logging
+ import os
+ import random
+ import sys
init_logger(logging.INFO if show_sql else logging.WARNING,
show_sql=show_sql)
Modified: lnt/trunk/lnt/lnttool/import_data.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/lnttool/import_data.py?rev=307804&r1=307803&r2=307804&view=diff
==============================================================================
--- lnt/trunk/lnt/lnttool/import_data.py (original)
+++ lnt/trunk/lnt/lnttool/import_data.py Wed Jul 12 09:14:56 2017
@@ -1,13 +1,5 @@
-import contextlib
-import pprint
-import sys
-
import click
-
import lnt.formats
-import lnt.util.ImportData
-import lnt.server.instance
-
@click.command("import")
@click.argument("instance_path", type=click.UNPROCESSED)
@@ -31,6 +23,11 @@ def action_import(instance_path, files,
show_sql, show_sample_count, show_raw_result, testsuite,
verbose, quiet, no_email, no_report):
"""import test data into a database"""
+ import contextlib
+ import lnt.server.instance
+ import lnt.util.ImportData
+ import pprint
+ import sys
# Load the LNT instance.
instance = lnt.server.instance.Instance.frompath(instance_path)
Modified: lnt/trunk/lnt/lnttool/import_report.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/lnttool/import_report.py?rev=307804&r1=307803&r2=307804&view=diff
==============================================================================
--- lnt/trunk/lnt/lnttool/import_report.py (original)
+++ lnt/trunk/lnt/lnttool/import_report.py Wed Jul 12 09:14:56 2017
@@ -1,9 +1,5 @@
-import os
-
import click
-import lnt.testing
-
@click.command("importreport", short_help="import simple space separated "
"data into a report to submit.")
@@ -29,6 +25,8 @@ def action_importreport(input, output, s
The format is "test-name.metric", so exec and size are valid metrics for
the test suite you are submitting to.
"""
+ import lnt.testing
+ import os
machine_info = {}
run_info = {'tag': suite}
Modified: lnt/trunk/lnt/lnttool/main.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/lnttool/main.py?rev=307804&r1=307803&r2=307804&view=diff
==============================================================================
--- lnt/trunk/lnt/lnttool/main.py (original)
+++ lnt/trunk/lnt/lnttool/main.py Wed Jul 12 09:14:56 2017
@@ -1,23 +1,15 @@
"""Implement the command line 'lnt' tool."""
-import logging
-import os
-import sys
-import json
-import contextlib
-import code
-import click
-
-import lnt
-from lnt.util import logger
-import lnt.testing.profile.profile as profile
-
from .common import init_logger
-from .create import action_create
from .convert import action_convert
+from .create import action_create
from .import_data import action_import
+from .import_report import action_importreport
from .updatedb import action_updatedb
from .viewcomparison import action_view_comparison
-from .import_report import action_importreport
+from lnt.util import logger
+import click
+import logging
+import sys
@click.command("runserver", short_help="start a new development server")
@@ -54,6 +46,7 @@ passing database instances back and fort
view the results.
"""
import lnt.server.ui.app
+ import os
init_logger(logging.DEBUG, show_sql=show_sql)
@@ -71,6 +64,7 @@ view the results.
if shell:
from flask import current_app
from flask import g
+ import code
ctx = app.test_request_context()
ctx.push()
@@ -91,9 +85,8 @@ view the results.
@click.option("--testsuite", "-s", default='nts')
def action_checkformat(input_file, testsuite):
"""check the format of an LNT test report file"""
-
- import lnt.server.db.v4db
import lnt.server.config
+ import lnt.server.db.v4db
import lnt.util.ImportData
db = lnt.server.db.v4db.V4DB('sqlite:///:memory:',
lnt.server.config.Config.dummy_instance())
@@ -155,13 +148,13 @@ def action_showtests():
help="show verbose test results")
def action_submit(url, files, commit, verbose):
"""submit a test report to the server"""
+ from lnt.util import ServerUtil
+ import lnt.util.ImportData
if not commit:
logger.warning("submit called with --commit=0, " +
"your results will not be saved at the server.")
- from lnt.util import ServerUtil
- import lnt.util.ImportData
files = ServerUtil.submitFiles(url, files, commit, verbose)
for submitted_file in files:
if verbose:
@@ -175,7 +168,6 @@ def action_submit(url, files, commit, ve
@click.option("--show-sql", is_flag=True, help="show all SQL queries")
def action_update(db_path, show_sql):
"""create and or auto-update the given database"""
-
init_logger(logging.INFO, show_sql=show_sql, stream=sys.stderr)
# Update the database.
@@ -205,12 +197,12 @@ def action_send_daily_report(instance_pa
from_address, today, subject_prefix, dry_run,
days, filter_machine_regex):
"""send a daily report email"""
+ import contextlib
import datetime
import email.mime.multipart
import email.mime.text
- import smtplib
-
import lnt.server.reporting.dailyreport
+ import smtplib
# Load the LNT instance.
instance = lnt.server.instance.Instance.frompath(instance_path)
@@ -298,10 +290,11 @@ def action_send_run_comparison(instance_
testsuite, host, from_address, to_address,
subject_prefix, dry_run):
"""send a run-vs-run comparison email"""
+ import contextlib
import email.mime.multipart
import email.mime.text
- import smtplib
import lnt.server.reporting.dailyreport
+ import smtplib
init_logger(logging.ERROR)
@@ -380,6 +373,7 @@ def action_profile():
@click.argument("output", type=click.Path(exists=True))
def command_update(input, output):
"""upgrade a profile to the latest version"""
+ import lnt.testing.profile.profile as profile
profile.Profile.fromFile(input).upgrade().save(filename=output)
@@ -387,6 +381,7 @@ def command_update(input, output):
@click.argument("input", type=click.Path(exists=True))
def command_get_version(input):
"""print the version of a profile"""
+ import lnt.testing.profile.profile as profile
print profile.Profile.fromFile(input).getVersion()
@@ -394,6 +389,8 @@ def command_get_version(input):
@click.argument("input", type=click.Path(exists=True))
def command_top_level_counters(input):
"""print the whole-profile counter values"""
+ import json
+ import lnt.testing.profile.profile as profile
print json.dumps(profile.Profile.fromFile(input).getTopLevelCounters())
@@ -401,6 +398,8 @@ def command_top_level_counters(input):
@click.argument("input", type=click.Path(exists=True))
def command_get_functions(input):
"""print the functions in a profile"""
+ import json
+ import lnt.testing.profile.profile as profile
print json.dumps(profile.Profile.fromFile(input).getFunctions())
@@ -409,6 +408,8 @@ def command_get_functions(input):
@click.argument('fn')
def command_code_for_function(input, fn):
"""print the code/instruction for a function"""
+ import json
+ import lnt.testing.profile.profile as profile
print json.dumps(
list(profile.Profile.fromFile(input).getCodeForFunction(fn)))
@@ -423,6 +424,7 @@ def _version_check():
requirements).
"""
import pkg_resources
+ import lnt
# Get the current distribution.
installed_dist = pkg_resources.get_distribution("LNT")
@@ -439,6 +441,7 @@ LNT or rerun 'setup.py develop' if using
def show_version(ctx, param, value):
"""print LNT version"""
+ import lnt
if not value or ctx.resilient_parsing:
return
if lnt.__version__:
Modified: lnt/trunk/lnt/lnttool/updatedb.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/lnttool/updatedb.py?rev=307804&r1=307803&r2=307804&view=diff
==============================================================================
--- lnt/trunk/lnt/lnttool/updatedb.py (original)
+++ lnt/trunk/lnt/lnttool/updatedb.py Wed Jul 12 09:14:56 2017
@@ -1,9 +1,5 @@
-import contextlib
import click
-import lnt.server.instance
-from lnt.util import logger
-
@click.command("updatedb")
@click.argument("instance_path", type=click.UNPROCESSED)
@@ -26,6 +22,9 @@ from lnt.util import logger
def action_updatedb(instance_path, database, testsuite, tmp_dir, commit,
show_sql, delete_machines, delete_runs, delete_order):
"""modify a database"""
+ from lnt.util import logger
+ import contextlib
+ import lnt.server.instance
# Load the instance.
instance = lnt.server.instance.Instance.frompath(instance_path)
Modified: lnt/trunk/lnt/lnttool/viewcomparison.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/lnttool/viewcomparison.py?rev=307804&r1=307803&r2=307804&view=diff
==============================================================================
--- lnt/trunk/lnt/lnttool/viewcomparison.py (original)
+++ lnt/trunk/lnt/lnttool/viewcomparison.py Wed Jul 12 09:14:56 2017
@@ -1,22 +1,7 @@
-import logging
-import os
-import shutil
-import sys
-import tempfile
-import thread
-import time
-import urllib
-import webbrowser
-import contextlib
-
import click
-from lnt.util import logger
-from lnt.util.ImportData import import_and_report
-from .common import init_logger
-
-def start_browser(url, debug=False):
+def _start_browser(url, debug=False):
def url_is_up(url):
try:
o = urllib.urlopen(url)
@@ -56,10 +41,22 @@ def start_browser(url, debug=False):
def action_view_comparison(report_a, report_b, hostname, port, dry_run,
testsuite):
"""view a report comparison using a temporary server"""
-
+ from .common import init_logger
+ from lnt.util import logger
+ from lnt.util.ImportData import import_and_report
+ import contextlib
+ import lnt.server.db.migrate
import lnt.server.instance
import lnt.server.ui.app
- import lnt.server.db.migrate
+ import logging
+ import os
+ import shutil
+ import sys
+ import tempfile
+ import thread
+ import time
+ import urllib
+ import webbrowser
init_logger(logging.ERROR)
@@ -96,7 +93,7 @@ def action_view_comparison(report_a, rep
logger.info("opening comparison view: %s" % (comparison_url,))
if not dry_run:
- thread.start_new_thread(start_browser, (comparison_url, True))
+ thread.start_new_thread(_start_browser, (comparison_url, True))
# Run the webserver.
app = lnt.server.ui.app.App.create_with_instance(instance)
More information about the llvm-commits
mailing list