mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-11-20 11:34:57 +01:00
feat(physicslog): the logs written every two seconds by a thread of their own, no file kept open; the black box's tapes as it goes
"physicslog yes" kept the .dat of every vehicle with a driver open for the whole run and flushed it twenty times a second from the simulation's thread: some 580 open files on Tomaszewo. The lines are kept now and a thread of their own writes them every two seconds, each file opened only for the moment it is written to. The files, their lines and their text mode stay as they were. - The black box, with the physics logs off, writes the tapes of the user's vehicles through the same writer as it goes, not at the end. A log begins when the user is first in the vehicle and goes on while the user looks around outside, until another vehicle is taken; back in it, the log goes on after the gap. The vehicle's own driver keeps the log only if it is the primary one, as a passive one's clock stands still; otherwise the driver of its train does. - What is kept is written when the simulator closes, after the black box, at the end of a test run, and when the test watchdog ends a run. A crash loses the last two seconds. - On Tomaszewo with the black box alone, the one tape grows every two seconds. With "physicslog yes", the 581 logs grow and the simulator holds as many handles as without them; writing them takes the thread about 1.9 s, which the closing waits for once.
This commit is contained in:
@@ -23,6 +23,7 @@ http://mozilla.org/MPL/2.0/.
|
||||
#include "world/Track.h"
|
||||
#include "utilities/Globals.h"
|
||||
#include "utilities/Logs.h"
|
||||
#include "utilities/physicslog.h"
|
||||
#include "utilities/utilities.h"
|
||||
|
||||
#include <algorithm>
|
||||
@@ -280,7 +281,6 @@ void blackbox_recorder::close() {
|
||||
m_writer->end(m_time);
|
||||
m_writer.reset();
|
||||
m_file.close();
|
||||
write_tapes();
|
||||
using milliseconds = std::chrono::duration<double, std::milli>;
|
||||
WriteLog(std::format("Black box: recording closed; {} looks around, {:.3f} ms each on average, the longest {:.3f} ms", m_looks,
|
||||
m_looks > 0 ? milliseconds{m_looktime}.count() / m_looks : 0.0, milliseconds{m_looklongest}.count()));
|
||||
@@ -492,30 +492,16 @@ void blackbox_recorder::keep_tape_line() {
|
||||
return;
|
||||
auto const *vehicle{train->Dynamic()};
|
||||
// the driver of the vehicle, whose log it would be: it keeps the name of its first vehicle, so a change of the cab
|
||||
// in a unit goes on in the same log. in a vehicle without one, the driver of its train
|
||||
auto const *driver{vehicle->Mechanik != nullptr ? vehicle->Mechanik : vehicle->ctOwner};
|
||||
// in a unit goes on in the same log. a passive one stands still (its clock too), so then the driver of the train
|
||||
auto const *driver{vehicle->Mechanik != nullptr && vehicle->Mechanik->primary() ? vehicle->Mechanik : vehicle->ctOwner};
|
||||
if (driver == nullptr)
|
||||
return;
|
||||
m_tapes[driver->physicslog_name()] += driver->physicslog_line();
|
||||
}
|
||||
|
||||
void blackbox_recorder::write_tapes() {
|
||||
for (auto const &[name, lines] : m_tapes) {
|
||||
// opened as the driver opens its log, so the file is the same to the byte
|
||||
auto const filename{"physicslog/" + name + ".dat"};
|
||||
std::fstream file{filename, std::ios::in | std::ios::out | std::ios::trunc};
|
||||
if (false == file.is_open()) {
|
||||
ErrorLog(std::format("Black box: can't create the physics log \"{}\"", filename));
|
||||
continue;
|
||||
}
|
||||
file << TController::physicslog_header() << lines;
|
||||
file.close();
|
||||
if (file.fail())
|
||||
ErrorLog(std::format("Black box: the physics log \"{}\" wasn't written whole", filename));
|
||||
else
|
||||
WriteLog(std::format("Black box: the physics log \"{}\" written from the recording", filename));
|
||||
auto const &name{driver->physicslog_name()};
|
||||
if (m_tapes.insert(name).second) {
|
||||
PhysicsLogs.begin(name, TController::physicslog_header());
|
||||
WriteLog(std::format("Black box: the physics log \"physicslog/{}.dat\" begun", name));
|
||||
}
|
||||
m_tapes.clear();
|
||||
PhysicsLogs.append(name, driver->physicslog_line());
|
||||
}
|
||||
|
||||
void blackbox_recorder::look_around(bool const Keyframe) {
|
||||
|
||||
Reference in New Issue
Block a user