Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
TDDD07
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Hugo Hörnquist
TDDD07
Commits
be1b9d60
Commit
be1b9d60
authored
2 years ago
by
Hugo Hörnquist
Browse files
Options
Downloads
Patches
Plain Diff
Random task select.
parent
9df2d30d
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
robot_agent/src/scheduler.c
+90
-18
90 additions, 18 deletions
robot_agent/src/scheduler.c
with
90 additions
and
18 deletions
robot_agent/src/scheduler.c
+
90
−
18
View file @
be1b9d60
...
...
@@ -14,12 +14,14 @@
#include
<stdlib.h>
#include
<sys/time.h>
#include
<unistd.h>
#include
<locale.h>
#include
<limits.h>
#include
<sys/stat.h>
/* project libraries */
#include
"scheduler.h"
#include
"task.h"
#include
"timelib.h"
#include
<locale.h>
/* -- Defines -- */
...
...
@@ -129,6 +131,51 @@ void scheduler_exec_task(scheduler_t *ces, int task_id)
}
}
const
char
*
const
task_names
[]
=
{
[
s_TASK_NOP_ID
]
=
"NOP"
,
[
s_TASK_MISSION_ID
]
=
"MISSION"
,
[
s_TASK_NAVIGATE_ID
]
=
"NAVIGATE"
,
[
s_TASK_CONTROL_ID
]
=
"CONTROL"
,
[
s_TASK_REFINE_ID
]
=
"REFINE"
,
[
s_TASK_REPORT_ID
]
=
"REPORT"
,
[
s_TASK_COMMUNICATE_ID
]
=
"COMMUNICATE"
,
[
s_TASK_AVOID_ID
]
=
"AVOID"
,
};
/* Select by commenting and uncommenting here */
int
const
tasks
[]
=
{
// s_TASK_NOP_ID,
s_TASK_MISSION_ID
,
s_TASK_NAVIGATE_ID
,
s_TASK_CONTROL_ID
,
s_TASK_REFINE_ID
,
s_TASK_REPORT_ID
,
s_TASK_COMMUNICATE_ID
,
// s_TASK_AVOID_ID,
};
size_t
task_count
=
sizeof
tasks
/
sizeof
(
int
);
#define DO(x) \
start = timelib_unix_timestamp(); \
for (int i = 0; i < 1; i++) { \
scheduler_exec_task(ces, (x)); \
} \
end = timelib_unix_timestamp(); \
printf(";%.9f\n", end - start, (end - start) / 1000.);
FILE
*
logfiles
[
255
]
=
{
0
};
void
close_files
(
void
)
{
for
(
int
i
=
0
;
i
<
task_count
;
i
++
)
{
if
(
logfiles
[
i
])
{
fclose
(
logfiles
[
i
]);
}
}
}
/**
* Run scheduler
* @param ces Pointer to scheduler structure
...
...
@@ -137,6 +184,20 @@ void scheduler_exec_task(scheduler_t *ces, int task_id)
void
scheduler_run
(
scheduler_t
*
ces
)
{
/* --- Local variables (define variables here) --- */
{
char
*
filename
=
malloc
(
PATH_MAX
);
mkdir
(
"/tmp/log"
,
0777
);
for
(
int
i
=
0
;
i
<
task_count
;
i
++
)
{
filename
[
0
]
=
'\0'
;
strcat
(
filename
,
"/tmp/log/"
);
strcat
(
filename
,
task_names
[
tasks
[
i
]]);
strcat
(
filename
,
".csv"
);
logfiles
[
i
]
=
fopen
(
filename
,
"w"
);
}
free
(
filename
);
}
atexit
(
close_files
);
/* --- Set minor cycle period --- */
ces
->
minor
=
100
;
...
...
@@ -146,24 +207,35 @@ void scheduler_run(scheduler_t *ces)
setlocale
(
LC_NUMERIC
,
"sv_SE.UTF-8"
);
double
start
,
end
;
#define DO(x) \
start = timelib_unix_timestamp(); \
for (int i = 0; i < 100; i++) { \
scheduler_exec_task(ces, (x)); \
} \
end = timelib_unix_timestamp(); \
printf(";%.9f\n", end - start, (end - start) / 1000.);
#if 1
for
(
int
j
=
0
;
j
<
100
;
j
++
)
{
printf
(
"Run %d
\n
"
,
j
);
DO
(
s_TASK_MISSION_ID
);
// 0.0005ms
DO
(
s_TASK_NAVIGATE_ID
);
// 0.1ms
DO
(
s_TASK_CONTROL_ID
);
// 0.6ms
DO
(
s_TASK_REFINE_ID
);
// 10ms
DO
(
s_TASK_REPORT_ID
);
// 0.00005ms
DO
(
s_TASK_COMMUNICATE_ID
);
// 1.7ms
DO
(
s_TASK_AVOID_ID
);
// 32ms
// printf("Collection loops;Communication time (ms)\n");
for
(
int
i
=
0
;
i
<
task_count
;
i
++
)
{
fprintf
(
logfiles
[
i
],
"Cycle;Task;Runcount;Victims;Time
\n
"
);
}
for
(
int
j
=
0
;;
j
++
)
{
if
(
j
%
10
==
0
/* timer_something */
)
{
printf
(
"Avoiding
\n
"
);
scheduler_exec_task
(
ces
,
s_TASK_AVOID_ID
);
}
start
=
timelib_unix_timestamp
();
int
selected_task
=
random
()
%
task_count
;
int
runcount
=
random
()
%
10
;
for
(
int
i
=
0
;
i
<
runcount
;
i
++
)
{
scheduler_exec_task
(
ces
,
tasks
[
selected_task
]);
}
end
=
timelib_unix_timestamp
();
fprintf
(
logfiles
[
selected_task
],
"%d;%s;%d;%d;%.9f
\n
"
,
j
,
task_names
[
selected_task
],
runcount
,
g_task_mission_data
.
victim_count
,
end
-
start
);
usleep
(
1e6
*
1
.
/
100
);
}
// sum = 45ms
...
...
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