Skip to content

Commit

Permalink
Cleaned up printouts
Browse files Browse the repository at this point in the history
  • Loading branch information
connornishijima committed Feb 6, 2024
1 parent db08ffa commit 91fed09
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 49 deletions.
10 changes: 2 additions & 8 deletions src/cpu_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,7 @@ void run_cpu() {
watch_cpu_fps(t_now_us); // (system.h)

// Occasionally print the average frame rate
print_fps_values(t_now_ms);

// Occasionally print connected WS clients
print_websocket_clients(t_now_ms);
print_system_info(t_now_ms);

// Write pending changes to LittleFS
sync_configuration_to_file_system(t_now_ms);
Expand Down Expand Up @@ -76,10 +73,7 @@ void run_cpu() {
uint32_t processing_us_spent = processing_end_us - processing_start_us;
uint32_t audio_core_us_per_loop = 1000000.0 / FPS_CPU;
float audio_frame_to_processing_ratio = processing_us_spent / float(audio_core_us_per_loop);
if (iter % 500 == 0) {
printf("MAIN CPU CORE USAGE: %.4f\n", audio_frame_to_processing_ratio);
print_memory_info();
}
CPU_CORE_USAGE = audio_frame_to_processing_ratio;

//------------------------------------------------------------------------------------------
yield(); // Keep CPU watchdog happy
Expand Down
3 changes: 2 additions & 1 deletion src/global_defines.h
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
#define NUM_FREQS 64
#define NUM_FREQS ( 64 ) // Number of Goertzel instances running in parallel (musical AND tempi, 128 total)
#define MAX_WEBSOCKET_CLIENTS ( 4 ) // Max simultaneous remote controls allowed at one time
40 changes: 30 additions & 10 deletions src/profiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ float FPS_GPU_SAMPLES[16];
float FPS_CPU = 0.0;
float FPS_GPU = 0.0;

float CPU_CORE_USAGE = 0.0;

inline bool fastcmp_func_name(const char* input_a, const char* input_b){
// Is first char different? DISQUALIFIED!
if(input_a[0] != input_b[0]){ return false; }
Expand Down Expand Up @@ -110,10 +112,6 @@ void profile_function(ProfileFunc func, const char* func_name) {
}

void print_profiled_function_hits() {
// TODO: Clean up printing so that FPS, connected clients, CPU usage, etc. all print at once
printf("--------------------------------\n");
printf("CPU: %f GPU: %f (FPS)\n", FPS_CPU, FPS_GPU);

#ifdef PROFILER_ENABLED
for (uint16_t i = 0; i < num_profiled_functions; i++) {
if (PROFILER_HITS == true) {
Expand Down Expand Up @@ -151,7 +149,7 @@ void watch_gpu_fps(uint32_t t_now_us) {
last_call = t_now_us;
}

void print_fps_values(uint32_t t_now_ms) {
void print_system_info(uint32_t t_now_ms) {
static uint32_t next_print_ms = 0;
const uint16_t print_interval_ms = 1000;

Expand All @@ -167,11 +165,33 @@ void print_fps_values(uint32_t t_now_ms) {
FPS_CPU /= 16.0;
FPS_GPU /= 16.0;

char output[64];
snprintf(output, 64, "FPS | CPU: %.2f | GPU: %.2f\n", FPS_CPU, FPS_GPU);
printf(output);
// printf("I love Julie and Sage!\n");
uint32_t free_heap = esp_get_free_heap_size();
UBaseType_t free_stack_cpu = uxTaskGetStackHighWaterMark(NULL); // CPU core (this one)
UBaseType_t free_stack_gpu = uxTaskGetStackHighWaterMark(xTaskGetHandle("loop_gpu")); // GPU core

extern bool web_server_ready;
extern PsychicWebSocketClient *get_client_in_slot(uint8_t slot);

printf("# SYSTEM INFO ####################\n");
printf("CPU CORE USAGE: %.2f%%\n", CPU_CORE_USAGE*100);
printf("CPU FPS: %.3f\n", FPS_CPU);
printf("GPU FPS: %.3f\n", FPS_GPU);
printf("Free Heap: %lu\n", (uint32_t)free_heap);
printf("Free Stack CPU: %lu\n", (uint32_t)free_stack_cpu);
printf("Free Stack GPU: %lu\n", (uint32_t)free_stack_gpu);
printf("\n");
printf("- WS CLIENTS -----------------\n");
if(web_server_ready == true){
for(uint16_t i = 0; i < MAX_WEBSOCKET_CLIENTS; i++){
PsychicWebSocketClient *client = get_client_in_slot(i);
if (client != NULL) {
printf("%s\n", client->remoteIP().toString().c_str());
}
}
}
printf("------------------------------\n");

print_profiled_function_hits();
//print_profiled_function_hits();
printf("##################################\n\n");
}
}
8 changes: 0 additions & 8 deletions src/utilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,6 @@ int autocorrelate_with_pattern(const float* data, unsigned int data_length, cons
return max_shift;
}

// Function to print free stack and heap
void print_memory_info() {
UBaseType_t free_stack = uxTaskGetStackHighWaterMark(NULL);
uint32_t free_heap = esp_get_free_heap_size();

printf("Free Stack: %lu\tFree Heap: %lu\n", (uint32_t)free_stack, (uint32_t)free_heap);
}

inline bool fastcmp(char* input_a, char* input_b){
// Is first char different? DISQUALIFIED!
if(input_a[0] != input_b[0]){ return false; }
Expand Down
22 changes: 0 additions & 22 deletions src/wireless.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
#define MAX_HTTP_REQUEST_ATTEMPTS ( 8 ) // Define the maximum number of retry attempts
#define INITIAL_BACKOFF_MS ( 1000 ) // Initial backoff delay in milliseconds

#define MAX_WEBSOCKET_CLIENTS (4) // Max simultaneous remote controls allowed at one time

PsychicHttpServer server;
PsychicWebSocketHandler websocket_handler;
websocket_client websocket_clients[MAX_WEBSOCKET_CLIENTS];
Expand Down Expand Up @@ -162,26 +160,6 @@ void transmit_to_client_in_slot(char *message, uint8_t client_slot) {
}
}

void print_websocket_clients(uint32_t t_now_ms) {
static uint32_t next_print_ms = 0;
const uint16_t print_interval_ms = 5000;

if(web_server_ready == true){
if (t_now_ms >= next_print_ms) {
next_print_ms += print_interval_ms;

printf("## WS CLIENTS ###############\n");
for(uint16_t i = 0; i < MAX_WEBSOCKET_CLIENTS; i++){
PsychicWebSocketClient *client = get_client_in_slot(i);
if (client != NULL) {
printf("%s\n", client->remoteIP().toString().c_str());
}
}
printf("#############################\n");
}
}
}

void init_wifi() {
WiFi.begin(WIFI_SSID, WIFI_PASSWORD); // Start the WiFi connection with the
// SSID and password in secrets.h
Expand Down

0 comments on commit 91fed09

Please sign in to comment.