зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1733335 - Add {add,subtract}_microseconds and Clone implementations to ProfilerTime r=emilio
Clone will make the ProfilerTime easier to use. And {add,subtract}_microseconds implementations are helpful when you need to subtract/add some duration before adding a marker. There is a similar code in the Webrender marker code, and this will allow them to use the new API instead of some custom code. Differential Revision: https://phabricator.services.mozilla.com/D127111
This commit is contained in:
Родитель
b92c09149c
Коммит
142d00a761
|
@ -38,10 +38,29 @@ void gecko_profiler_construct_timestamp_now(mozilla::TimeStamp* aTimeStamp) {
|
|||
new (aTimeStamp) mozilla::TimeStamp(mozilla::TimeStamp::Now());
|
||||
}
|
||||
|
||||
void gecko_profiler_clone_timestamp(const mozilla::TimeStamp* aSrcTimeStamp,
|
||||
mozilla::TimeStamp* aDestTimeStamp) {
|
||||
new (aDestTimeStamp) mozilla::TimeStamp(*aSrcTimeStamp);
|
||||
}
|
||||
|
||||
void gecko_profiler_destruct_timestamp(mozilla::TimeStamp* aTimeStamp) {
|
||||
aTimeStamp->~TimeStamp();
|
||||
}
|
||||
|
||||
void gecko_profiler_add_timestamp(const mozilla::TimeStamp* aTimeStamp,
|
||||
mozilla::TimeStamp* aDestTimeStamp,
|
||||
double aMicroseconds) {
|
||||
new (aDestTimeStamp) mozilla::TimeStamp(
|
||||
*aTimeStamp + mozilla::TimeDuration::FromMicroseconds(aMicroseconds));
|
||||
}
|
||||
|
||||
void gecko_profiler_subtract_timestamp(const mozilla::TimeStamp* aTimeStamp,
|
||||
mozilla::TimeStamp* aDestTimeStamp,
|
||||
double aMicroseconds) {
|
||||
new (aDestTimeStamp) mozilla::TimeStamp(
|
||||
*aTimeStamp - mozilla::TimeDuration::FromMicroseconds(aMicroseconds));
|
||||
}
|
||||
|
||||
void gecko_profiler_construct_marker_timing_instant_at(
|
||||
mozilla::MarkerTiming* aMarkerTiming, const mozilla::TimeStamp* aTime) {
|
||||
#ifdef MOZ_GECKO_PROFILER
|
||||
|
|
|
@ -43,10 +43,20 @@ void gecko_profiler_construct_label(mozilla::AutoProfilerLabel* aAutoLabel,
|
|||
JS::ProfilingCategoryPair aCategoryPair);
|
||||
void gecko_profiler_destruct_label(mozilla::AutoProfilerLabel* aAutoLabel);
|
||||
|
||||
// Construct and destruct the timestamp for profiler time.
|
||||
// Construct, clone and destruct the timestamp for profiler time.
|
||||
void gecko_profiler_construct_timestamp_now(mozilla::TimeStamp* aTimeStamp);
|
||||
void gecko_profiler_clone_timestamp(const mozilla::TimeStamp* aSrcTimeStamp,
|
||||
mozilla::TimeStamp* aDestTimeStamp);
|
||||
void gecko_profiler_destruct_timestamp(mozilla::TimeStamp* aTimeStamp);
|
||||
|
||||
// Addition and subtraction for timestamp.
|
||||
void gecko_profiler_add_timestamp(const mozilla::TimeStamp* aTimeStamp,
|
||||
mozilla::TimeStamp* aDestTimeStamp,
|
||||
double aMicroseconds);
|
||||
void gecko_profiler_subtract_timestamp(const mozilla::TimeStamp* aTimeStamp,
|
||||
mozilla::TimeStamp* aDestTimeStamp,
|
||||
double aMicroseconds);
|
||||
|
||||
// Various MarkerTiming constructors and a destructor.
|
||||
void gecko_profiler_construct_marker_timing_instant_at(
|
||||
mozilla::MarkerTiming* aMarkerTiming, const mozilla::TimeStamp* aTime);
|
||||
|
|
|
@ -34,6 +34,32 @@ impl ProfilerTime {
|
|||
ProfilerTime(marker_timing.assume_init())
|
||||
}
|
||||
}
|
||||
|
||||
pub fn add_microseconds(self, microseconds: f64) -> Self {
|
||||
let mut dest = MaybeUninit::<mozilla::TimeStamp>::uninit();
|
||||
unsafe {
|
||||
bindings::gecko_profiler_add_timestamp(&self.0, dest.as_mut_ptr(), microseconds);
|
||||
ProfilerTime(dest.assume_init())
|
||||
}
|
||||
}
|
||||
|
||||
pub fn subtract_microseconds(self, microseconds: f64) -> Self {
|
||||
let mut dest = MaybeUninit::<mozilla::TimeStamp>::uninit();
|
||||
unsafe {
|
||||
bindings::gecko_profiler_subtract_timestamp(&self.0, dest.as_mut_ptr(), microseconds);
|
||||
ProfilerTime(dest.assume_init())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Clone for ProfilerTime {
|
||||
fn clone(&self) -> Self {
|
||||
let mut dest = MaybeUninit::<mozilla::TimeStamp>::uninit();
|
||||
unsafe {
|
||||
bindings::gecko_profiler_clone_timestamp(&self.0, dest.as_mut_ptr());
|
||||
ProfilerTime(dest.assume_init())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for ProfilerTime {
|
||||
|
|
Загрузка…
Ссылка в новой задаче