Skip to main content
Version: 0.0.98

ts_shape.events.profiling.handshakes

Mapping-free handshake profiling: who makes the machine wait?

:class:HandshakeProfileEvents finds request / acknowledge pairs between the boolean signals of one PLC without being told which signal talks to which: an edge A that is (almost) always answered by an edge B of another signal before A happens again, and B (almost) never comes without a preceding A -- robot_ready↑ → press_open↑, req_conveyor↑ → ack_conveyor↑. Per pair:

  • the waiting time of every occurrence and its register (median, P10, P90, potential = median - P10);
  • pair_kind: four_phase when the full request/acknowledge protocol is seen (A↑ → B↑ → A↓ → B↓), else two_phase;
  • waits_on: partner when the answer time varies (someone else decides when to answer), fixed when it is a constant delay (a timer or a fixed sequence in the same program);
  • with cycles: the share of the cycle the wait takes and how much of the cycle time variance it explains.

An answer logged at the same timestamp as its request is not counted: on polled data a handshake faster than the poll cannot be told from two signals written in the same scan, and its wait cannot be measured.

Classes
NameDescription
HandshakeProfileEventsRequest / acknowledge pairs and the time spent waiting on them.

HandshakeProfileEvents​

classsource
HandshakeProfileEvents(
dataframe: pd.DataFrame,
*,
cycle_profile: CycleProfileEvents | None = None,
signal_uuids: list[str] | None = None,
min_follow_ratio: float = MIN_FOLLOW_RATIO,
min_occurrences: int = 30,
time_column: str = "systime",
uuid_column: str = "uuid",
event_uuid: str = "prod:handshake_profile",
**cycle_options: Any
) -> None

Bases: _UnitProfiler

Request / acknowledge pairs and the time spent waiting on them.

Example
>>> import ts_shape
>>> frame, truth = ts_shape.make_plc_cycles(
... n_cycles=300, seed=1, handshake_partner=True)
>>> pairs = ts_shape.HandshakeProfileEvents(frame).handshake_pairs()
>>> "plc:req_conveyor↑ → plc:ack_conveyor↑" in set(pairs["pair"])
True
Functions
NameDescription
handshake_pairsThe request / answer pairs found, with their evidence.
handshake_recordsOne interval per answered request.
handshake_registerWhat each handshake wait costs, linked to the cycle.
evaluation_windowWhether each pair can be trusted, and why not.
summaryHeadline numbers (JSON-able).
Parameters
NameTypeDescriptionDefault
dataframeDataFrameLong-format signals of one PLC.required
cycle_profileCycleProfileEvents | NoneA computed cycle profile of the same signals to reuse; None (default) builds one.None
signal_uuidslist[str] | NoneSignals to use (default: all).None
min_follow_ratiofloatA request must be answered, and an answer preceded by a request, at least this often.MIN_FOLLOW_RATIO
min_occurrencesintEdges seen fewer times are not candidates; a pair with fewer occurrences is not evaluable.30
time_columnstrTimestamp column.'systime'
uuid_columnstrSignal column.'uuid'
event_uuidstruuid of the handshake records.'prod:handshake_profile'
**cycle_optionsAnyOptions of the cycle profile built when cycle_profile is None.{}

handshake_pairs​

methodsource
handshake_pairs() -> pd.DataFrame

The request / answer pairs found, with their evidence.

Returns
TypeDescription
DataFrameOne row per pair: pair ("<request> → <answer>"),
DataFramerequest, answer, request_uuid, answer_uuid,
DataFramepair_kind (four_phase / two_phase),
DataFrameoccurrence_count, follow_ratio, precede_ratio,
DataFramemedian_delay_seconds and waits_on (partner for a
DataFramevarying answer time, fixed for a constant delay).

handshake_records​

methodsource
handshake_records() -> pd.DataFrame

One interval per answered request.

Returns
NameTypeDescription
IntervalsDataFramestart (request), end (answer),
DataFrameduration_seconds (the wait), uuid, source_uuid (the
DataFrameanswering signal), pair.

handshake_register​

methodsource
handshake_register() -> pd.DataFrame

What each handshake wait costs, linked to the cycle.

Returns
TypeDescription
DataFramefunc:~ts_shape.events.profiling._base.potential_register
DataFrameof the waits per pair plus pair_kind, waits_on,
DataFramecycle_share_ratio (median wait / median cycle),
DataFramecycle_spearman_factor (rank correlation of the wait with the
DataFrameduration of its cycle) and variance_contribution_factor
DataFrame(cov(wait, cycle) / var(cycle) over the normal cycles).

evaluation_window​

methodsource
evaluation_window() -> pd.DataFrame

Whether each pair can be trusted, and why not.

Returns
TypeDescription
DataFrameOne row per pair (scope = the pair; one all row when none
DataFrameis found): unit_count (answered requests), evaluable,
DataFramereason (below_resolution when the median wait is shorter
DataFramethan twice the time resolution) and time_resolution_seconds.

summary​

methodsource
summary() -> dict[str, Any]

Headline numbers (JSON-able).

Returns
TypeDescription
dict[str, Any]evaluable (any pair evaluable), reason, pair_count,
dict[str, Any]partner_pair_count and top_wait_pair (the partner pair
dict[str, Any]with the largest total potential, four-phase pairs first).