Skip to contentSkip to conversation

libtraceeval: Add traceeval_stat_max/min_timestamp() API

PATCH In review Steven Rostedt 2 participants 4 messages Oct 5, 2023 – Oct 17, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libtraceeval: Add traceeval_stat_max/min_timestamp() API

From: "Steven Rostedt (Google)" <[email protected]>

If a value field is flagged as a TIMESTAMP, and another field is flagged as a STAT, have the statistics for the STAT field automatically keep track of when the max and min happened (what the TIMESTAMP field was at those instances).

---
 include/traceeval.h |   4 ++
 src/eval-local.h    |   3 ++
 src/histograms.c    | 105 +++++++++++++++++++++++++++++++++++++-------
 3 files changed, 97 insertions(+), 15 deletions(-)
include/traceeval.h +4 -0
index a70a5b09057b..bbf8f6ac7dd1 100644
@@ -242,6 +242,10 @@ unsigned long long traceeval_stat_max(struct traceeval_stat *stat);
 unsigned long long traceeval_stat_min(struct traceeval_stat *stat);
 unsigned long long traceeval_stat_total(struct traceeval_stat *stat);
 unsigned long long traceeval_stat_count(struct traceeval_stat *stat);
+unsigned long long traceeval_stat_max_timestamp(struct traceeval_stat *stat,
+						unsigned long long *ts);
+unsigned long long traceeval_stat_min_timestamp(struct traceeval_stat *stat,
+						unsigned long long *ts);
 
 struct traceeval_iterator *traceeval_iterator_get(struct traceeval *teval);
 void traceeval_iterator_put(struct traceeval_iterator *iter);
src/eval-local.h +3 -0
index 01b1b838e8bf..fabb1a06e7df 100644
@@ -47,7 +47,9 @@ struct hash_table {
 
 struct traceeval_stat {
 	unsigned long long	max;
+	unsigned long long	max_ts;
 	unsigned long long	min;
+	unsigned long long	min_ts;
 	unsigned long long	total;
 	unsigned long long	std;
 	size_t			count;
@@ -72,6 +74,7 @@ struct traceeval {
 	size_t				nr_elements;
 	size_t				sizeof_type;
 	size_t				sizeof_data;
+	ssize_t				timestamp_idx;
 };
 
 struct traceeval_iterator {
src/histograms.c +90 -15

226 lines not on this page · raw message

Signature · 1 line
2.40.1
#1 lore raw
Quoted 6 lines · Steven Rostedt

From: "Steven Rostedt (Google)" <[email protected]>

If a value field is flagged as a TIMESTAMP, and another field is flagged as a STAT, have the statistics for the STAT field automatically keep track of when the max and min happened (what the TIMESTAMP field was at those instances).

I'm confused as to why we have TRACEEVAL_FL_TIMESTAMP and a separate data entry with that flag, instead of only storing the timestamp in the entry metadata, as we do with the other STATs?

From the description above where we have one TIMESTAMP and one STAT, I would expect to see structures defined like this
(from [PATCH v2] libtraceeval: Add wake-lat sample code):

+struct traceeval_type sched_vals[] = {
+ {

+               .name           = "timestamp",
+               .flags          = TRACEEVAL_FL_TIMESTAMP,
+               .type           = TRACEEVAL_TYPE_NUMBER_64,
+       },
+       {
+               .name           = "delta",
+               .flags          = TRACEEVAL_FL_STAT,
+               .type           = TRACEEVAL_TYPE_NUMBER_64,

+ }

where the timestamp is sync'd with the STAT min and max, right?

But we also have this:

+struct traceeval_type wakeup_vals[] = {
+ {

+               .name           = "timestamp",
+               .flags          = TRACEEVAL_FL_TIMESTAMP,
+               .type           = TRACEEVAL_TYPE_NUMBER_64,

+ }
+};

in a structure that doesn't have a corresponding STAT field? This is also confusing to me because we need to keep 2 values (min and max TS), but this only holds one?

The timestamp is already stored independently in the stat metadata in struct traceeval_stat:

src/eval-local.h struct hash_table { · line 55

Quoted 8 lines

struct traceeval_stat {

src/eval-local.h +2 -0
 	unsigned long long	max;
+	unsigned long long	max_ts;
 	unsigned long long	min;
+	unsigned long long	min_ts;
 	unsigned long long	total;
 	unsigned long long	std;
 	size_t			count;

which I think is enough?

It seems like instead we really want our two flags to be:

TRACEEVAL_FL_STAT
and
TRACEEVAL_FL_STAT_TS

where the first just keeps the normal stats (min, max, average, std. dev, etc) and the second does all that plus timestamps for min and max?

This would also allow you to keep min and max stats independently for multiple entries in a single structure, i.e.:

struct traceeval_type task_vals[] = {
{
.name = "wake_delay",
.flags = TRACEEVAL_FL_STAT_TS,
.type = TRACEEVAL_TYPE_NUMBER_64,
},
{
.name = "runtime",
.flags = TRACEEVAL_FL_STAT_TS,
.type = TRACEEVAL_TYPE_NUMBER_64,
}
};

which I don't think is possible under the current scheme?

What am I missing?

#2 lore raw
Quoted 11 lines · On Wed, 11 Oct 2023 16:21:00 -0600 Ross Zwisler <[email protected]> wrote:
Quoted 6 lines · Steven Rostedt

From: "Steven Rostedt (Google)" <[email protected]>

If a value field is flagged as a TIMESTAMP, and another field is flagged as a STAT, have the statistics for the STAT field automatically keep track of when the max and min happened (what the TIMESTAMP field was at those instances).

I'm confused as to why we have TRACEEVAL_FL_TIMESTAMP and a separate data entry with that flag, instead of only storing the timestamp in the entry metadata, as we do with the other STATs?

Actually, I may remove this part entirely, as it's pretty much superseded by the TRACEEVAL_TYPE_DELTA, which I moved to, and haven't needed the separate val marked for the timestamp.

Quoted 17 lines
Quoted 2 lines

From the description above where we have one TIMESTAMP and one STAT, I would

expect to see structures defined like this
(from [PATCH v2] libtraceeval: Add wake-lat sample code):

(quoted diff) +11 -0
+struct traceeval_type sched_vals[] = {
+       {
+               .name           = "timestamp",
+               .flags          = TRACEEVAL_FL_TIMESTAMP,
+               .type           = TRACEEVAL_TYPE_NUMBER_64,
+       },
+       {
+               .name           = "delta",
+               .flags          = TRACEEVAL_FL_STAT,
+               .type           = TRACEEVAL_TYPE_NUMBER_64,
+       }
Quoted 1 line

where the timestamp is sync'd with the STAT min and max, right?

The new type is done like:

	{
		.name		= "delta",
		.type		= TRACEEVAL_TYPE_DELTA,
	}

Which will automatically be marked as STAT flag, and is set with:

	TRACEEVAL_SET_DELTA(vals, delta, timestamp);

Is that what you are thinking about?

-- Steve

Quoted 57 lines

But we also have this:

(quoted diff) +7 -0
+struct traceeval_type wakeup_vals[] = {
+       {
+               .name           = "timestamp",
+               .flags          = TRACEEVAL_FL_TIMESTAMP,
+               .type           = TRACEEVAL_TYPE_NUMBER_64,
+       }
+};

in a structure that doesn't have a corresponding STAT field? This is also confusing to me because we need to keep 2 values (min and max TS), but this only holds one?

The timestamp is already stored independently in the stat metadata in struct traceeval_stat:

src/eval-local.h struct hash_table { · line 55

Quoted 8 lines

struct traceeval_stat {

src/eval-local.h +2 -0
 	unsigned long long	max;
+	unsigned long long	max_ts;
 	unsigned long long	min;
+	unsigned long long	min_ts;
 	unsigned long long	total;
 	unsigned long long	std;
 	size_t			count;  

which I think is enough?

It seems like instead we really want our two flags to be:

TRACEEVAL_FL_STAT
and
TRACEEVAL_FL_STAT_TS

where the first just keeps the normal stats (min, max, average, std. dev, etc) and the second does all that plus timestamps for min and max?

This would also allow you to keep min and max stats independently for multiple entries in a single structure, i.e.:

struct traceeval_type task_vals[] = {
{
.name = "wake_delay",
.flags = TRACEEVAL_FL_STAT_TS,
.type = TRACEEVAL_TYPE_NUMBER_64,
},
{
.name = "runtime",
.flags = TRACEEVAL_FL_STAT_TS,
.type = TRACEEVAL_TYPE_NUMBER_64,
}
};

which I don't think is possible under the current scheme?

What am I missing?

#3 lore raw
Quoted 45 lines · Steven Rostedt
Quoted 11 lines · On Wed, 11 Oct 2023 16:21:00 -0600 Ross Zwisler <[email protected]> wrote:
Quoted 6 lines · Steven Rostedt

From: "Steven Rostedt (Google)" <[email protected]>

If a value field is flagged as a TIMESTAMP, and another field is flagged as a STAT, have the statistics for the STAT field automatically keep track of when the max and min happened (what the TIMESTAMP field was at those instances).

I'm confused as to why we have TRACEEVAL_FL_TIMESTAMP and a separate data entry with that flag, instead of only storing the timestamp in the entry metadata, as we do with the other STATs?

Actually, I may remove this part entirely, as it's pretty much superseded by the TRACEEVAL_TYPE_DELTA, which I moved to, and haven't needed the separate val marked for the timestamp.

Quoted 17 lines
Quoted 2 lines

From the description above where we have one TIMESTAMP and one STAT, I would

expect to see structures defined like this
(from [PATCH v2] libtraceeval: Add wake-lat sample code):

(quoted diff) +11 -0
+struct traceeval_type sched_vals[] = {
+       {
+               .name           = "timestamp",
+               .flags          = TRACEEVAL_FL_TIMESTAMP,
+               .type           = TRACEEVAL_TYPE_NUMBER_64,
+       },
+       {
+               .name           = "delta",
+               .flags          = TRACEEVAL_FL_STAT,
+               .type           = TRACEEVAL_TYPE_NUMBER_64,
+       }
Quoted 1 line

where the timestamp is sync'd with the STAT min and max, right?

The new type is done like:

	{
		.name		= "delta",
		.type		= TRACEEVAL_TYPE_DELTA,
	}
Quoted 5 lines

Which will automatically be marked as STAT flag, and is set with:

	TRACEEVAL_SET_DELTA(vals, delta, timestamp);

Is that what you are thinking about?

Yep, I think so. I'll take a harder look at TRACEEVAL_TYPE_DELTA.