tools/mac/power/collapse_profile.py
def shorten_stack(self, stack):
    """Drop some frames that don't offer any valuable information. The part
    above/before the frame is trimmed. This means that the base of the stack
    can be dropped but no frame can "skipped".

    Example (dropping biz):

    foo;bar;biz;boo --> boo
    foo;biz;bar;boo --> bar;boo

    Args:
      stack: An array of strings that represent each frame of a stack trace.

    Returns: The input array with zero or more elements removed.
    """

    message_pump_roots = [
        "base::MessagePumpNSRunLoop::DoRun", "base::MessagePumpDefault::Run",
        "base::MessagePumpKqueue::Run", "base::MessagePumpCFRunLoopBase::Run",
        "base::MessagePumpNSApplication::DoRun", "base::mac::CallWithEHFrame"
    ]

    first_ignored_index = -1
    for i, frame in enumerate(stack):
      if any(
          frame.startswith(message_pump_root)
          for message_pump_root in message_pump_roots):
        # If any of the markers is present in the function it means everything
        # under the frame should be dropped from the stack.
        first_ignored_index = max(
            i - 1,
            0)  # Cutoff point is included but can't be smaller than zero.
        break

    if first_ignored_index != -1:
      return stack[first_ignored_index + 1:]
    else:
      return stack
Drop some frames that don't offer any valuable information. The part
    above/before the frame is trimmed. This means that the base of the stack
    can be dropped but no frame can "skipped".

    Example (dropping biz):

    foo;bar;biz;boo --> boo
    foo;biz;bar;boo --> bar;boo

    Args:
      stack: An array of strings that represent each frame of a stack trace.

    Returns: The input array with zero or more elements removed.
    
Drop some frames that don't offer any valuable information. The part
above/before the frame is trimmed. This means that the base of the stack
can be dropped but no frame can "skipped".

Example (dropping biz).


Drop some frames that don ' t offer any valuable information . The part above / before the frame is trimmed . This means that the base of the stack can be dropped but no frame can " skipped " . Example ( dropping biz ) .
def shorten_stack(self, stack):
    message_pump_roots = [
        "base::MessagePumpNSRunLoop::DoRun", "base::MessagePumpDefault::Run",
        "base::MessagePumpKqueue::Run", "base::MessagePumpCFRunLoopBase::Run",
        "base::MessagePumpNSApplication::DoRun", "base::mac::CallWithEHFrame"
    ]
    first_ignored_index = -1
    for i, frame in enumerate(stack):
      if any(
          frame.startswith(message_pump_root)
          for message_pump_root in message_pump_roots):
        first_ignored_index = max(
            i - 1,
            0)  
        break
    if first_ignored_index != -1:
      return stack[first_ignored_index + 1:]
    else:
      return stack
def shorten_stack ( self , stack ) : message_pump_roots = [ "base::MessagePumpNSRunLoop::DoRun" , "base::MessagePumpDefault::Run" , "base::MessagePumpKqueue::Run" , "base::MessagePumpCFRunLoopBase::Run" , "base::MessagePumpNSApplication::DoRun" , "base::mac::CallWithEHFrame" ] first_ignored_index = - 1 for i , frame in enumerate ( stack ) : if any ( frame . startswith ( message_pump_root ) for message_pump_root in message_pump_roots ) : first_ignored_index = max ( i - 1 , 0 ) break if first_ignored_index != - 1 : return stack [ first_ignored_index + 1 : ] else : return stack
Drop some frames that don't offer any valuable information.
Drop some frames that don ' t offer any valuable information .
"""Drop some frames that don't offer any valuable information. The part
    above/before the frame is trimmed. This means that the base of the stack
    can be dropped but no frame can "skipped".

    Example (dropping biz):

    foo;bar;biz;boo --> boo
    foo;biz;bar;boo --> bar;boo

    Args:
      stack: An array of strings that represent each frame of a stack trace.

    Returns: The input array with zero or more elements removed.
    """ # If any of the markers is present in the function it means everything # under the frame should be dropped from the stack. # Cutoff point is included but can't be smaller than zero.
self
stack
An array of strings that represent each frame of a stack trace.
An array of strings that represent each frame of a stack trace .