github.com/apache/beam/sdks/v2@v2.48.2/python/apache_beam/runners/worker/statesampler_fast.pxd (about)

     1  #
     2  # Licensed to the Apache Software Foundation (ASF) under one or more
     3  # contributor license agreements.  See the NOTICE file distributed with
     4  # this work for additional information regarding copyright ownership.
     5  # The ASF licenses this file to You under the Apache License, Version 2.0
     6  # (the "License"); you may not use this file except in compliance with
     7  # the License.  You may obtain a copy of the License at
     8  #
     9  #    http://www.apache.org/licenses/LICENSE-2.0
    10  #
    11  # Unless required by applicable law or agreed to in writing, software
    12  # distributed under the License is distributed on an "AS IS" BASIS,
    13  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14  # See the License for the specific language governing permissions and
    15  # limitations under the License.
    16  #
    17  
    18  cimport cython
    19  
    20  from apache_beam.metrics.execution cimport MetricsContainer
    21  
    22  from cpython cimport pythread
    23  from libc.stdint cimport int32_t, int64_t
    24  
    25  cdef class StateSampler(object):
    26    """Tracks time spent in states during pipeline execution."""
    27    cdef int _sampling_period_ms
    28    cdef int _sampling_period_ms_start
    29    cdef double _sampling_period_ratio
    30  
    31    cdef list scoped_states_by_index
    32  
    33    cdef public bint started
    34    cdef public bint finished
    35    cdef object sampling_thread
    36  
    37    # This lock guards members that are shared between threads, specificaly
    38    # finished, scoped_states_by_index, and the nsecs field of each state therein.
    39    cdef pythread.PyThread_type_lock lock
    40  
    41    cdef public int64_t state_transition_count
    42    cdef public int64_t time_since_transition
    43  
    44    cdef int32_t current_state_index
    45  
    46    cpdef ScopedState current_state(self)
    47    cdef inline ScopedState current_state_c(self)
    48  
    49    cpdef _scoped_state(
    50        self, counter_name, name_context, output_counter, metrics_container)
    51  
    52  cdef class ScopedState(object):
    53    """Context manager class managing transitions for a given sampler state."""
    54  
    55    cdef readonly StateSampler sampler
    56    cdef readonly int32_t state_index
    57    cdef readonly object counter
    58    cdef readonly object name
    59    cdef readonly object name_context
    60    cdef readonly int64_t _nsecs
    61    cdef int32_t old_state_index
    62    cdef readonly MetricsContainer metrics_container
    63  
    64    cpdef __enter__(self)
    65  
    66    cpdef __exit__(self, unused_exc_type, unused_exc_value, unused_traceback)