Browse Source

Replace printf with DEBUG_ macros in debug_performance.c

nodeinfo-routing-update
Evgeny 8 months ago
parent
commit
8e5ca41879
  1. 22
      tests/debug_performance.c

22
tests/debug_performance.c

@ -4,44 +4,50 @@
#include <unistd.h> #include <unistd.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <fcntl.h> #include <fcntl.h>
#include "../lib/u_async.h"
#include "../lib/debug_config.h"
static void test_callback(int fd, void* arg) { static void test_callback(int fd, void* arg) {
(void)fd; (void)arg; (void)fd; (void)arg;
} }
int main() { int main() {
debug_config_init();
debug_set_level(DEBUG_LEVEL_TRACE);
debug_set_categories(DEBUG_CATEGORY_ALL);
uasync_t* ua = uasync_create(); uasync_t* ua = uasync_create();
if (!ua) return 1; if (!ua) return 1;
printf("=== Debug Performance Test ===\n"); DEBUG_INFO(DEBUG_CATEGORY_UASYNC, "=== Debug Performance Test ===");
// Test 1: Normal add/remove // Test 1: Normal add/remove
int sock1 = socket(AF_INET, SOCK_DGRAM, 0); int sock1 = socket(AF_INET, SOCK_DGRAM, 0);
void* id1 = uasync_add_socket(ua, sock1, test_callback, NULL, NULL, NULL); void* id1 = uasync_add_socket(ua, sock1, test_callback, NULL, NULL, NULL);
printf("Added socket %d: id=%p\n", sock1, id1); DEBUG_INFO(DEBUG_CATEGORY_UASYNC, "Added socket %d: id=%p", sock1, id1);
size_t alloc1, free1, alloc2, free2; size_t alloc1, free1, alloc2, free2;
uasync_get_stats(ua, &alloc1, &free1, &alloc2, &free2); uasync_get_stats(ua, &alloc1, &free1, &alloc2, &free2);
printf("After add: timers %zu/%zu, sockets %zu/%zu\n", alloc1, free1, alloc2, free2); DEBUG_INFO(DEBUG_CATEGORY_UASYNC, "After add: timers %zu/%zu, sockets %zu/%zu", alloc1, free1, alloc2, free2);
uasync_remove_socket(ua, id1); uasync_remove_socket(ua, id1);
printf("Removed socket %d\n", sock1); DEBUG_INFO(DEBUG_CATEGORY_UASYNC, "Removed socket %d", sock1);
uasync_get_stats(ua, &alloc1, &free1, &alloc2, &free2); uasync_get_stats(ua, &alloc1, &free1, &alloc2, &free2);
printf("After remove: timers %zu/%zu, sockets %zu/%zu\n", alloc1, free1, alloc2, free2); DEBUG_INFO(DEBUG_CATEGORY_UASYNC, "After remove: timers %zu/%zu, sockets %zu/%zu", alloc1, free1, alloc2, free2);
close(sock1); close(sock1);
// Test 2: Failed add // Test 2: Failed add
int sock2 = 9999; // Invalid socket int sock2 = 9999; // Invalid socket
void* id2 = uasync_add_socket(ua, sock2, test_callback, NULL, NULL, NULL); void* id2 = uasync_add_socket(ua, sock2, test_callback, NULL, NULL, NULL);
printf("Tried to add invalid socket %d: id=%p\n", sock2, id2); DEBUG_INFO(DEBUG_CATEGORY_UASYNC, "Tried to add invalid socket %d: id=%p", sock2, id2);
uasync_get_stats(ua, &alloc1, &free1, &alloc2, &free2); uasync_get_stats(ua, &alloc1, &free1, &alloc2, &free2);
printf("After failed add: timers %zu/%zu, sockets %zu/%zu\n", alloc1, free1, alloc2, free2); DEBUG_INFO(DEBUG_CATEGORY_UASYNC, "After failed add: timers %zu/%zu, sockets %zu/%zu", alloc1, free1, alloc2, free2);
uasync_destroy(ua, 0); uasync_destroy(ua, 0);
printf("Destroyed uasync\n"); DEBUG_INFO(DEBUG_CATEGORY_UASYNC, "Destroyed uasync");
return 0; return 0;
} }

Loading…
Cancel
Save