Mangoapp: frametime message queue

pull/657/head
FlightlessMango 2 years ago
parent 52ae70f650
commit ee7f3fbfd2

@ -8,7 +8,7 @@
#include "imgui_impl_opengl3.h"
#include <stdio.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <sys/msg.h>
#include <thread>
#include <unistd.h>
#include "../overlay.h"
@ -62,24 +62,38 @@ overlay_params params {};
static ImVec2 window_size;
static uint32_t vendorID;
static std::string deviceName;
int fd;
char str1[80];
char *shm_str;
struct mangoapp {
int pid;
int read;
};
mangoapp *mangoapp_ptr;
void read_thread(){
struct mangoapp_msg_header {
long msg_type; // Message queue ID, never change
uint32_t version; /* for major changes in the way things work */
} __attribute__((packed));
struct mangoapp_msg_v1 {
struct mangoapp_msg_header hdr;
uint32_t pid;
uint64_t frametime_ns;
// WARNING: Always ADD fields, never remove or repurpose fields
} __attribute__((packed));
static uint8_t raw_msg[1024] = {0};
void msg_read_thread(){
int key = ftok("mangoapp", 65);
int msgid = msgget(key, 0666 | IPC_CREAT);
const struct mangoapp_msg_header *hdr = (const struct mangoapp_msg_header*) raw_msg;
const struct mangoapp_msg_v1 *mangoapp_v1 = (const struct mangoapp_msg_v1*) raw_msg;
while (1){
if (mangoapp_ptr->read < 1) {
update_hud_info(sw_stats, params, vendorID);
mangoapp_ptr->read = 1;
// make sure that the message recieved is compatible
// and that we're not trying to use variables that don't exist (yet)
size_t msg_size = msgrcv(msgid, (void *) raw_msg, sizeof(raw_msg), 1, 0);
if (hdr->version == 1){
if (msg_size > offsetof(struct mangoapp_msg_v1, frametime_ns)){
update_hud_info_with_frametime(sw_stats, params, vendorID, mangoapp_v1->frametime_ns);
}
} else {
sleep(0.0001);
printf("Unsupported mangoapp struct version: %i\n", hdr->version);
exit(1);
}
}
}
@ -171,12 +185,7 @@ int main(int, char**)
init_gpu_stats(vendorID, params);
init_system_info();
sw_stats.engine = EngineTypes::GAMESCOPE;
// Our state
key_t key = ftok("mangoapp",65);
int shmid = shmget(key,sizeof(mangoapp),0666|IPC_CREAT);
auto shm_address = shmat(shmid, (void*)0, 0);
mangoapp_ptr = (mangoapp*)shm_address;
std::thread(read_thread).detach();
std::thread(msg_read_thread).detach();
// Main loop
while (!glfwWindowShouldClose(window))
{

@ -159,7 +159,7 @@ void stop_hw_updater()
hw_update_thread.reset();
}
void update_hud_info(struct swapchain_stats& sw_stats, struct overlay_params& params, uint32_t vendorID){
void update_hud_info_with_frametime(struct swapchain_stats& sw_stats, struct overlay_params& params, uint32_t vendorID, uint64_t frametime_ns){
uint32_t f_idx = sw_stats.n_frames % ARRAY_SIZE(sw_stats.frames_stats);
uint64_t now = os_time_get_nano(); /* ns */
double elapsed = (double)(now - sw_stats.last_fps_update); /* ns */
@ -169,10 +169,10 @@ void update_hud_info(struct swapchain_stats& sw_stats, struct overlay_params& pa
if (sw_stats.last_present_time) {
sw_stats.frames_stats[f_idx].stats[OVERLAY_PLOTS_frame_timing] =
now - sw_stats.last_present_time;
frametime_ns;
}
frametime = (now - sw_stats.last_present_time) / 1000;
frametime = frametime_ns / 1000;
if (elapsed >= params.fps_sampling_period) {
if (!hw_update_thread)
@ -202,6 +202,12 @@ void update_hud_info(struct swapchain_stats& sw_stats, struct overlay_params& pa
sw_stats.n_frames_since_update++;
}
void update_hud_info(struct swapchain_stats& sw_stats, struct overlay_params& params, uint32_t vendorID){
uint64_t now = os_time_get_nano(); /* ns */
uint64_t frametime_ns = now - sw_stats.last_present_time;
update_hud_info_with_frametime(sw_stats, params, vendorID, frametime_ns);
}
void calculate_benchmark_data(){
vector<float> sorted = benchmark.fps_data;
std::sort(sorted.begin(), sorted.end());

@ -145,6 +145,7 @@ extern overlay_params *_params;
void position_layer(struct swapchain_stats& data, struct overlay_params& params, ImVec2 window_size);
void render_imgui(swapchain_stats& data, struct overlay_params& params, ImVec2& window_size, bool is_vulkan);
void update_hud_info(struct swapchain_stats& sw_stats, struct overlay_params& params, uint32_t vendorID);
void update_hud_info_with_frametime(struct swapchain_stats& sw_stats, struct overlay_params& params, uint32_t vendorID, uint64_t frametime_ns);
void update_hw_info(struct swapchain_stats& sw_stats, struct overlay_params& params, uint32_t vendorID);
void init_gpu_stats(uint32_t& vendorID, overlay_params& params);
void init_cpu_stats(overlay_params& params);

Loading…
Cancel
Save