-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Ingvar Stepanyan <me@rreverser.com> Co-authored-by: Steve Boytsun <steve@clockwokrlabs.io> Co-authored-by: Ingvar Stepanyan <me@rreverser.com>
- Loading branch information
1 parent
f6bc6dc
commit 14e5098
Showing
11 changed files
with
100 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using System.Text; | ||
using SpacetimeDB.Internal; | ||
|
||
namespace SpacetimeDB; | ||
|
||
public sealed class LogStopwatch : IDisposable | ||
{ | ||
private readonly FFI.ConsoleTimerId StopwatchId; | ||
private bool WasStopped; | ||
|
||
public LogStopwatch(string name) | ||
{ | ||
var name_bytes = Encoding.UTF8.GetBytes(name); | ||
StopwatchId = FFI._console_timer_start(name_bytes, (uint)name_bytes.Length); | ||
} | ||
|
||
void IDisposable.Dispose() | ||
{ | ||
if (!WasStopped) | ||
{ | ||
End(); | ||
} | ||
} | ||
|
||
public void End() | ||
{ | ||
FFI._console_timer_end(StopwatchId); | ||
WasStopped = true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 7 additions & 7 deletions
14
crates/bindings/src/time_span.rs → crates/bindings/src/log_stopwatch.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,23 @@ | ||
pub struct Span { | ||
span_id: u32, | ||
pub struct LogStopwatch { | ||
stopwatch_id: u32, | ||
} | ||
|
||
impl Span { | ||
pub fn start(name: &str) -> Self { | ||
impl LogStopwatch { | ||
pub fn new(name: &str) -> Self { | ||
let name = name.as_bytes(); | ||
let id = unsafe { spacetimedb_bindings_sys::raw::_console_timer_start(name.as_ptr(), name.len()) }; | ||
Self { span_id: id } | ||
Self { stopwatch_id: id } | ||
} | ||
|
||
pub fn end(self) { | ||
// just drop self | ||
} | ||
} | ||
|
||
impl std::ops::Drop for Span { | ||
impl std::ops::Drop for LogStopwatch { | ||
fn drop(&mut self) { | ||
unsafe { | ||
spacetimedb_bindings_sys::raw::_console_timer_end(self.span_id); | ||
spacetimedb_bindings_sys::raw::_console_timer_end(self.stopwatch_id); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14e5098
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Benchmarking failed. Please check the workflow run for details.
14e5098
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Benchmarking failed. Please check the workflow run for details.