Clock resolution

67 views
Skip to first unread message

Mario Demontis

unread,
Feb 23, 2024, 2:00:38 PM2/23/24
to Perfetto Development - www.perfetto.dev
Hi!
I'm attempting to use perfetto on an embedded system and the clock I'm using to generate timestamps is 216MHz. It would be nice if I could emit timestamps as they are and not have to convert them to a 1GHz scale: it costs me one multiplication and one division, which could be more conveniently done on the analyzer side.
I see there is a unit_multiplier_ns field in the Clock proto message, but that's not enough, as I would have to set it at 200, and the error is too big.
Is it possible to add the possibility to specify a clock frequency field?

Thanks,
Mario

Lalit Maganti

unread,
Feb 23, 2024, 2:10:17 PM2/23/24
to Mario Demontis, Perfetto Development - www.perfetto.dev
Perfetto has support for clock resolution offline and this is described in our doc at https://perfetto.dev/docs/concepts/clock-sync

Unfortunately clocks are assumed to tick at the same rate, as you've noted there is no way to specify the frequency of a clock. This is the first time someone has come up with this request. 

Design proposals and pull requests for fixing this are welcome but likely will not be something we will get to ourselves. 

--
You received this message because you are subscribed to the Google Groups "Perfetto Development - www.perfetto.dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to perfetto-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/perfetto-dev/d332dcf4-b34f-4382-b95b-5b4aefb86803n%40googlegroups.com.

Lalit Maganti

unread,
Feb 23, 2024, 2:46:53 PM2/23/24
to Mario Demontis, Perfetto Development - www.perfetto.dev
Actually thinking more, `unit_multiplier_ns` coild be adapted to become frequency.

Sending a patch to allow specifying any value there would probably be the nicest way to implement this feature. 

Mario Demontis

unread,
Feb 23, 2024, 3:28:00 PM2/23/24
to Perfetto Development - www.perfetto.dev
Right now unit_multiplier_ns is a uint64. Do you mean to change it to a double so that we can multiply with fractional units?
Or add another field representing the frequency?

Lalit Maganti

unread,
Feb 23, 2024, 3:53:53 PM2/23/24
to Mario Demontis, Perfetto Development - www.perfetto.dev
Hmmm so just to clarify, if unit_multiplier_ns was a double, you'd want 1000000/216000 = 4.62... to be the value to set right?

We cannot change the field but we could potentially add a new field with the same semantics but just a double instead. We'd also need to think carefully about how to deal with rounding in trace processor. 

Mario Demontis

unread,
Feb 23, 2024, 4:10:15 PM2/23/24
to Perfetto Development - www.perfetto.dev
We could add a divider field. In my case I'd set  unit_multiplier_ns to 1000 and divider to 216.
The benefit is that we keep the semantic closer to the original one.
Moreover there should be fewer numeric issues, I think. Except for overflow, but that's already present since we're allowed to multiply...

Lalit Maganti

unread,
Feb 26, 2024, 8:48:11 AM2/26/24
to Mario Demontis, Perfetto Development - www.perfetto.dev
Your suggestion makes sense to me. Happy to accept contributions for adding support for this (guidance for this is available at https://perfetto.dev/docs/contributing/getting-started)

If we need to implement, might require a fixit week for us to get to this. I'd file a GitHub bug for tracking this in that case.

Mario Demontis

unread,
Mar 1, 2024, 4:42:50 AM3/1/24
to Perfetto Development - www.perfetto.dev
I'll try to prepare the modification (seems pretty straightforward)
Thanks
Mario

Reply all
Reply to author
Forward
0 new messages