- u_async.c: process immediate_queue BEFORE epoll_wait in uasync_poll - stcp_link.c: defensive NULL etcp_conn/etcp_link in stcp_link_close - utun_instance.c: move stcp_server_list_destroy_all to Phase J (before ETCP), add deferred drain in both Phase J and L - stcp.h/c: STCP_HS_ENC_CLIENT 6→38, STCP_HS_ENC_SERVER 7→39, exchange ed25519_pubkey in both handshake directions - etcp_connections.c: copy peer_ed25519 from STCP to ETCP_CONN in etcp_link_enter_ready_tcp; guard link->etcp in tcp_link_close_cb - chat_sync.c: fix lk->conn NULL dereference for TCP links - test_stcp.c: update stcp_server_create/stcp_client_connect callsites - tools/chat_tcp_test: change transport udp→tcp
53 lines
1.3 KiB
C
53 lines
1.3 KiB
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <unistd.h>
|
|
|
|
#define BLOCK_SIZE 10
|
|
|
|
static int counts[] = {0, 100, 1000, 10000, 100000};
|
|
static int n_counts = 5;
|
|
|
|
static long read_vm_field(const char *field) {
|
|
char path[64], buf[256];
|
|
snprintf(path, sizeof(path), "/proc/%d/status", getpid());
|
|
FILE *f = fopen(path, "r");
|
|
if (!f) return -1;
|
|
long val = -1;
|
|
while (fgets(buf, sizeof(buf), f)) {
|
|
if (strncmp(buf, field, strlen(field)) == 0) {
|
|
sscanf(buf + strlen(field) + 1, "%ld", &val);
|
|
break;
|
|
}
|
|
}
|
|
fclose(f);
|
|
return val;
|
|
}
|
|
|
|
static void measure(const char *label) {
|
|
long rss = read_vm_field("VmRSS");
|
|
long data = read_vm_field("VmData");
|
|
long size = read_vm_field("VmSize");
|
|
printf(" %-8s VmRSS=%6ld kB VmData=%6ld kB VmSize=%6ld kB\n", label, rss, data, size);
|
|
}
|
|
|
|
int main(void) {
|
|
printf("Block size: %d bytes\n", BLOCK_SIZE);
|
|
|
|
for (int c = 0; c < n_counts; c++) {
|
|
int n = counts[c];
|
|
printf("\n--- %d blocks (requested %d bytes) ---\n", n, n * BLOCK_SIZE);
|
|
measure("before");
|
|
|
|
void **ptrs = malloc(n * sizeof(void*));
|
|
for (int i = 0; i < n; i++) {
|
|
ptrs[i] = malloc(BLOCK_SIZE);
|
|
memset(ptrs[i], 0, BLOCK_SIZE);
|
|
}
|
|
|
|
measure("after ");
|
|
free(ptrs);
|
|
}
|
|
return 0;
|
|
}
|