tests/logexceptions.py
author Pierre-Yves David <pierre-yves.david@octobus.net>
Wed, 02 Oct 2019 18:16:02 -0400
changeset 43297 8a2925265402
parent 43076 2372284d9457
child 46819 d4ba4d51f85f
permissions -rw-r--r--
sidedatacopies: fast path data fetching if revision has no sidedata When using the side data mode, we know their won't be any copy information sidedata. Skipping revision restoration give an important speed boost. In the future, there will be other user of sidedata, reducing the efficiency of this. We should consider adding a dedicated flag in revlog V2 to preserve this optimisation. The current situation is good enough for now. revision: large amount; added files: large amount; rename small amount; c3b14617fbd7 9ba6ab77fd29 before: ! wall 2.401569 comb 2.400000 user 2.390000 sys 0.010000 (median of 10) after: ! wall 1.429294 comb 1.430000 user 1.410000 sys 0.020000 (median of 10) revision: large amount; added files: small amount; rename small amount; c3b14617fbd7 f650a9b140d2 before: ! wall 3.519140 comb 3.520000 user 3.470000 sys 0.050000 (median of 10) after: ! wall 1.963332 comb 1.960000 user 1.960000 sys 0.000000 (median of 10) revision: large amount; added files: large amount; rename large amount; 08ea3258278e d9fa043f30c0 before: ! wall 0.593880 comb 0.600000 user 0.590000 sys 0.010000 (median of 15) after: ! wall 0.251679 comb 0.250000 user 0.250000 sys 0.000000 (median of 38) revision: small amount; added files: large amount; rename large amount; df6f7a526b60 a83dc6a2d56f before: ! wall 0.013414 comb 0.020000 user 0.020000 sys 0.000000 (median of 220) after: ! wall 0.013222 comb 0.020000 user 0.020000 sys 0.000000 (median of 223) revision: small amount; added files: large amount; rename small amount; 4aa4e1f8e19a 169138063d63 before: ! wall 0.002711 comb 0.000000 user 0.000000 sys 0.000000 (median of 1000) after: ! wall 0.001631 comb 0.000000 user 0.000000 sys 0.000000 (median of 1000) revision: small amount; added files: small amount; rename small amount; 4bc173b045a6 964879152e2e before: ! wall 0.000077 comb 0.000000 user 0.000000 sys 0.000000 (median of 12208) after: ! wall 0.000078 comb 0.000000 user 0.000000 sys 0.000000 (median of 12012) revision: medium amount; added files: large amount; rename medium amount; c95f1ced15f2 2c68e87c3efe before: ! wall 0.410067 comb 0.410000 user 0.410000 sys 0.000000 (median of 23) after: ! wall 0.207786 comb 0.200000 user 0.200000 sys 0.000000 (median of 46) revision: medium amount; added files: medium amount; rename small amount; d343da0c55a8 d7746d32bf9d before: ! wall 0.097004 comb 0.090000 user 0.090000 sys 0.000000 (median of 100) after: ! wall 0.038495 comb 0.030000 user 0.030000 sys 0.000000 (median of 100) Differential Revision: https://phab.mercurial-scm.org/D7074
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
35190
bd8875b6473c run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
     1
# logexceptions.py - Write files containing info about Mercurial exceptions
bd8875b6473c run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
     2
#
bd8875b6473c run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
     3
# Copyright 2017 Matt Mackall <mpm@selenic.com>
bd8875b6473c run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
     4
#
bd8875b6473c run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
     5
# This software may be used and distributed according to the terms of the
bd8875b6473c run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
     6
# GNU General Public License version 2 or any later version.
bd8875b6473c run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
     7
bd8875b6473c run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
     8
from __future__ import absolute_import
bd8875b6473c run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
     9
bd8875b6473c run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    10
import inspect
bd8875b6473c run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    11
import os
bd8875b6473c run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    12
import sys
bd8875b6473c run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    13
import traceback
bd8875b6473c run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    14
import uuid
bd8875b6473c run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    15
bd8875b6473c run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    16
from mercurial import (
bd8875b6473c run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    17
    dispatch,
bd8875b6473c run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    18
    extensions,
bd8875b6473c run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    19
)
bd8875b6473c run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    20
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36037
diff changeset
    21
35190
bd8875b6473c run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    22
def handleexception(orig, ui):
bd8875b6473c run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    23
    res = orig(ui)
bd8875b6473c run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    24
bd8875b6473c run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    25
    if not ui.environ.get(b'HGEXCEPTIONSDIR'):
bd8875b6473c run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    26
        return res
bd8875b6473c run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    27
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36037
diff changeset
    28
    dest = os.path.join(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36037
diff changeset
    29
        ui.environ[b'HGEXCEPTIONSDIR'], str(uuid.uuid4()).encode('ascii')
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36037
diff changeset
    30
    )
35190
bd8875b6473c run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    31
bd8875b6473c run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    32
    exc_type, exc_value, exc_tb = sys.exc_info()
bd8875b6473c run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    33
bd8875b6473c run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    34
    stack = []
bd8875b6473c run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    35
    tb = exc_tb
bd8875b6473c run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    36
    while tb:
bd8875b6473c run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    37
        stack.append(tb)
bd8875b6473c run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    38
        tb = tb.tb_next
bd8875b6473c run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    39
    stack.reverse()
bd8875b6473c run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    40
bd8875b6473c run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    41
    hgframe = 'unknown'
bd8875b6473c run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    42
    hgline = 'unknown'
bd8875b6473c run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    43
bd8875b6473c run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    44
    # Find the first Mercurial frame in the stack.
bd8875b6473c run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    45
    for tb in stack:
bd8875b6473c run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    46
        mod = inspect.getmodule(tb)
bd8875b6473c run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    47
        if not mod.__name__.startswith(('hg', 'mercurial')):
bd8875b6473c run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    48
            continue
bd8875b6473c run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    49
bd8875b6473c run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    50
        frame = tb.tb_frame
bd8875b6473c run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    51
bd8875b6473c run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    52
        try:
bd8875b6473c run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    53
            with open(inspect.getsourcefile(tb), 'r') as fh:
bd8875b6473c run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    54
                hgline = fh.readlines()[frame.f_lineno - 1].strip()
bd8875b6473c run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    55
        except (IndexError, OSError):
bd8875b6473c run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    56
            pass
bd8875b6473c run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    57
bd8875b6473c run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    58
        hgframe = '%s:%d' % (frame.f_code.co_filename, frame.f_lineno)
bd8875b6473c run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    59
        break
bd8875b6473c run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    60
bd8875b6473c run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    61
    primary = traceback.extract_tb(exc_tb)[-1]
bd8875b6473c run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    62
    primaryframe = '%s:%d' % (primary.filename, primary.lineno)
bd8875b6473c run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    63
bd8875b6473c run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    64
    with open(dest, 'wb') as fh:
bd8875b6473c run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    65
        parts = [
bd8875b6473c run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    66
            str(exc_value),
bd8875b6473c run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    67
            primaryframe,
bd8875b6473c run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    68
            hgframe,
bd8875b6473c run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    69
            hgline,
36037
8de90e006c78 run-tests: report tests that exception occurred in
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35190
diff changeset
    70
            ui.environ[b'TESTNAME'].decode('utf-8', 'replace'),
35190
bd8875b6473c run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    71
        ]
bd8875b6473c run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    72
        fh.write(b'\0'.join(p.encode('utf-8', 'replace') for p in parts))
bd8875b6473c run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    73
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36037
diff changeset
    74
35190
bd8875b6473c run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    75
def extsetup(ui):
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36037
diff changeset
    76
    extensions.wrapfunction(dispatch, 'handlecommandexception', handleexception)