Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
LARN
X-Lap
Commits
f8cd9601
Commit
f8cd9601
authored
Feb 08, 2021
by
Sven Liefgen
Browse files
Cleanup
parent
f9294f35
Changes
2
Hide whitespace changes
Inline
Side-by-side
build.rs
View file @
f8cd9601
...
...
@@ -32,14 +32,15 @@ fn main() {
// Create constants for kinds
let
mut
kind_
consts
=
String
::
new
(
);
for
(
i
,
kind
)
in
packet_types
.as_hash
()
.unwrap
()
.keys
()
.enumerate
()
{
kind_
consts
.push_str
(
"pub
const TS_
"
);
kind
_consts
.push_str
(
kind
.as_str
()
.unwrap
()
.to_uppercase
()
.as_str
());
kind_
consts
.push_str
(
"
: usize =
"
);
kind_
consts
.push_str
(
i
.to_string
()
.as_str
());
kind_
consts
.push_str
(
"
;
\n
"
);
let
mut
kind_
enum
=
String
::
from
(
"#[derive(EnumIter, Copy, Clone)]
\n
"
);
kind_enum
.push_str
(
"#[allow(non_camel_case_types)]
\n
"
);
kind_
enum
.push_str
(
"pub
enum Kind {
\n
"
);
for
kind
in
packet_types
.as_hash
()
.unwrap
()
.keys
()
{
kind_
enum
.push_str
(
"
TS_
"
);
kind_
enum
.push_str
(
kind
.as_str
()
.unwrap
()
.to_uppercase
()
.as_str
());
kind_
enum
.push_str
(
"
,
\n
"
);
}
kind_enum
.push_str
(
"}
\n
"
);
// Create timestamps
...
...
@@ -64,7 +65,7 @@ fn main() {
&
dest_path
,
format!
(
"{}
\n
{}
\n
{}
\n
{}
\n
"
,
ts_rows
,
static_xlap
,
kind_
consts
,
timestamp_id_enum
,
ts_rows
,
static_xlap
,
kind_
enum
,
timestamp_id_enum
,
),
)
.unwrap
();
...
...
src/lib.rs
View file @
f8cd9601
...
...
@@ -20,6 +20,23 @@ pub unsafe fn current_cycle() -> u64 {
include!
(
concat!
(
env!
(
"OUT_DIR"
),
"/xlap_generated.rs"
));
//const TS_ROWS: usize = 2;
//static XLAP: [AtomicPtr<TimestampTable>; 2] = [
// ...
//];
//#[derive(EnumIter, Copy, Clone)]
//#[allow(non_camel_case_types)]
//pub enum Kind {
// ...
//}
//#[derive(EnumCount, EnumIter, AsRefStr)]
//pub enum TimestampId {
// ...
//}
// ---------------------------------------------
/// A moment in time, expressed in cycles and time
...
...
@@ -42,27 +59,27 @@ static mut ZERO: Option<Instant> = None;
/// Update the clock value of a timestamp by setting it to an explicit value
#[inline(always)]
pub
unsafe
fn
timestamp_value
(
kind
:
usize
,
row
:
usize
,
id
:
TimestampId
,
value
:
Instant
)
{
(
*
XLAP
[
kind
]
.load
(
Ordering
::
Acquire
))
.rows
[
row
%
TS_ROWS
]
.timestamp
[
id
as
usize
]
.t
=
value
;
pub
unsafe
fn
timestamp_value
(
kind
:
Kind
,
row
:
usize
,
id
:
TimestampId
,
value
:
Instant
)
{
(
*
XLAP
[
kind
as
usize
]
.load
(
Ordering
::
Acquire
))
.rows
[
row
%
TS_ROWS
]
.timestamp
[
id
as
usize
]
.t
=
value
;
}
/// Update the clock value of a cyclestamp by setting it to an explicit value
#[inline(always)]
pub
unsafe
fn
cyclestamp_value
(
kind
:
usize
,
row
:
usize
,
id
:
TimestampId
,
value
:
u64
)
{
(
*
XLAP
[
kind
]
.load
(
Ordering
::
Acquire
))
.rows
[
row
%
TS_ROWS
]
.timestamp
[
id
as
usize
]
.c
=
value
;
pub
unsafe
fn
cyclestamp_value
(
kind
:
Kind
,
row
:
usize
,
id
:
TimestampId
,
value
:
u64
)
{
(
*
XLAP
[
kind
as
usize
]
.load
(
Ordering
::
Acquire
))
.rows
[
row
%
TS_ROWS
]
.timestamp
[
id
as
usize
]
.c
=
value
;
}
/// Update the clock value of a timestamp
#[inline(always)]
pub
unsafe
fn
timestamp_clock
(
kind
:
usize
,
row
:
usize
,
id
:
TimestampId
)
{
(
*
XLAP
[
kind
]
.load
(
Ordering
::
Acquire
))
.rows
[
row
%
TS_ROWS
]
.timestamp
[
id
as
usize
]
.t
=
pub
unsafe
fn
timestamp_clock
(
kind
:
Kind
,
row
:
usize
,
id
:
TimestampId
)
{
(
*
XLAP
[
kind
as
usize
]
.load
(
Ordering
::
Acquire
))
.rows
[
row
%
TS_ROWS
]
.timestamp
[
id
as
usize
]
.t
=
Instant
::
now
();
}
/// Update the cycle value of a timestamp
#[inline(always)]
pub
unsafe
fn
timestamp_cycle
(
kind
:
usize
,
row
:
usize
,
id
:
TimestampId
)
{
(
*
XLAP
[
kind
]
.load
(
Ordering
::
Acquire
))
.rows
[
row
%
TS_ROWS
]
.timestamp
[
id
as
usize
]
.c
=
pub
unsafe
fn
timestamp_cycle
(
kind
:
Kind
,
row
:
usize
,
id
:
TimestampId
)
{
(
*
XLAP
[
kind
as
usize
]
.load
(
Ordering
::
Acquire
))
.rows
[
row
%
TS_ROWS
]
.timestamp
[
id
as
usize
]
.c
=
current_cycle
();
}
...
...
@@ -83,13 +100,19 @@ impl TimestampTable {
}
/// Dump the collected timestamps to a csv file
pub
unsafe
fn
dump
(
file
:
&
str
)
->
std
::
io
::
Result
<
()
>
{
pub
unsafe
fn
dump_all
(
file
:
&
str
)
->
std
::
io
::
Result
<
()
>
{
Self
::
dump
(
file
,
Kind
::
iter
()
.collect
::
<
Vec
<
_
>>
()
.as_slice
())
}
/// Dump the collected timestamps of the given tables to a csv file
pub
unsafe
fn
dump
(
file
:
&
str
,
tables
:
&
[
Kind
])
->
std
::
io
::
Result
<
()
>
{
let
mut
file
=
std
::
fs
::
File
::
create
(
file
)
?
;
Self
::
dump_header
(
&
mut
file
)
?
;
for
(
kind
,
ptr
)
in
XLAP
.iter
()
.enumerate
()
{
let
table
=
&*
ptr
.load
(
Ordering
::
Acquire
);
for
kind
in
tables
{
let
table
=
&*
XLAP
[
*
kind
as
usize
]
.load
(
Ordering
::
Acquire
);
// TODO: skip the first one?
for
(
i
,
row
)
in
table
.rows
.iter
()
.enumerate
()
.skip
(
1
)
{
write!
(
&
mut
file
,
"{}, {}"
,
i
,
kind
)
?
;
write!
(
&
mut
file
,
"{}, {}"
,
i
,
*
kind
as
usize
)
?
;
for
timestamp
in
row
.timestamp
.iter
()
{
let
t
=
timestamp
.t
.saturating_duration_since
(
ZERO
.unwrap
());
write!
(
&
mut
file
,
", {}, {}"
,
t
.as_micros
(),
timestamp
.c
)
?
;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment