Best Python code snippet using autotest_python
result_entry.py
Source:result_entry.py  
1# coding: utf-82from __future__ import absolute_import3from datetime import date, datetime  # noqa: F4014from typing import List, Dict  # noqa: F4015from nwrsc.api.models.base_model_ import Model6from nwrsc.api.models.decorated_run import DecoratedRun  # noqa: F401,E5017from nwrsc.api import util8class ResultEntry(Model):9    """NOTE: This class is auto generated by the swagger code generator program.10    Do not edit the class manually.11    """12    def __init__(self, driverid: str=None, carid: str=None, firstname: str=None, lastname: str=None, year: str=None, make: str=None, model: str=None, color: str=None, number: int=None, classcode: str=None, indexcode: str=None, indexstr: str=None, useclsmult: bool=None, indexval: float=None, rungroup: int=None, runs: List[DecoratedRun]=None, net: float=None, pen: float=None, netall: float=None, penall: float=None, position: int=None, diff1: float=None, diffn: float=None, pospoints: int=None, diffpoints: float=None, points: float=None, trophy: bool=None, modified: datetime=None):  # noqa: E50113        """ResultEntry - a model defined in Swagger14        :param driverid: The driverid of this ResultEntry.  # noqa: E50115        :type driverid: str16        :param carid: The carid of this ResultEntry.  # noqa: E50117        :type carid: str18        :param firstname: The firstname of this ResultEntry.  # noqa: E50119        :type firstname: str20        :param lastname: The lastname of this ResultEntry.  # noqa: E50121        :type lastname: str22        :param year: The year of this ResultEntry.  # noqa: E50123        :type year: str24        :param make: The make of this ResultEntry.  # noqa: E50125        :type make: str26        :param model: The model of this ResultEntry.  # noqa: E50127        :type model: str28        :param color: The color of this ResultEntry.  # noqa: E50129        :type color: str30        :param number: The number of this ResultEntry.  # noqa: E50131        :type number: int32        :param classcode: The classcode of this ResultEntry.  # noqa: E50133        :type classcode: str34        :param indexcode: The indexcode of this ResultEntry.  # noqa: E50135        :type indexcode: str36        :param indexstr: The indexstr of this ResultEntry.  # noqa: E50137        :type indexstr: str38        :param useclsmult: The useclsmult of this ResultEntry.  # noqa: E50139        :type useclsmult: bool40        :param indexval: The indexval of this ResultEntry.  # noqa: E50141        :type indexval: float42        :param rungroup: The rungroup of this ResultEntry.  # noqa: E50143        :type rungroup: int44        :param runs: The runs of this ResultEntry.  # noqa: E50145        :type runs: List[DecoratedRun]46        :param net: The net of this ResultEntry.  # noqa: E50147        :type net: float48        :param pen: The pen of this ResultEntry.  # noqa: E50149        :type pen: float50        :param netall: The netall of this ResultEntry.  # noqa: E50151        :type netall: float52        :param penall: The penall of this ResultEntry.  # noqa: E50153        :type penall: float54        :param position: The position of this ResultEntry.  # noqa: E50155        :type position: int56        :param diff1: The diff1 of this ResultEntry.  # noqa: E50157        :type diff1: float58        :param diffn: The diffn of this ResultEntry.  # noqa: E50159        :type diffn: float60        :param pospoints: The pospoints of this ResultEntry.  # noqa: E50161        :type pospoints: int62        :param diffpoints: The diffpoints of this ResultEntry.  # noqa: E50163        :type diffpoints: float64        :param points: The points of this ResultEntry.  # noqa: E50165        :type points: float66        :param trophy: The trophy of this ResultEntry.  # noqa: E50167        :type trophy: bool68        :param modified: The modified of this ResultEntry.  # noqa: E50169        :type modified: datetime70        """71        self.swagger_types = {72            'driverid': str,73            'carid': str,74            'firstname': str,75            'lastname': str,76            'year': str,77            'make': str,78            'model': str,79            'color': str,80            'number': int,81            'classcode': str,82            'indexcode': str,83            'indexstr': str,84            'useclsmult': bool,85            'indexval': float,86            'rungroup': int,87            'runs': List[DecoratedRun],88            'net': float,89            'pen': float,90            'netall': float,91            'penall': float,92            'position': int,93            'diff1': float,94            'diffn': float,95            'pospoints': int,96            'diffpoints': float,97            'points': float,98            'trophy': bool,99            'modified': datetime100        }101        self.attribute_map = {102            'driverid': 'driverid',103            'carid': 'carid',104            'firstname': 'firstname',105            'lastname': 'lastname',106            'year': 'year',107            'make': 'make',108            'model': 'model',109            'color': 'color',110            'number': 'number',111            'classcode': 'classcode',112            'indexcode': 'indexcode',113            'indexstr': 'indexstr',114            'useclsmult': 'useclsmult',115            'indexval': 'indexval',116            'rungroup': 'rungroup',117            'runs': 'runs',118            'net': 'net',119            'pen': 'pen',120            'netall': 'netall',121            'penall': 'penall',122            'position': 'position',123            'diff1': 'diff1',124            'diffn': 'diffn',125            'pospoints': 'pospoints',126            'diffpoints': 'diffpoints',127            'points': 'points',128            'trophy': 'trophy',129            'modified': 'modified'130        }131        self._driverid = driverid132        self._carid = carid133        self._firstname = firstname134        self._lastname = lastname135        self._year = year136        self._make = make137        self._model = model138        self._color = color139        self._number = number140        self._classcode = classcode141        self._indexcode = indexcode142        self._indexstr = indexstr143        self._useclsmult = useclsmult144        self._indexval = indexval145        self._rungroup = rungroup146        self._runs = runs147        self._net = net148        self._pen = pen149        self._netall = netall150        self._penall = penall151        self._position = position152        self._diff1 = diff1153        self._diffn = diffn154        self._pospoints = pospoints155        self._diffpoints = diffpoints156        self._points = points157        self._trophy = trophy158        self._modified = modified159    @classmethod160    def from_dict(cls, dikt) -> 'ResultEntry':161        """Returns the dict as a model162        :param dikt: A dict.163        :type: dict164        :return: The ResultEntry of this ResultEntry.  # noqa: E501165        :rtype: ResultEntry166        """167        return util.deserialize_model(dikt, cls)168    @property169    def driverid(self) -> str:170        """Gets the driverid of this ResultEntry.171        the UUID of the driver  # noqa: E501172        :return: The driverid of this ResultEntry.173        :rtype: str174        """175        return self._driverid176    @driverid.setter177    def driverid(self, driverid: str):178        """Sets the driverid of this ResultEntry.179        the UUID of the driver  # noqa: E501180        :param driverid: The driverid of this ResultEntry.181        :type driverid: str182        """183        self._driverid = driverid184    @property185    def carid(self) -> str:186        """Gets the carid of this ResultEntry.187        the UUID of the car  # noqa: E501188        :return: The carid of this ResultEntry.189        :rtype: str190        """191        return self._carid192    @carid.setter193    def carid(self, carid: str):194        """Sets the carid of this ResultEntry.195        the UUID of the car  # noqa: E501196        :param carid: The carid of this ResultEntry.197        :type carid: str198        """199        self._carid = carid200    @property201    def firstname(self) -> str:202        """Gets the firstname of this ResultEntry.203        the driver firstname  # noqa: E501204        :return: The firstname of this ResultEntry.205        :rtype: str206        """207        return self._firstname208    @firstname.setter209    def firstname(self, firstname: str):210        """Sets the firstname of this ResultEntry.211        the driver firstname  # noqa: E501212        :param firstname: The firstname of this ResultEntry.213        :type firstname: str214        """215        self._firstname = firstname216    @property217    def lastname(self) -> str:218        """Gets the lastname of this ResultEntry.219        the driver lastname  # noqa: E501220        :return: The lastname of this ResultEntry.221        :rtype: str222        """223        return self._lastname224    @lastname.setter225    def lastname(self, lastname: str):226        """Sets the lastname of this ResultEntry.227        the driver lastname  # noqa: E501228        :param lastname: The lastname of this ResultEntry.229        :type lastname: str230        """231        self._lastname = lastname232    @property233    def year(self) -> str:234        """Gets the year of this ResultEntry.235        the car year  # noqa: E501236        :return: The year of this ResultEntry.237        :rtype: str238        """239        return self._year240    @year.setter241    def year(self, year: str):242        """Sets the year of this ResultEntry.243        the car year  # noqa: E501244        :param year: The year of this ResultEntry.245        :type year: str246        """247        self._year = year248    @property249    def make(self) -> str:250        """Gets the make of this ResultEntry.251        the car make  # noqa: E501252        :return: The make of this ResultEntry.253        :rtype: str254        """255        return self._make256    @make.setter257    def make(self, make: str):258        """Sets the make of this ResultEntry.259        the car make  # noqa: E501260        :param make: The make of this ResultEntry.261        :type make: str262        """263        self._make = make264    @property265    def model(self) -> str:266        """Gets the model of this ResultEntry.267        the car model  # noqa: E501268        :return: The model of this ResultEntry.269        :rtype: str270        """271        return self._model272    @model.setter273    def model(self, model: str):274        """Sets the model of this ResultEntry.275        the car model  # noqa: E501276        :param model: The model of this ResultEntry.277        :type model: str278        """279        self._model = model280    @property281    def color(self) -> str:282        """Gets the color of this ResultEntry.283        the car color  # noqa: E501284        :return: The color of this ResultEntry.285        :rtype: str286        """287        return self._color288    @color.setter289    def color(self, color: str):290        """Sets the color of this ResultEntry.291        the car color  # noqa: E501292        :param color: The color of this ResultEntry.293        :type color: str294        """295        self._color = color296    @property297    def number(self) -> int:298        """Gets the number of this ResultEntry.299        the car number  # noqa: E501300        :return: The number of this ResultEntry.301        :rtype: int302        """303        return self._number304    @number.setter305    def number(self, number: int):306        """Sets the number of this ResultEntry.307        the car number  # noqa: E501308        :param number: The number of this ResultEntry.309        :type number: int310        """311        self._number = number312    @property313    def classcode(self) -> str:314        """Gets the classcode of this ResultEntry.315        the car classcode (in series classlist)  # noqa: E501316        :return: The classcode of this ResultEntry.317        :rtype: str318        """319        return self._classcode320    @classcode.setter321    def classcode(self, classcode: str):322        """Sets the classcode of this ResultEntry.323        the car classcode (in series classlist)  # noqa: E501324        :param classcode: The classcode of this ResultEntry.325        :type classcode: str326        """327        self._classcode = classcode328    @property329    def indexcode(self) -> str:330        """Gets the indexcode of this ResultEntry.331        the car indexcode (in series indexlist)  # noqa: E501332        :return: The indexcode of this ResultEntry.333        :rtype: str334        """335        return self._indexcode336    @indexcode.setter337    def indexcode(self, indexcode: str):338        """Sets the indexcode of this ResultEntry.339        the car indexcode (in series indexlist)  # noqa: E501340        :param indexcode: The indexcode of this ResultEntry.341        :type indexcode: str342        """343        self._indexcode = indexcode344    @property345    def indexstr(self) -> str:346        """Gets the indexstr of this ResultEntry.347        the displayed indexcode (may have indentifiers such as * if special handling is provided)  # noqa: E501348        :return: The indexstr of this ResultEntry.349        :rtype: str350        """351        return self._indexstr352    @indexstr.setter353    def indexstr(self, indexstr: str):354        """Sets the indexstr of this ResultEntry.355        the displayed indexcode (may have indentifiers such as * if special handling is provided)  # noqa: E501356        :param indexstr: The indexstr of this ResultEntry.357        :type indexstr: str358        """359        self._indexstr = indexstr360    @property361    def useclsmult(self) -> bool:362        """Gets the useclsmult of this ResultEntry.363        true if the flag is set that will selectively apply the classcode multiplier (not common)  # noqa: E501364        :return: The useclsmult of this ResultEntry.365        :rtype: bool366        """367        return self._useclsmult368    @useclsmult.setter369    def useclsmult(self, useclsmult: bool):370        """Sets the useclsmult of this ResultEntry.371        true if the flag is set that will selectively apply the classcode multiplier (not common)  # noqa: E501372        :param useclsmult: The useclsmult of this ResultEntry.373        :type useclsmult: bool374        """375        self._useclsmult = useclsmult376    @property377    def indexval(self) -> float:378        """Gets the indexval of this ResultEntry.379        the compiled index value to use (includes zero or more of class index, car index and class multiplier)  # noqa: E501380        :return: The indexval of this ResultEntry.381        :rtype: float382        """383        return self._indexval384    @indexval.setter385    def indexval(self, indexval: float):386        """Sets the indexval of this ResultEntry.387        the compiled index value to use (includes zero or more of class index, car index and class multiplier)  # noqa: E501388        :param indexval: The indexval of this ResultEntry.389        :type indexval: float390        """391        self._indexval = indexval392    @property393    def rungroup(self) -> int:394        """Gets the rungroup of this ResultEntry.395        the rungroup this entry ran in  # noqa: E501396        :return: The rungroup of this ResultEntry.397        :rtype: int398        """399        return self._rungroup400    @rungroup.setter401    def rungroup(self, rungroup: int):402        """Sets the rungroup of this ResultEntry.403        the rungroup this entry ran in  # noqa: E501404        :param rungroup: The rungroup of this ResultEntry.405        :type rungroup: int406        """407        self._rungroup = rungroup408    @property409    def runs(self) -> List[DecoratedRun]:410        """Gets the runs of this ResultEntry.411        an array of runs  # noqa: E501412        :return: The runs of this ResultEntry.413        :rtype: List[DecoratedRun]414        """415        return self._runs416    @runs.setter417    def runs(self, runs: List[DecoratedRun]):418        """Sets the runs of this ResultEntry.419        an array of runs  # noqa: E501420        :param runs: The runs of this ResultEntry.421        :type runs: List[DecoratedRun]422        """423        self._runs = runs424    @property425    def net(self) -> float:426        """Gets the net of this ResultEntry.427        the sum net time of the best COUNTED run from each course  # noqa: E501428        :return: The net of this ResultEntry.429        :rtype: float430        """431        return self._net432    @net.setter433    def net(self, net: float):434        """Sets the net of this ResultEntry.435        the sum net time of the best COUNTED run from each course  # noqa: E501436        :param net: The net of this ResultEntry.437        :type net: float438        """439        self._net = net440    @property441    def pen(self) -> float:442        """Gets the pen of this ResultEntry.443        the sum unindexed time of COUNTED runs from each course (includes penalties)  # noqa: E501444        :return: The pen of this ResultEntry.445        :rtype: float446        """447        return self._pen448    @pen.setter449    def pen(self, pen: float):450        """Sets the pen of this ResultEntry.451        the sum unindexed time of COUNTED runs from each course (includes penalties)  # noqa: E501452        :param pen: The pen of this ResultEntry.453        :type pen: float454        """455        self._pen = pen456    @property457    def netall(self) -> float:458        """Gets the netall of this ResultEntry.459        the sum net time of the best run from each course  # noqa: E501460        :return: The netall of this ResultEntry.461        :rtype: float462        """463        return self._netall464    @netall.setter465    def netall(self, netall: float):466        """Sets the netall of this ResultEntry.467        the sum net time of the best run from each course  # noqa: E501468        :param netall: The netall of this ResultEntry.469        :type netall: float470        """471        self._netall = netall472    @property473    def penall(self) -> float:474        """Gets the penall of this ResultEntry.475        the sum unindexed time of the best run from each course (includes penalties)  # noqa: E501476        :return: The penall of this ResultEntry.477        :rtype: float478        """479        return self._penall480    @penall.setter481    def penall(self, penall: float):482        """Sets the penall of this ResultEntry.483        the sum unindexed time of the best run from each course (includes penalties)  # noqa: E501484        :param penall: The penall of this ResultEntry.485        :type penall: float486        """487        self._penall = penall488    @property489    def position(self) -> int:490        """Gets the position of this ResultEntry.491        the finishing position in class  # noqa: E501492        :return: The position of this ResultEntry.493        :rtype: int494        """495        return self._position496    @position.setter497    def position(self, position: int):498        """Sets the position of this ResultEntry.499        the finishing position in class  # noqa: E501500        :param position: The position of this ResultEntry.501        :type position: int502        """503        self._position = position504    @property505    def diff1(self) -> float:506        """Gets the diff1 of this ResultEntry.507        the difference in time to first place: (net1 - netx)/indexval  # noqa: E501508        :return: The diff1 of this ResultEntry.509        :rtype: float510        """511        return self._diff1512    @diff1.setter513    def diff1(self, diff1: float):514        """Sets the diff1 of this ResultEntry.515        the difference in time to first place: (net1 - netx)/indexval  # noqa: E501516        :param diff1: The diff1 of this ResultEntry.517        :type diff1: float518        """519        self._diff1 = diff1520    @property521    def diffn(self) -> float:522        """Gets the diffn of this ResultEntry.523        the difference in time to the next position: (netn - netx)/indexval  # noqa: E501524        :return: The diffn of this ResultEntry.525        :rtype: float526        """527        return self._diffn528    @diffn.setter529    def diffn(self, diffn: float):530        """Sets the diffn of this ResultEntry.531        the difference in time to the next position: (netn - netx)/indexval  # noqa: E501532        :param diffn: The diffn of this ResultEntry.533        :type diffn: float534        """535        self._diffn = diffn536    @property537    def pospoints(self) -> int:538        """Gets the pospoints of this ResultEntry.539        the championship points for the current position  # noqa: E501540        :return: The pospoints of this ResultEntry.541        :rtype: int542        """543        return self._pospoints544    @pospoints.setter545    def pospoints(self, pospoints: int):546        """Sets the pospoints of this ResultEntry.547        the championship points for the current position  # noqa: E501548        :param pospoints: The pospoints of this ResultEntry.549        :type pospoints: int550        """551        self._pospoints = pospoints552    @property553    def diffpoints(self) -> float:554        """Gets the diffpoints of this ResultEntry.555        the championship points based on difference from first  # noqa: E501556        :return: The diffpoints of this ResultEntry.557        :rtype: float558        """559        return self._diffpoints560    @diffpoints.setter561    def diffpoints(self, diffpoints: float):562        """Sets the diffpoints of this ResultEntry.563        the championship points based on difference from first  # noqa: E501564        :param diffpoints: The diffpoints of this ResultEntry.565        :type diffpoints: float566        """567        self._diffpoints = diffpoints568    @property569    def points(self) -> float:570        """Gets the points of this ResultEntry.571        one of pospoints or diffpoints depending on the series settings  # noqa: E501572        :return: The points of this ResultEntry.573        :rtype: float574        """575        return self._points576    @points.setter577    def points(self, points: float):578        """Sets the points of this ResultEntry.579        one of pospoints or diffpoints depending on the series settings  # noqa: E501580        :param points: The points of this ResultEntry.581        :type points: float582        """583        self._points = points584    @property585    def trophy(self) -> bool:586        """Gets the trophy of this ResultEntry.587        true if this position is awarded a trophy for the event  # noqa: E501588        :return: The trophy of this ResultEntry.589        :rtype: bool590        """591        return self._trophy592    @trophy.setter593    def trophy(self, trophy: bool):594        """Sets the trophy of this ResultEntry.595        true if this position is awarded a trophy for the event  # noqa: E501596        :param trophy: The trophy of this ResultEntry.597        :type trophy: bool598        """599        self._trophy = trophy600    @property601    def modified(self) -> datetime:602        """Gets the modified of this ResultEntry.603        the mod time  # noqa: E501604        :return: The modified of this ResultEntry.605        :rtype: datetime606        """607        return self._modified608    @modified.setter609    def modified(self, modified: datetime):610        """Sets the modified of this ResultEntry.611        the mod time  # noqa: E501612        :param modified: The modified of this ResultEntry.613        :type modified: datetime614        """...process_profiles.py
Source:process_profiles.py  
1#!/usr/bin/env vpython2# Copyright 2017 The Chromium Authors. All rights reserved.3# Use of this source code is governed by a BSD-style license that can be4# found in the LICENSE file.5"""Lists all the reached symbols from an instrumentation dump."""6import argparse7import logging8import operator9import os10import sys11_SRC_PATH = os.path.abspath(os.path.join(12    os.path.dirname(__file__), os.pardir, os.pardir))13path = os.path.join(_SRC_PATH, 'tools', 'cygprofile')14sys.path.append(path)15import symbol_extractor16def _Median(items):17  if not items:18    return None19  sorted_items = sorted(items)20  if len(sorted_items) & 1:21    return sorted_items[len(sorted_items)/2]22  else:23    return (sorted_items[len(sorted_items)/2 - 1] +24            sorted_items[len(sorted_items)/2]) / 225class SymbolOffsetProcessor(object):26  """Utility for processing symbols in binaries.27  This class is used to translate between general offsets into a binary and the28  starting offset of symbols in the binary. Because later phases in orderfile29  generation have complicated strategies for resolving multiple symbols that map30  to the same binary offset, this class is concerned with locating a symbol31  containing a binary offset. If such a symbol exists, the start offset will be32  unique, even when there are multiple symbol names at the same location in the33  binary.34  In the function names below, "dump" is used to refer to arbitrary offsets in a35  binary (eg, from a profiling run), while "offset" refers to a symbol36  offset. The dump offsets are relative to the start of text, as returned by37  lightweight_cygprofile.cc.38  This class manages expensive operations like extracting symbols, so that39  higher-level operations can be done in different orders without the caller40  managing all the state.41  """42  def __init__(self, binary_filename):43    self._binary_filename = binary_filename44    self._symbol_infos = None45    self._name_to_symbol = None46    self._offset_to_primary = None47    self._offset_to_symbols = None48  def SymbolInfos(self):49    """The symbols associated with this processor's binary.50    The symbols are ordered by offset.51    Returns:52      [symbol_extractor.SymbolInfo]53    """54    if self._symbol_infos is None:55      self._symbol_infos = symbol_extractor.SymbolInfosFromBinary(56          self._binary_filename)57      self._symbol_infos.sort(key=lambda s: s.offset)58      logging.info('%d symbols from %s',59                   len(self._symbol_infos), self._binary_filename)60    return self._symbol_infos61  def NameToSymbolMap(self):62    """Map symbol names to their full information.63    Returns:64      {symbol name (str): symbol_extractor.SymbolInfo}65    """66    if self._name_to_symbol is None:67      self._name_to_symbol = {s.name: s for s in self.SymbolInfos()}68    return self._name_to_symbol69  def OffsetToPrimaryMap(self):70    """The map of a symbol offset in this binary to its primary symbol.71    Several symbols can be aliased to the same address, through ICF. This72    returns the first one. The order is consistent for a given binary, as it's73    derived from the file layout. We assert that all aliased symbols are the74    same size.75    Returns:76      {offset (int): primary (symbol_extractor.SymbolInfo)}77    """78    if self._offset_to_primary is None:79      self._offset_to_primary = {}80      for s in self.SymbolInfos():81        if s.offset not in self._offset_to_primary:82          self._offset_to_primary[s.offset] = s83        else:84          curr = self._offset_to_primary[s.offset]85          if curr.size != s.size:86            assert curr.size == 0 or s.size == 0, (87                'Nonzero size mismatch between {} and {}'.format(88                    curr.name, s.name))89            # Upgrade to a symbol with nonzero size, otherwise don't change90            # anything so that we use the earliest nonzero-size symbol.91            if curr.size == 0 and s.size != 0:92              self._offset_to_primary[s.offset] = s93    return self._offset_to_primary94  def OffsetToSymbolsMap(self):95    """Map offsets to the set of matching symbols.96    Unlike OffsetToPrimaryMap, this is a 1-to-many mapping.97    Returns;98      {offset (int): [symbol_extractor.SymbolInfo]}99    """100    if self._offset_to_symbols is None:101      self._offset_to_symbols = symbol_extractor.GroupSymbolInfosByOffset(102          self.SymbolInfos())103    return self._offset_to_symbols104  def OffsetsPrimarySize(self, offsets):105    """Computes the total primary size of a set of offsets.106    Args:107      offsets (int iterable) a set of offsets.108    Returns109      int The sum of the primary size of the offsets.110    """111    return sum(self.OffsetToPrimaryMap()[x].size for x in offsets)112  def GetReachedOffsetsFromDump(self, dump):113    """Find the symbol offsets from a list of binary offsets.114    The dump is a list offsets into a .text section. This finds the symbols115    which contain the dump offsets, and returns their offsets. Note that while116    usually a symbol offset corresponds to a single symbol, in some cases117    several symbols will map to the same offset. For that reason this function118    returns only the offset list. See cyglog_to_orderfile.py for computing more119    information about symbols.120    Args:121     dump: (int iterable) Dump offsets, for example as returned by MergeDumps().122    Returns:123      [int] Reached symbol offsets.124    """125    dump_offset_to_symbol_info = self._GetDumpOffsetToSymbolInfo()126    logging.info('Offset to Symbol size = %d', len(dump_offset_to_symbol_info))127    assert max(dump) / 4 <= len(dump_offset_to_symbol_info)128    already_seen = set()129    reached_offsets = []130    reached_return_addresses_not_found = 0131    for dump_offset in dump:132      symbol_info = dump_offset_to_symbol_info[dump_offset / 4]133      if symbol_info is None:134        reached_return_addresses_not_found += 1135        continue136      if symbol_info.offset in already_seen:137        continue138      reached_offsets.append(symbol_info.offset)139      already_seen.add(symbol_info.offset)140    if reached_return_addresses_not_found:141      logging.warning('%d return addresses don\'t map to any symbol',142                      reached_return_addresses_not_found)143    return reached_offsets144  def MatchSymbolNames(self, symbol_names):145    """Find the symbols in this binary which match a list of symbols.146    Args:147      symbol_names (str iterable) List of symbol names.148    Returns:149      [symbol_extractor.SymbolInfo] Symbols in this binary matching the names.150    """151    our_symbol_names = set(s.name for s in self.SymbolInfos())152    matched_names = our_symbol_names.intersection(set(symbol_names))153    return [self.NameToSymbolMap()[n] for n in matched_names]154  def _GetDumpOffsetToSymbolInfo(self):155    """Computes an array mapping each word in .text to a symbol.156    Returns:157      [symbol_extractor.SymbolInfo or None] For every 4 bytes of the .text158        section, maps it to a symbol, or None.159    """160    min_offset = min(s.offset for s in self.SymbolInfos())161    max_offset = max(s.offset + s.size for s in self.SymbolInfos())162    text_length_words = (max_offset - min_offset) / 4163    offset_to_symbol_info = [None for _ in xrange(text_length_words)]164    for s in self.SymbolInfos():165      offset = s.offset - min_offset166      for i in range(offset / 4, (offset + s.size) / 4):167        offset_to_symbol_info[i] = s168    return offset_to_symbol_info169class ProfileManager(object):170  """Manipulates sets of profiles.171  The manager supports only lightweight-style profiles (see172  lightweight_cygprofile.cc) and not the older cygprofile offset lists.173  A "profile set" refers to a set of data from an instrumented version of chrome174  that will be processed together, usually to produce a single orderfile. A175  "run" refers to a session of chrome, visiting several pages and thus176  comprising a browser process and at least one renderer process. A "dump"177  refers to the instrumentation in chrome writing out offsets of instrumented178  functions. There may be several dumps per run, for example one describing179  chrome startup and a second describing steady-state page interaction. Each180  process in a run produces one file per dump.181  These dump files have a timestamp of the dump time. Each process produces its182  own timestamp, but the dumps from each process occur very near in time to each183  other (< 1 second). If there are several dumps per run, each set of dumps is184  marked by a "phase" in the filename which is consistent across processes. For185  example the dump for the startup could be phase 0 and then the steady-state186  would be labeled phase 1.187  We assume the files are named like *-TIMESTAMP.SUFFIX_PHASE, where TIMESTAMP188  is in nanoseconds, SUFFIX is string without dashes, PHASE is an integer189  numbering the phases as 0, 1, 2..., and the only dot is the one between190  TIMESTAMP and SUFFIX. Note that the current dump filename also includes a191  process id which is currently unused.192  This manager supports several configurations of dumps.193  * A single dump from a single run. These files are merged together to produce194    a single dump without regard for browser versus renderer methods.195  * Several phases of dumps from a single run. Files are grouped by phase as196    described above.197  * Several phases of dumps from multiple runs from a set of telemetry198    benchmarks. The timestamp is used to distinguish each run because each199    benchmark takes < 10 seconds to run but there are > 50 seconds of setup200    time. This files can be grouped into run sets that are within 30 seconds of201    each other. Each run set is then grouped into phases as before.202  """203  class _RunGroup(object):204    RUN_GROUP_THRESHOLD_NS = 30e9205    def __init__(self):206      self._filenames = []207    def Filenames(self, phase=None):208      if phase is None:209        return self._filenames210      return [f for f in self._filenames211              if ProfileManager._Phase(f) == phase]212    def Add(self, filename):213      self._filenames.append(filename)214    def IsCloseTo(self, filename):215      run_group_ts = _Median(216          [ProfileManager._Timestamp(f) for f in self._filenames])217      return abs(ProfileManager._Timestamp(filename) -218                 run_group_ts) < self.RUN_GROUP_THRESHOLD_NS219  def __init__(self, filenames):220    """Initialize a ProfileManager.221    Args:222      filenames ([str]): List of filenames describe the profile set.223    """224    self._filenames = sorted(filenames, key=self._Timestamp)225    self._run_groups = None226  def GetPhases(self):227    """Return the set of phases of all orderfiles.228    Returns:229      set(int)230    """231    return set(self._Phase(f) for f in self._filenames)232  def GetMergedOffsets(self, phase=None):233    """Merges files, as if from a single dump.234    Args:235      phase (int, optional) If present, restrict to this phase.236    Returns:237      [int] Ordered list of reached offsets. Each offset only appears238      once in the output, in the order of the first dump that contains it.239    """240    if phase is None:241      return self._GetOffsetsForGroup(self._filenames)242    return self._GetOffsetsForGroup(f for f in self._filenames243                                    if self._Phase(f) == phase)244  def GetRunGroupOffsets(self, phase=None):245    """Merges files from each run group and returns offset list for each.246    Args:247      phase (int, optional) If present, restrict to this phase.248    Returns:249     [ [int] ] List of offsets lists, each as from GetMergedOffsets.250    """251    return [self._GetOffsetsForGroup(g) for g in self._GetRunGroups(phase)]252  def _GetOffsetsForGroup(self, filenames):253    dumps = [self._ReadOffsets(f) for f in filenames]254    seen_offsets = set()255    result = []256    for dump in dumps:257      for offset in dump:258        if offset not in seen_offsets:259          result.append(offset)260          seen_offsets.add(offset)261    return result262  def _GetRunGroups(self, phase=None):263    if self._run_groups is None:264      self._ComputeRunGroups()265    return [g.Filenames(phase) for g in self._run_groups]266  @classmethod267  def _Timestamp(cls, filename):268      dash_index = filename.rindex('-')269      dot_index = filename.rindex('.')270      return int(filename[dash_index+1:dot_index])271  @classmethod272  def _Phase(cls, filename):273    return int(filename.split('_')[-1])274  def _ReadOffsets(self, filename):275    return [int(x.strip()) for x in open(filename)]276  def _ComputeRunGroups(self):277    self._run_groups = []278    for f in self._filenames:279      for g in self._run_groups:280        if g.IsCloseTo(f):281          g.Add(f)282          break283      else:284        g = self._RunGroup()285        g.Add(f)286        self._run_groups.append(g)287def GetReachedOffsetsFromDumpFiles(dump_filenames, library_filename):288  """Produces a list of symbol offsets reached by the dumps.289  Args:290    dump_filenames (str iterable) A list of dump filenames.291    library_filename (str) The library file which the dumps refer to.292  Returns:293    [int] A list of symbol offsets. This order of symbol offsets produced is294      given by the deduplicated order of offsets found in dump_filenames (see295      also MergeDumps().296  """297  dump = ProfileManager(dump_filenames).GetMergedOffsets()298  if not dump:299    logging.error('Empty dump, cannot continue: %s', '\n'.join(dump_filenames))300    return None301  logging.info('Reached offsets = %d', len(dump))302  processor = SymbolOffsetProcessor(library_filename)303  return processor.GetReachedOffsetsFromDump(dump)304def CreateArgumentParser():305  """Returns an ArgumentParser."""306  parser = argparse.ArgumentParser(description='Outputs reached symbols')307  parser.add_argument('--instrumented-build-dir', type=str,308                      help='Path to the instrumented build', required=True)309  parser.add_argument('--build-dir', type=str, help='Path to the build dir',310                      required=True)311  parser.add_argument('--dumps', type=str, help='A comma-separated list of '312                      'files with instrumentation dumps', required=True)313  parser.add_argument('--output', type=str, help='Output filename',314                      required=True)315  parser.add_argument('--offsets-output', type=str,316                      help='Output filename for the symbol offsets',317                      required=False, default=None)318  parser.add_argument('--library-name', default='libchrome.so',319                      help=('Chrome shared library name (usually libchrome.so '320                            'or libmonochrome.so'))321  return parser322def main():323  logging.basicConfig(level=logging.INFO)324  parser = CreateArgumentParser()325  args = parser.parse_args()326  logging.info('Merging dumps')327  dump_files = args.dumps.split(',')328  profile_manager = ProfileManager(dump_files)329  profile_manager.SortByTimestamp()330  dumps = profile_manager.GetMergedOffsets()331  instrumented_native_lib = os.path.join(args.instrumented_build_dir,332                                         'lib.unstripped', args.library_name)333  regular_native_lib = os.path.join(args.build_dir,334                                    'lib.unstripped', args.library_name)335  instrumented_processor = SymbolOffsetProcessor(instrumented_native_lib)336  reached_offsets = instrumented_processor.GetReachedOffsetsFromDumps(dumps)337  if args.offsets_output:338    with file(args.offsets_output, 'w') as f:339      f.write('\n'.join(map(str, reached_offsets)))340  logging.info('Reached Offsets = %d', len(reached_offsets))341  primary_map = instrumented_processor.OffsetToPrimaryMap()342  reached_primary_symbols = set(343      primary_map[offset] for offset in reached_offsets)344  logging.info('Reached symbol names = %d', len(reached_primary_symbols))345  regular_processor = SymbolOffsetProcessor(regular_native_lib)346  matched_in_regular_build = regular_processor.MatchSymbolNames(347      s.name for s in reached_primary_symbols)348  logging.info('Matched symbols = %d', len(matched_in_regular_build))349  total_size = sum(s.size for s in matched_in_regular_build)350  logging.info('Total reached size = %d', total_size)351  with open(args.output, 'w') as f:352    for s in matched_in_regular_build:353      f.write(s.name + '\n')354if __name__ == '__main__':...Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
