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
23bb415e
Commit
23bb415e
authored
Feb 24, 2021
by
Sven Liefgen
Browse files
Add feature gate to enable xlap
This means xlap is disabled by default
parent
c7b85aa6
Changes
3
Hide whitespace changes
Inline
Side-by-side
Cargo.toml
View file @
23bb415e
...
...
@@ -6,6 +6,9 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[features]
xlap
=
[]
[dependencies]
strum
=
{
version
=
"0.20"
,
features
=
["derive"]
}
...
...
build.rs
View file @
23bb415e
...
...
@@ -25,7 +25,8 @@ fn main() {
.len
();
let
mut
static_xlap
=
format!
(
"static XLAP: [AtomicPtr<TimestampTable>; {}] = [
\n
"
,
"#[cfg(feature =
\"
xlap
\"
)]
\n
\
static XLAP: [AtomicPtr<TimestampTable>; {}] = [
\n
"
,
packet_types_count
);
for
_
in
0
..
packet_types_count
{
...
...
@@ -35,7 +36,8 @@ fn main() {
// Create constants for kinds
let
mut
kind_enum
=
String
::
from
(
"#[derive(EnumIter, Copy, Clone)]
\n
"
);
let
mut
kind_enum
=
String
::
from
(
"#[cfg(feature =
\"
xlap
\"
)]
\n
"
);
kind_enum
.push_str
(
"#[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
()
{
...
...
@@ -49,8 +51,8 @@ fn main() {
let
timestamps
=
&
yaml
[
"stamps"
];
let
mut
timestamp_id_enum
=
String
::
from
(
"#[derive(EnumCount, EnumIter, AsRefStr, Copy, Clone)]
\n
"
);
let
mut
timestamp_id_enum
=
String
::
from
(
"#[cfg(feature =
\"
xlap
\"
)]"
);
timestamp_id_enum
.push_str
(
"#[derive(EnumCount, EnumIter, AsRefStr, Copy, Clone)]
\n
"
);
timestamp_id_enum
.push_str
(
"pub enum TimestampId {
\n
"
);
for
timestamp_id
in
timestamps
.as_hash
()
...
...
@@ -67,7 +69,11 @@ fn main() {
let
count
=
&
yaml
[
"rows"
]
.as_i64
()
.unwrap_or
(
4098
);
let
ts_rows
=
format!
(
"const TS_ROWS: usize = {};
\n
"
,
count
+
1
);
let
ts_rows
=
format!
(
"#[cfg(feature =
\"
xlap
\"
)]
\n
\
const TS_ROWS: usize = {};
\n
"
,
count
+
1
);
fs
::
write
(
&
dest_path
,
...
...
src/lib.rs
View file @
23bb415e
...
...
@@ -45,18 +45,22 @@ struct Timestamp {
t
:
Instant
,
}
#[cfg(feature
=
"xlap"
)]
/// A row wit timestamps
struct
TimestampTableRow
{
timestamp
:
[
Timestamp
;
TimestampId
::
COUNT
],
}
#[cfg(feature
=
"xlap"
)]
/// Table containing all the timestamps
pub
struct
TimestampTable
{
rows
:
[
TimestampTableRow
;
TS_ROWS
],
}
#[cfg(feature
=
"xlap"
)]
static
mut
ZERO
:
Option
<
Instant
>
=
None
;
#[cfg(feature
=
"xlap"
)]
/// Update the clock and cycle value of a timestamp by setting them to en explicit value
#[inline(always)]
pub
unsafe
fn
set_timestamp
(
kind
:
Kind
,
row
:
usize
,
id
:
TimestampId
,
(
t
,
c
):
(
Instant
,
u64
))
{
...
...
@@ -64,6 +68,7 @@ pub unsafe fn set_timestamp(kind: Kind, row: usize, id: TimestampId, (t, c): (In
set_timestamp_cycle
(
kind
,
row
,
id
,
c
);
}
#[cfg(feature
=
"xlap"
)]
/// Update the clock value of a timestamp by setting it to an explicit value
#[inline(always)]
pub
unsafe
fn
set_timestamp_clock
(
kind
:
Kind
,
row
:
usize
,
id
:
TimestampId
,
value
:
Instant
)
{
...
...
@@ -71,6 +76,7 @@ pub unsafe fn set_timestamp_clock(kind: Kind, row: usize, id: TimestampId, value
value
;
}
#[cfg(feature
=
"xlap"
)]
/// Update the clock value of a cyclestamp by setting it to an explicit value
#[inline(always)]
pub
unsafe
fn
set_timestamp_cycle
(
kind
:
Kind
,
row
:
usize
,
id
:
TimestampId
,
value
:
u64
)
{
...
...
@@ -78,6 +84,7 @@ pub unsafe fn set_timestamp_cycle(kind: Kind, row: usize, id: TimestampId, value
value
;
}
#[cfg(feature
=
"xlap"
)]
/// Update the clock value of a timestamp
#[inline(always)]
pub
unsafe
fn
timestamp_clock
(
kind
:
Kind
,
row
:
usize
,
id
:
TimestampId
)
{
...
...
@@ -85,6 +92,7 @@ pub unsafe fn timestamp_clock(kind: Kind, row: usize, id: TimestampId) {
Instant
::
now
();
}
#[cfg(feature
=
"xlap"
)]
/// Update the cycle value of a timestamp
#[inline(always)]
pub
unsafe
fn
timestamp_cycle
(
kind
:
Kind
,
row
:
usize
,
id
:
TimestampId
)
{
...
...
@@ -92,18 +100,21 @@ pub unsafe fn timestamp_cycle(kind: Kind, row: usize, id: TimestampId) {
current_cycle
();
}
#[cfg(feature
=
"xlap"
)]
/// Create a clock value without saving it to a table
#[inline(always)]
pub
fn
get_timestamp_clock
()
->
Instant
{
Instant
::
now
()
}
#[cfg(feature
=
"xlap"
)]
/// Create a cycle value without saving it to a table
#[inline(always)]
pub
fn
get_timestamp_cycle
()
->
u64
{
unsafe
{
current_cycle
()
}
}
#[cfg(feature
=
"xlap"
)]
/// Install a timestamp table
///
/// Allocate memory for the empty timestamp tables and store pointers in the XLAP static
...
...
@@ -119,6 +130,7 @@ pub unsafe fn init() {
}
}
#[cfg(feature
=
"xlap"
)]
impl
TimestampTable
{
/// Dump the collected timestamps to a csv file
pub
unsafe
fn
dump_all
(
file
:
&
str
)
->
std
::
io
::
Result
<
()
>
{
...
...
@@ -153,3 +165,78 @@ impl TimestampTable {
Ok
(())
}
}
#[cfg(not(feature
=
"xlap"
))]
/// Table containing all the timestamps
pub
struct
TimestampTable
;
#[cfg(not(feature
=
"xlap"
))]
pub
struct
Kind
;
#[cfg(not(feature
=
"xlap"
))]
pub
struct
TimestampId
;
#[cfg(not(feature
=
"xlap"
))]
/// Update the clock and cycle value of a timestamp by setting them to en explicit value
#[inline(always)]
pub
unsafe
fn
set_timestamp
(
_
:
Kind
,
_
:
usize
,
_
:
TimestampId
,
_
:
(
Instant
,
u64
))
{}
#[cfg(not(feature
=
"xlap"
))]
/// Update the clock value of a timestamp by setting it to an explicit value
#[inline(always)]
pub
unsafe
fn
set_timestamp_clock
(
_
:
Kind
,
_
:
usize
,
_
:
TimestampId
,
_
:
Instant
)
{}
#[cfg(not(feature
=
"xlap"
))]
/// Update the clock value of a cyclestamp by setting it to an explicit value
#[inline(always)]
pub
unsafe
fn
set_timestamp_cycle
(
_
:
Kind
,
_
:
usize
,
_
:
TimestampId
,
_
:
u64
)
{}
#[cfg(not(feature
=
"xlap"
))]
/// Update the clock value of a timestamp
#[inline(always)]
pub
unsafe
fn
timestamp_clock
(
_
:
Kind
,
_
:
usize
,
_
:
TimestampId
)
{}
#[cfg(not(feature
=
"xlap"
))]
/// Update the cycle value of a timestamp
#[inline(always)]
pub
unsafe
fn
timestamp_cycle
(
_
:
Kind
,
_
:
usize
,
_
:
TimestampId
)
{}
#[cfg(not(feature
=
"xlap"
))]
/// Create a clock value without saving it to a table
#[inline(always)]
pub
fn
get_timestamp_clock
()
->
Instant
{
Instant
::
now
()
}
#[cfg(not(feature
=
"xlap"
))]
/// Create a cycle value without saving it to a table
#[inline(always)]
pub
fn
get_timestamp_cycle
()
->
u64
{
0
}
#[cfg(not(feature
=
"xlap"
))]
/// Install a timestamp table
///
/// Allocate memory for the empty timestamp tables and store pointers in the XLAP static
pub
unsafe
fn
init
()
{}
#[cfg(not(feature
=
"xlap"
))]
impl
TimestampTable
{
/// Dump the collected timestamps to a csv file
pub
unsafe
fn
dump_all
(
file
:
&
str
)
->
std
::
io
::
Result
<
()
>
{
Self
::
dump
(
file
,
&
[])
}
/// Dump the collected timestamps of the given tables to a csv file
pub
unsafe
fn
dump
(
file
:
&
str
,
_
:
&
[
Kind
])
->
std
::
io
::
Result
<
()
>
{
let
mut
file
=
std
::
fs
::
File
::
create
(
file
)
?
;
Self
::
dump_header
(
&
mut
file
)
?
;
Ok
(())
}
fn
dump_header
(
file
:
&
mut
std
::
fs
::
File
)
->
std
::
io
::
Result
<
()
>
{
write!
(
file
,
"XLAP was disabled"
)
?
;
Ok
(())
}
}
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