Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
SWIFTsim
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
SWIFT
SWIFTsim
Commits
91dcbc32
Commit
91dcbc32
authored
5 years ago
by
Loic Hausammann
Browse files
Options
Downloads
Patches
Plain Diff
Logger: Add structure for time record
parent
c739e843
No related branches found
No related tags found
1 merge request
!685
Logger loader
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
logger/logger_time.c
+30
-33
30 additions, 33 deletions
logger/logger_time.c
logger/logger_time.h
+16
-7
16 additions, 7 deletions
logger/logger_time.h
logger/tests/testTimeArray.c
+6
-3
6 additions, 3 deletions
logger/tests/testTimeArray.c
with
52 additions
and
43 deletions
logger/logger_time.c
+
30
−
33
View file @
91dcbc32
...
...
@@ -33,14 +33,19 @@ void time_array_ensure_size(struct time_array *t) {
/* Increase the size */
t
->
capacity
*=
2
;
t
->
time
=
realloc
(
t
->
time
,
sizeof
(
double
)
*
t
->
capacity
);
if
(
t
->
time
==
NULL
)
error
(
"Failed to realloc time memory."
);
/* Allocate the new array */
struct
time_record
*
tmp
=
malloc
(
sizeof
(
struct
time_record
)
*
t
->
capacity
);
if
(
tmp
==
NULL
)
error
(
"Failed to allocate the time records."
);
t
->
int_time
=
realloc
(
t
->
int_time
,
sizeof
(
integertime_t
)
*
t
->
capacity
);
if
(
t
->
int_time
==
NULL
)
error
(
"Failed to realloc integer time memory."
);
/* Copy the memory */
memcpy
(
tmp
,
t
->
records
,
sizeof
(
struct
time_record
)
*
t
->
size
);
t
->
offset
=
realloc
(
t
->
offset
,
sizeof
(
size_t
)
*
t
->
capacity
);
if
(
t
->
offset
==
NULL
)
error
(
"Failed to realloc offset memory."
);
/* Cleanup the memory */
free
(
t
->
records
);
/* Set the pointer to the new array */
t
->
records
=
tmp
;
}
/**
...
...
@@ -58,9 +63,9 @@ void time_array_append(struct time_array *t, const integertime_t int_time,
time_array_ensure_size
(
t
);
/* Copy the values */
t
->
time
[
t
->
size
]
=
time
;
t
->
int_time
[
t
->
size
]
=
int_time
;
t
->
offset
[
t
->
size
]
=
offset
;
t
->
records
[
t
->
size
]
.
time
=
time
;
t
->
records
[
t
->
size
]
.
int_time
=
int_time
;
t
->
records
[
t
->
size
]
.
offset
=
offset
;
/* Increase the size used. */
t
->
size
+=
1
;
...
...
@@ -141,14 +146,8 @@ size_t time_offset_first_record(const struct header *h) {
*/
void
time_array_init
(
struct
time_array
*
t
)
{
/* Allocate the arrays */
t
->
int_time
=
malloc
(
sizeof
(
integertime_t
)
*
LOGGER_TIME_INIT_SIZE
);
if
(
t
->
int_time
==
NULL
)
error
(
"Failed to initialize the integer times."
);
t
->
time
=
malloc
(
sizeof
(
double
)
*
LOGGER_TIME_INIT_SIZE
);
if
(
t
->
time
==
NULL
)
error
(
"Failed to initialize the times."
);
t
->
offset
=
malloc
(
sizeof
(
size_t
)
*
LOGGER_TIME_INIT_SIZE
);
if
(
t
->
offset
==
NULL
)
error
(
"Failed to initialize the offsets."
);
t
->
records
=
malloc
(
sizeof
(
struct
time_record
)
*
LOGGER_TIME_INIT_SIZE
);
if
(
t
->
records
==
NULL
)
error
(
"Failed to initialize the time records."
);
/* Initialize the sizes */
t
->
size
=
0
;
...
...
@@ -196,7 +195,7 @@ void time_array_populate(struct time_array *t, struct logger_logfile *log) {
integertime_t
time_array_get_integertime
(
struct
time_array
*
t
,
const
size_t
offset
)
{
size_t
ind
=
time_array_get_index
(
t
,
offset
);
return
t
->
int_time
[
ind
]
;
return
t
->
records
[
ind
].
int_time
;
}
/**
...
...
@@ -209,7 +208,7 @@ integertime_t time_array_get_integertime(struct time_array *t,
*/
double
time_array_get_time
(
const
struct
time_array
*
t
,
const
size_t
offset
)
{
size_t
ind
=
time_array_get_index
(
t
,
offset
);
return
t
->
time
[
ind
]
;
return
t
->
records
[
ind
].
time
;
}
/**
...
...
@@ -224,15 +223,18 @@ size_t time_array_get_index(const struct time_array *t, const size_t offset) {
#ifdef SWIFT_DEBUG_CHECKS
if
(
!
t
)
error
(
"NULL pointer."
);
if
(
offset
<
t
->
records
[
0
].
offset
||
offset
>
t
->
records
[
t
->
size
].
offset
)
error
(
"Offset outside of range."
);
#endif
/* Find the time_array with the correct offset. */
for
(
size_t
i
=
1
;
i
<
t
->
size
;
i
++
)
{
if
(
offset
<
t
->
offset
[
i
]
)
{
if
(
offset
<
t
->
records
[
i
].
offset
)
{
return
i
-
1
;
}
else
if
(
offset
==
t
->
offset
[
i
]
)
else
if
(
offset
==
t
->
records
[
i
].
offset
)
return
i
;
}
...
...
@@ -246,14 +248,8 @@ size_t time_array_get_index(const struct time_array *t, const size_t offset) {
*/
void
time_array_free
(
struct
time_array
*
t
)
{
/* Free the arrays */
free
(
t
->
int_time
);
t
->
int_time
=
NULL
;
free
(
t
->
time
);
t
->
time
=
NULL
;
free
(
t
->
offset
);
t
->
offset
=
NULL
;
free
(
t
->
records
);
t
->
records
=
NULL
;
/* Reset the counters */
t
->
size
=
0
;
...
...
@@ -271,13 +267,14 @@ void time_array_print(const struct time_array *t) {
size_t
n
=
t
->
size
;
size_t
up_threshold
=
n
-
threshold
;
printf
(
"Times (size %lu): [%lli (%g)"
,
n
,
t
->
int_time
[
0
],
t
->
time
[
0
]);
printf
(
"Times (size %lu): [%lli (%g)"
,
n
,
t
->
records
[
0
].
int_time
,
t
->
records
[
0
].
time
);
/* Loop over all elements. */
for
(
size_t
i
=
1
;
i
<
n
;
i
++
)
{
/* Skip the times at the center of the array. */
if
(
i
<
threshold
||
i
>
up_threshold
)
printf
(
", %lli (%g)"
,
t
->
int_time
[
i
]
,
t
->
time
[
i
]
);
printf
(
", %lli (%g)"
,
t
->
records
[
i
].
int_time
,
t
->
records
[
i
].
time
);
if
(
i
==
threshold
)
printf
(
", ..."
);
}
...
...
@@ -296,12 +293,12 @@ void time_array_print_offset(const struct time_array *t) {
size_t
n
=
t
->
size
;
size_t
up_threshold
=
n
-
threshold
;
printf
(
"Times (size %lu): [%lu"
,
n
,
t
->
offset
[
0
]
);
printf
(
"Times (size %lu): [%lu"
,
n
,
t
->
records
[
0
].
offset
);
/* Loop over all elements. */
for
(
size_t
i
=
1
;
i
<
n
;
i
++
)
{
/* Skip the offset in the middle of the array. */
if
(
i
<
threshold
||
i
>
up_threshold
)
printf
(
", %lu"
,
t
->
offset
[
i
]
);
if
(
i
<
threshold
||
i
>
up_threshold
)
printf
(
", %lu"
,
t
->
records
[
i
].
offset
);
if
(
i
==
threshold
)
printf
(
", ..."
);
}
...
...
This diff is collapsed.
Click to expand it.
logger/logger_time.h
+
16
−
7
View file @
91dcbc32
...
...
@@ -29,6 +29,20 @@ struct logger_reader;
#define LOGGER_TIME_INIT_SIZE 1024
/**
* @brief This structure contains all the information present in a time record.
*/
struct
time_record
{
/* Integertime of the records. */
integertime_t
int_time
;
/* Double time of the records. */
double
time
;
/* Offset in the file of the time records. */
size_t
offset
;
};
/**
* @brief This structure contains all the time record.
*
...
...
@@ -44,14 +58,9 @@ struct logger_reader;
* #time_array_get_index.
*/
struct
time_array
{
/* Integertime of the records. */
integertime_t
*
int_time
;
/* Double time of the records. */
double
*
time
;
/* Offset in the file of the time records. */
size_t
*
offset
;
/* The complete list of time record */
struct
time_record
*
records
;
/* Number of element in the arrays. */
size_t
size
;
...
...
This diff is collapsed.
Click to expand it.
logger/tests/testTimeArray.c
+
6
−
3
View file @
91dcbc32
...
...
@@ -27,11 +27,14 @@
int
main
(
int
argc
,
char
*
argv
[])
{
/* Check that we are really testing the reallocation */
if
(
NUMBER_OF_ELEMENT
<
LOGGER_TIME_INIT_SIZE
)
{
error
(
"Not testing the reallocation."
);
}
/* Fix the random seed in order to reproduce the results */
srand
(
100
);
/* Initialize the time array */
struct
time_array
times
;
time_array_init
(
&
times
);
...
...
@@ -66,9 +69,9 @@ int main(int argc, char *argv[]) {
/* Check the values obtained */
assert
(
i
==
ind
);
assert
(
int_time
==
times
.
int_time
[
ind
]
);
assert
(
time
==
times
.
time
[
ind
]
);
assert
(
offset
==
times
.
offset
[
ind
]
);
assert
(
int_time
==
times
.
records
[
ind
].
int_time
);
assert
(
time
==
times
.
records
[
ind
].
time
);
assert
(
offset
==
times
.
records
[
ind
].
offset
);
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment