Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Renaming And Refactoring #60

Merged
merged 4 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions expected/utility.out
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ CREATE EXTENSION pg_tracing;
SET pg_tracing.sample_rate = 0.0;
-- View displaying spans with their nested level
CREATE VIEW peek_spans_with_level AS
WITH RECURSIVE list_trace_spans(trace_id, parent_id, span_id, query_id, span_type, span_operation, span_start, span_end, sql_error_code, userid, dbid, pid, subxact_count, plan_startup_cost, plan_total_cost, plan_rows, plan_width, rows, nloops, shared_blks_hit, shared_blks_read, shared_blks_dirtied, shared_blks_written, local_blks_hit, local_blks_read, local_blks_dirtied, local_blks_written, blk_read_time, blk_write_time, temp_blks_read, temp_blks_written, temp_blk_read_time, temp_blk_write_time, wal_records, wal_fpi, wal_bytes, jit_functions, jit_generation_time, jit_inlining_time, jit_optimization_time, jit_emission_time, startup, parameters, deparse_info, lvl) AS (
SELECT p.*, 1
WITH RECURSIVE list_trace_spans AS (
SELECT p.*, 1 as lvl
FROM pg_tracing_peek_spans p where not parent_id=ANY(SELECT span_id from pg_tracing_peek_spans)
UNION ALL
SELECT s.*, lvl + 1
Expand Down
4 changes: 2 additions & 2 deletions sql/utility.sql
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ SET pg_tracing.sample_rate = 0.0;

-- View displaying spans with their nested level
CREATE VIEW peek_spans_with_level AS
WITH RECURSIVE list_trace_spans(trace_id, parent_id, span_id, query_id, span_type, span_operation, span_start, span_end, sql_error_code, userid, dbid, pid, subxact_count, plan_startup_cost, plan_total_cost, plan_rows, plan_width, rows, nloops, shared_blks_hit, shared_blks_read, shared_blks_dirtied, shared_blks_written, local_blks_hit, local_blks_read, local_blks_dirtied, local_blks_written, blk_read_time, blk_write_time, temp_blks_read, temp_blks_written, temp_blk_read_time, temp_blk_write_time, wal_records, wal_fpi, wal_bytes, jit_functions, jit_generation_time, jit_inlining_time, jit_optimization_time, jit_emission_time, startup, parameters, deparse_info, lvl) AS (
SELECT p.*, 1
WITH RECURSIVE list_trace_spans AS (
SELECT p.*, 1 as lvl
FROM pg_tracing_peek_spans p where not parent_id=ANY(SELECT span_id from pg_tracing_peek_spans)
UNION ALL
SELECT s.*, lvl + 1
Expand Down
12 changes: 6 additions & 6 deletions src/pg_tracing.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ typedef struct PerLevelInfos
* level. Executor run is used as
* parent for spans generated from
* planstate */
TimestampTz executor_start;
TimestampTz executor_end;
TimestampTz executor_run_start;
TimestampTz executor_run_end;
} PerLevelInfos;

/* GUC variables */
Expand Down Expand Up @@ -1067,7 +1067,7 @@ process_query_desc(const Traceparent * traceparent, const QueryDesc *queryDesc,
if (pg_tracing_planstate_spans)
{
uint64 parent_id = per_level_infos[nested_level].executor_run_span_id;
TimestampTz parent_start = per_level_infos[nested_level].executor_start;
TimestampTz parent_start = per_level_infos[nested_level].executor_run_start;
uint64 query_id = queryDesc->plannedstmt->queryId;

process_planstate(traceparent, queryDesc, sql_error_code,
Expand Down Expand Up @@ -1881,7 +1881,7 @@ pg_tracing_ExecutorRun(QueryDesc *queryDesc, ScanDirection direction, uint64 cou
executor_run_span = push_child_active_span(pg_tracing_mem_ctx, &span_context, SPAN_EXECUTOR_RUN);

per_level_infos[nested_level].executor_run_span_id = executor_run_span->span_id;
per_level_infos[nested_level].executor_start = executor_run_span->start;
per_level_infos[nested_level].executor_run_start = executor_run_span->start;

/*
* If this query starts parallel worker, push the trace context for the
Expand Down Expand Up @@ -1956,7 +1956,7 @@ pg_tracing_ExecutorRun(QueryDesc *queryDesc, ScanDirection direction, uint64 cou
nested_level--;
/* End ExecutorRun span and store it */
pop_and_store_active_span(span_end_time);
per_level_infos[nested_level].executor_end = span_end_time;
per_level_infos[nested_level].executor_run_end = span_end_time;
}

/*
Expand Down Expand Up @@ -2087,7 +2087,7 @@ pg_tracing_ExecutorEnd(QueryDesc *queryDesc)
* We're at the end of the Executor for this level, generate spans from
* the planstate if needed
*/
parent_end = per_level_infos[nested_level].executor_end;
parent_end = per_level_infos[nested_level].executor_run_end;
process_query_desc(traceparent, queryDesc, 0, pg_tracing_deparse_plan, parent_end);

/* No need to increment nested level here */
Expand Down
3 changes: 0 additions & 3 deletions src/pg_tracing.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,6 @@ typedef struct Span
SpanType type; /* Type of the span. Used to generate the
* span's name */

bool parallel_aware;
bool async_capable;

int8 nested_level; /* Nested level of this span this span.
* Internal usage only */
int8 parent_planstate_index; /* Index to the parent planstate of
Expand Down
13 changes: 5 additions & 8 deletions src/pg_tracing_planstate.c
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ drop_traced_planstates(void)
* It will track the time of the first node call needed to place the planstate span.
*/
static TupleTableSlot *
ExecProcNodeFirstPgTracing(PlanState *node)
ExecProcNodeFirstPgTracing(PlanState *planstate)
{
uint64 span_id;

Expand All @@ -201,7 +201,7 @@ ExecProcNodeFirstPgTracing(PlanState *node)
max_planstart * sizeof(TracedPlanstate));
}

switch (nodeTag(node))
switch (nodeTag(planstate))
{
case T_GatherState:
case T_GatherMergeState:
Expand All @@ -218,16 +218,16 @@ ExecProcNodeFirstPgTracing(PlanState *node)
}

/* Register planstate start */
traced_planstates[index_planstart].planstate = node;
traced_planstates[index_planstart].planstate = planstate;
traced_planstates[index_planstart].node_start = GetCurrentTimestamp();
traced_planstates[index_planstart].span_id = span_id;
traced_planstates[index_planstart].nested_level = nested_level;
index_planstart++;

exit:
/* Restore previous exec proc */
node->ExecProcNode = previous_ExecProcNode;
return node->ExecProcNode(node);
planstate->ExecProcNode = previous_ExecProcNode;
return planstate->ExecProcNode(planstate);
}

/*
Expand Down Expand Up @@ -602,9 +602,6 @@ create_span_node(PlanState *planstate, const planstateTraceContext * planstateTr
const char *operation_name;
int len_operation_name;

span.parallel_aware = plan->parallel_aware;
span.async_capable = plan->async_capable;

operation_name = plan_to_rel_name(planstateTraceContext, planstate);
len_operation_name = strlen(operation_name);
if (len_operation_name > 0)
Expand Down
2 changes: 0 additions & 2 deletions src/pg_tracing_span.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ begin_span(TraceId trace_id, Span * span, SpanType type,
else
span->span_id = pg_prng_uint64(&pg_global_prng_state);

span->parallel_aware = false;
span->async_capable = false;
span->worker_id = -1;
span->operation_name_offset = -1;
span->num_parameters = 0;
Expand Down