Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature module start time #311

Merged
merged 42 commits into from
Jan 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
15a7a1b
Ran formatting script
konglobemeralt Oct 6, 2020
904722d
Merge branch 'dev' of https://github.com/RI-SE/Maestro into dev
konglobemeralt Dec 2, 2020
b8b74af
Added starttime to modules
konglobemeralt Dec 3, 2020
ed61307
Changed name from temp tu statusBuffer
konglobemeralt Dec 3, 2020
4aabd20
Update test.conf
konglobemeralt Dec 3, 2020
00fa87e
Ran formatting script
konglobemeralt Dec 3, 2020
f5599f9
Merge branch 'feature_moduleStartTime' of https://github.com/RI-SE/Ma…
konglobemeralt Dec 3, 2020
c1842d1
Update core/src/systemcontrol.c
konglobemeralt Dec 8, 2020
a581361
Update modules/ScenarioControl/src/main.cpp
konglobemeralt Dec 8, 2020
12e4b49
Moved pid proc reader to util
konglobemeralt Dec 8, 2020
3b8647d
Fixed merge conflict
konglobemeralt Dec 8, 2020
cf2b62f
Merge branch 'dev' into feature_moduleStartTime
konglobemeralt Dec 8, 2020
2031a55
Fixed PATH_MAX
konglobemeralt Dec 8, 2020
c6f8f39
Added enum for proc fields
konglobemeralt Dec 8, 2020
85f70fc
Merge branch 'feature_moduleStartTime' of https://github.com/RI-SE/Ma…
konglobemeralt Dec 8, 2020
f34cd22
Added error return
konglobemeralt Dec 8, 2020
9de51b7
Update core/src/util.c
konglobemeralt Dec 8, 2020
2b331ed
Update core/src/util.c
konglobemeralt Dec 9, 2020
fbfb43d
Merge branch 'dev' into feature_moduleStartTime
konglobemeralt Dec 9, 2020
54fb527
Update core/src/util.c
konglobemeralt Dec 9, 2020
ebec962
Merge branch 'dev' into feature_moduleStartTime
konglobemeralt Dec 10, 2020
a2fc66f
Merge branch 'dev' into feature_moduleStartTime
konglobemeralt Dec 10, 2020
4d4b753
Update core/src/systemcontrol.c
konglobemeralt Dec 10, 2020
362b308
Merge branch 'dev' into feature_moduleStartTime
LukasWikander Dec 11, 2020
947ad13
Update core/src/util.c
konglobemeralt Dec 11, 2020
df50c9a
Ran code formatter
konglobemeralt Dec 11, 2020
0b50433
Fixed case
konglobemeralt Dec 11, 2020
80d7ba3
Fixed case
konglobemeralt Dec 11, 2020
8221142
Merge branch 'dev' into feature_moduleStartTime
LukasWikander Dec 11, 2020
2fd9671
Merge branch 'dev' into feature_moduleStartTime
konglobemeralt Jan 13, 2021
06188e9
Merge branch 'dev' into feature_moduleStartTime
konglobemeralt Jan 13, 2021
98ceb3a
Changed string to timeval struct
konglobemeralt Jan 13, 2021
6943d43
Merge branch 'feature_moduleStartTime' of https://github.com/RI-SE/Ma…
konglobemeralt Jan 13, 2021
06e6112
Changed MODULES_IN_USE to 2
konglobemeralt Jan 13, 2021
ff6fd56
Added nicer responses for modules
konglobemeralt Jan 13, 2021
4a14a70
Merge branch 'feature_moduleStartTime' of https://github.com/RI-SE/Ma…
konglobemeralt Jan 13, 2021
54b7a46
Ran formatter
konglobemeralt Jan 14, 2021
309b30c
Removed extraneous printout
konglobemeralt Jan 14, 2021
4ad5d83
Ran formatter again
konglobemeralt Jan 14, 2021
c710f9e
Small format fix
konglobemeralt Jan 14, 2021
be0ffc9
Merge branch 'dev' into feature_moduleStartTime
konglobemeralt Jan 15, 2021
e505fe4
Merge branch 'dev' into feature_moduleStartTime
konglobemeralt Jan 26, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions core/inc/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -743,9 +743,12 @@ I32 UtilPopulateEXACDataStructFromMQ(C8* rawEXAC, size_t rawEXACsize, EXACData *
I32 UtilPopulateTRCMDataStructFromMQ(C8* rawTRCM, size_t rawTRCMsize, TRCMData *trcmData);
I32 UtilPopulateACCMDataStructFromMQ(C8* rawACCM, size_t rawACCMsize, ACCMData *accmData);

struct timeval UtilGetPIDUptime(pid_t pID);
double UtilGetDistance(double lat1, double lon1, double lat2, double lon2);


enum procFields {startTime = 21, vSize = 22};

typedef struct {
uint64_t timestamp;
int32_t latitude;
Expand Down
6 changes: 4 additions & 2 deletions core/src/journalcontrol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,14 +134,16 @@ void journalcontrol_task(TimeType * GPSTime, GSDType * GSD, LOG_LEVEL logLevel)
generateOutputJournal(journals);
break;

case COMM_GETSTATUS:
case COMM_GETSTATUS: {
std::fill(mqSendBuffer.begin(), mqSendBuffer.end(), 0);
snprintf(mqSendBuffer.data(), mqSendBuffer.size(), "%s", MODULE_NAME);
unsigned long startTime = UtilGetPIDUptime(getpid()).tv_sec;
snprintf(mqSendBuffer.data(), mqSendBuffer.size(), "%s:%lu", MODULE_NAME, startTime);
mqSendBuffer.back() = '\0';
if (iCommSend(COMM_GETSTATUS_OK, mqSendBuffer.data(), mqSendBuffer.size()) < 0) {
LogMessage(LOG_LEVEL_ERROR, "Fatal communication fault when sending status reply");
}
break;
}
case COMM_REPLAY:
LogMessage(LOG_LEVEL_WARNING, "Replay function out of date");
break;
Expand Down
44 changes: 10 additions & 34 deletions core/src/systemcontrol.c
Original file line number Diff line number Diff line change
Expand Up @@ -2911,11 +2911,8 @@ void appendSysInfoString(char *ControlResponseBuffer, const size_t bufferSize) {

size_t remainingBufferSpace = bufferSize;
struct sysinfo info;
char procFilename[100] = { 0 };
char stringBuffer[255], statFileBuffer[255];
char stringBuffer[255];
long hours, minutes, seconds;
pid_t pid = 0;
FILE *pidstat = NULL;

// Server uptime
sysinfo(&info);
Expand All @@ -2928,39 +2925,18 @@ void appendSysInfoString(char *ControlResponseBuffer, const size_t bufferSize) {
strncat(ControlResponseBuffer, stringBuffer, remainingBufferSpace - 1);
remainingBufferSpace -= strlen(stringBuffer);

pid = getpid();
snprintf(procFilename, sizeof (procFilename), "/proc/%d/stat", pid);
unsigned long startTime = UtilGetPIDUptime(getpid()).tv_sec;

pidstat = fopen(procFilename, "r");
if (pidstat == NULL) {
LogMessage(LOG_LEVEL_ERROR, "Could not open file %s", procFilename);
return;
}

fgets(statFileBuffer, sizeof (statFileBuffer), pidstat);
fclose(pidstat);
unsigned long long timeAtStart = startTime / (unsigned long long)(sysconf(_SC_CLK_TCK));
long serverUptime = (long)((unsigned long long)info.uptime - timeAtStart);

// Get start time from proc/pid/stat
char *token = strtok(statFileBuffer, " ");
int statIndex = 0;

while (token != NULL) {
if (statIndex == 21) { //Get starttime %llu from proc file for pid.
unsigned long long timeAtStart =
strtoull(token, NULL, 10) / (unsigned long long)(sysconf(_SC_CLK_TCK));
long serverUptime = (long)((unsigned long long)info.uptime - timeAtStart);

hours = serverUptime / 3600;
minutes = (serverUptime - (3600 * hours)) / 60;
seconds = (serverUptime - (3600 * hours) - (minutes * 60));
sprintf(stringBuffer, "Server uptime: %ld:%ld:%ld\n", hours, minutes, seconds);
strncat(ControlResponseBuffer, stringBuffer, remainingBufferSpace - 1);
remainingBufferSpace -= strlen(stringBuffer);
break;
}
token = strtok(NULL, " ");
statIndex++;
}
hours = serverUptime / 3600;
minutes = (serverUptime - (3600 * hours)) / 60;
seconds = (serverUptime - (3600 * hours) - (minutes * 60));
sprintf(stringBuffer, "Server uptime: %ld:%ld:%ld\n", hours, minutes, seconds);
strncat(ControlResponseBuffer, stringBuffer, remainingBufferSpace - 1);
remainingBufferSpace -= strlen(stringBuffer);
//Make it clear that this is placeholder data
strncat(ControlResponseBuffer, "Maestro powerlevel: 90001\n", remainingBufferSpace - 1);
}
46 changes: 46 additions & 0 deletions core/src/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -3963,6 +3963,52 @@ I32 UtilPopulateACCMDataStructFromMQ(C8 * rawACCM, size_t rawACCMsize, ACCMData
return 0;
}


/*!
* \brief getPIDuptime reads the proc file of the pid in question and returns start time of the process after boot. In kernels before Linux 2.6, this value was expressed in
jiffies. Since Linux 2.6, the value is expressed in
clock ticks (divide by sysconf(_SC_CLK_TCK)).
* \param pid the pid in question.
* \return The time the process started after system boot.
*/
struct timeval UtilGetPIDUptime(pid_t pID) {
FILE *pidstat = NULL;
struct timeval timeSinceStart;
char filename[PATH_MAX] = { 0 };
snprintf(filename, sizeof (filename), "/proc/%d/stat", pID);

pidstat = fopen(filename, "r");
if (pidstat == NULL) {
LogMessage(LOG_LEVEL_ERROR, "Error: Couldn't open [%s]\n", filename);
timeSinceStart.tv_sec = -1;
timeSinceStart.tv_usec = -1;
return timeSinceStart;
}

char strval1[100] = { 0 };
fgets(strval1, 255, pidstat);

fclose(pidstat);
// Get start time from proc/pid/stat
char *token = strtok(strval1, " ");
int loopCounter = 0;

char uptime[247];

while (token != NULL) {
if (loopCounter == startTime) { //Get starttime %llu from proc file for pid.
sprintf(uptime, "%s", token);
}
token = strtok(NULL, " ");
loopCounter++;
}


timeSinceStart.tv_sec = (strtoul(uptime, NULL, 10));
return timeSinceStart;
}


/*!
* \brief UtilgetDistance calculates the distance between two log lat positions usgin haversine formula.
* \param lat1 Latitude of first coordinate
Expand Down
7 changes: 5 additions & 2 deletions modules/ScenarioControl/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,15 @@ int main()
LogMessage(LOG_LEVEL_INFO,"Received disconnect command");
state = UNINITIALIZED;
break;
case COMM_GETSTATUS:
case COMM_GETSTATUS: {
unsigned long startTime = UtilGetPIDUptime(getpid()).tv_sec;
memset(mqSendData, 0, sizeof (mqSendData));
sprintf(mqSendData, "%s", MODULE_NAME);
sprintf(mqSendData, "%s:%lu", MODULE_NAME, startTime);

if (iCommSend(COMM_GETSTATUS_OK, mqSendData, sizeof (mqSendData)) < 0) {
LogMessage(LOG_LEVEL_ERROR, "Fatal communication fault when sending GETSTATUS.");
}
}
break;
case COMM_GETSTATUS_OK:
break;
Expand Down
7 changes: 5 additions & 2 deletions modules/Supervision/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,15 @@ int main() {
break;
case COMM_OBC_STATE:
break;
case COMM_GETSTATUS:
case COMM_GETSTATUS: {
unsigned long startTime = UtilGetPIDUptime(getpid()).tv_sec;
memset(mqSendData, 0, sizeof (mqSendData));
sprintf(mqSendData, "%s", MODULE_NAME);
sprintf(mqSendData, "%s:%lu", MODULE_NAME, startTime);

if (iCommSend(COMM_GETSTATUS_OK, mqSendData, sizeof (mqSendData)) < 0) {
LogMessage(LOG_LEVEL_ERROR, "Fatal communication fault when sending GETSTATUS.");
}
}
break;
case COMM_GETSTATUS_OK:
break;
Expand Down