Skip to content

tdfs4ds.call_phases

tdfs4ds.call_phases

History of the framework's own cost per call and phase (0.3.8.0).

FS_CALL_PHASES (optional table, append-only) keeps, for every banded tdfs4ds call, one row per (call, process, phase): statements, database time, CPU, I/O, spool, skew and rows written, copied from DBQL by :func:harvest_call_phases (a third, separate INSERT ... SELECT run by harvest_execution_resources, so a run pays nothing more). Nothing is written by the client.

Reading it

  • FS_V_CALL_PHASES: the facts, plus PHASE_GROUP (work / safety / framework).
  • FS_V_FRAMEWORK_COST_RUN: one row per call and process: the step's framework, safety and work statements and database time, rows written and FIXED_COST_RESIDUAL (the step's framework time minus the process's median): the anomaly signal.
  • FS_V_FRAMEWORK_COST_DAILY: one row per (day, process, phase group), days without a call filled with zeros over the process's active span: a regular series for TD_ARIMA* or anomaly detection.
  • :func:framework_cost reads them; :func:register_framework_monitoring (opt-in) stores the cost as features of its own data domain.

What the figures are, and are not

  • The call band carries no process id: a statement has a process only inside an execution (ingestion). Statements outside it belong to the call; when a call touched exactly one process they are attributed to it, otherwise PROCESS_ID is NULL (call level) and the views show CALL_LEVEL.
  • Rows: DBQL has no row count for CREATE TABLE ... AS (the staging). ROWS_WRITTEN is the feature rows the MERGE / INSERT statements wrote (StmtDMLRowCount): an unchanged re-run writes 0. ROWS_RETURNED is the rows the SELECTs returned.
  • A call's number of steps is its number of executions (CALL_EXECUTIONS, at least 1): a roll_out of 2 processes over 3 dates is 6 steps, of which the call-level statements are shared.
  • DB_ELAPSED_SEC is DBQL's FirstRespTime - StartTime summed over the statements: the database side only; the round trip is the client's (see tdfs4ds.profile).
  • A statement's mechanism (client / procedure / macro) comes from the optional band key TDFS4DS_MECHANISM; without it client.

logger module-attribute

logger = logging.getLogger(__name__)

TABLE module-attribute

TABLE = 'FS_CALL_PHASES'

VIEW module-attribute

VIEW = 'FS_V_CALL_PHASES'

RUN_VIEW module-attribute

RUN_VIEW = 'FS_V_FRAMEWORK_COST_RUN'

DAILY_VIEW module-attribute

DAILY_VIEW = 'FS_V_FRAMEWORK_COST_DAILY'

VIEWS module-attribute

VIEWS = (VIEW, RUN_VIEW, DAILY_VIEW)

CALL_LEVEL module-attribute

CALL_LEVEL = 'CALL_LEVEL'

COLUMNS module-attribute

COLUMNS = ('CALL_ID', 'PROCESS_ID', 'PHASE', 'CALL_KIND', 'MECHANISM', 'PACKAGE_VERSION', 'APP_USER', 'DATA_DOMAIN', 'PROCESS_VIEW', 'RUN_ID', 'VALIDTIME_DATE', 'CALL_START', 'CALL_END', 'CALL_EXECUTIONS', 'N_STATEMENTS', 'N_ERRORS', 'DB_ELAPSED_SEC', 'AMP_CPU_SEC', 'IMPACT_CPU_SEC', 'TOTAL_IO', 'MAX_SPOOL_BYTES', 'CPU_SKEW_PCT', 'IO_SKEW_PCT', 'ROWS_WRITTEN', 'ROWS_RETURNED', 'HARVESTED_AT')

_STATE module-attribute

_STATE: Dict[str, Optional[bool]] = {'tables': None}

_WARNED module-attribute

_WARNED: set = set()

_LEVELS module-attribute

_LEVELS = {'call': VIEW, 'run': RUN_VIEW, 'daily': DAILY_VIEW}

MONITOR_PROCESS_VIEW module-attribute

MONITOR_PROCESS_VIEW = 'FS_MON_FRAMEWORK_BY_PROCESS'

MONITOR_DOMAIN_VIEW module-attribute

MONITOR_DOMAIN_VIEW = 'FS_MON_FRAMEWORK_BY_DOMAIN'

MONITOR_WINDOW_DAYS module-attribute

MONITOR_WINDOW_DAYS = 28

logger_safe

logger_safe(level, message, *args, **kwargs)

Wrapper around the global logger that only emits logs when tdfs4ds.DISPLAY_LOGS is True. level is a string like "info", "error", etc.

sql_literal

sql_literal(value)

Escape value for use inside a single-quoted SQL string literal.

For the DBC probes and catalog predicates that compare a name as data (WHERE DatabaseName = '…'). The caller supplies the surrounding quotes.

enabled

enabled() -> bool

reset_state

reset_state() -> None

_warn_once

_warn_once(key: str, message: str) -> None

_run_sql

_run_sql(sql, params=None)

_frame

_frame(sql)

_table

_table(name) -> str

_view

_view(name) -> str

table_ddl

table_ddl() -> str

_group_case

_group_case(col='PHASE') -> str

facts_view_sql

facts_view_sql() -> str

run_view_sql

run_view_sql() -> str

One row per (call, process): the step's cost by group. steps = executions of the call (>= 1).

daily_view_sql

daily_view_sql() -> str

_view_statements

_view_statements() -> tuple

_create_views

_create_views() -> None

call_phases_creation

call_phases_creation(existing: Optional[Iterable[str]] = None) -> bool

Create FS_CALL_PHASES and its three views when missing. Never raises; a failure is remembered and not retried (the table is optional).

available

available() -> bool

_dml

_dml(kind) -> str

_statement_base_sql

_statement_base_sql(days=None) -> str

The DBQL statements of banded calls: one row each, with the phase, the band values and the measures (the same formulas as profiling.run_profile_sql / followup_resource_usage_sql).

harvest_sql

harvest_sql(days=None, flush_minutes=None) -> str

The INSERT ... SELECT that stores the calls whose DBQL rows are complete and not stored yet.

_bound_days

_bound_days() -> Optional[int]

Days of DBQL to scan: from two days before the last stored call, else everything DBQL holds.

harvest_call_phases

harvest_call_phases(days=None, flush_minutes=None, dry_run=False) -> dict

Copy the finished calls from DBQL into FS_CALL_PHASES (in the database, nothing comes to the client). Never raises: {"ok", "rows", "error", "sql"}.

framework_cost_sql

framework_cost_sql(level='run', process_ids=None, data_domains=None, days=None) -> str

The SELECT behind :func:framework_cost. Pure.

framework_cost

framework_cost(level='run', *, process_ids=None, data_domains=None, days=None, as_pandas=False)

The framework's own cost, read from FS_CALL_PHASES' views.

level: 'call' (call x process x phase), 'run' (call x process: the step's framework, safety and work cost and FIXED_COST_RESIDUAL) or 'daily' (day x process x phase group, zero-filled). Returns a teradataml DataFrame, or a pandas frame with as_pandas=True. Empty until a banded call has been harvested (DBQL flushes every 10 minutes; harvest_execution_resources(force...)).

write_framework_cost_report

write_framework_cost_report(path=None, days=90, data_domains=None, fmt='html', measure_round_trip=False) -> str

Write the framework cost report (the app's Performance > Framework cost tab) to path and return it.

fmt: 'html' (a standalone page, light and dark) or 'csv' (one row per call and process). Reads FS_CALL_PHASES only; never changes anything.

monitoring_sql

monitoring_sql(window_days=MONITOR_WINDOW_DAYS) -> dict

The two process views of the monitoring: {view_name: (sql, entity_id, features)}. Pure.

register_framework_monitoring

register_framework_monitoring(data_domain='FS_MONITORING', run_now=True, window_days=MONITOR_WINDOW_DAYS)

Store the framework's cost as features (opt-in): two process views over FS_V_FRAMEWORK_COST_DAILY registered in their own data domain, so history, lineage and time travel come from the store.

  • FS_MON_FRAMEWORK_BY_PROCESS (entity PROCESS_ID): framework_statements_per_step, framework_sec_per_step, work_sec_per_1k_rows, safety_share over the last window_days.
  • FS_MON_FRAMEWORK_BY_DOMAIN (entity MONITORED_DOMAIN): domain_framework_share, domain_calls.

Writes only in data_domain (the global tdfs4ds.DATA_DOMAIN is restored). Drive it with tdfs4ds.run(process_id) daily, or a domain clock. Returns {view_name: process_id} (None for a registration that was refused: see the log).