mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-08-22 10:10:06 +00:00
This required couple of internal changes to the isc_mem_debugging. The isc_mem_debugging is now internal to isc_mem unit and there are three new functions: 1. isc_mem_setdebugging() can change the debugging setting for an individual memory context. This is need for the memory contexts used for OpenSSL, libxml and libuv accounting as recording and tracing memory is broken there. 2. isc_mem_debugon() / isc_mem_debugoff() can be used to change default memory debugging flags as well as debugging flags for isc_g_mctx. Additionally, the memory debugging is inconsistent across the code-base. For now, we are keeping the existing flags, but three new environment variables have been added 'ISC_MEM_DEBUGRECORD', 'ISC_MEM_DEBUGTRACE' and 'ISC_MEM_DEBUGUSAGE' to set the global debugging flags at any program using the memory contexts.
102 lines
2.4 KiB
C
102 lines
2.4 KiB
C
/*
|
|
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
|
*
|
|
* SPDX-License-Identifier: MPL-2.0
|
|
*
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, you can obtain one at https://mozilla.org/MPL/2.0/.
|
|
*
|
|
* See the COPYRIGHT file distributed with this work for additional
|
|
* information regarding copyright ownership.
|
|
*/
|
|
#include <err.h>
|
|
#include <errno.h>
|
|
#include <stdbool.h>
|
|
#include <stdint.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
|
|
#include <isc/buffer.h>
|
|
#include <isc/lib.h>
|
|
#include <isc/mem.h>
|
|
#include <isc/result.h>
|
|
#include <isc/time.h>
|
|
#include <isc/util.h>
|
|
|
|
#include <dns/compress.h>
|
|
#include <dns/fixedname.h>
|
|
#include <dns/lib.h>
|
|
#include <dns/name.h>
|
|
|
|
static void
|
|
CHECKRESULT(isc_result_t result, const char *msg) {
|
|
if (result != ISC_R_SUCCESS) {
|
|
printf("%s: %s\n", msg, isc_result_totext(result));
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
}
|
|
|
|
int
|
|
main(void) {
|
|
isc_result_t result;
|
|
isc_buffer_t buf;
|
|
|
|
static dns_fixedname_t fixedname[65536];
|
|
unsigned int count = 0;
|
|
|
|
char *line = NULL;
|
|
size_t linecap = 0;
|
|
ssize_t linelen;
|
|
while ((linelen = getline(&line, &linecap, stdin)) > 0) {
|
|
if (line[linelen - 1] == '\n') {
|
|
line[--linelen] = '\0';
|
|
}
|
|
isc_buffer_init(&buf, line, linelen);
|
|
isc_buffer_add(&buf, linelen);
|
|
|
|
if (count == ARRAY_SIZE(fixedname)) {
|
|
errx(1, "too many names");
|
|
}
|
|
dns_name_t *name = dns_fixedname_initname(&fixedname[count++]);
|
|
result = dns_name_fromtext(name, &buf, dns_rootname, 0);
|
|
CHECKRESULT(result, line);
|
|
}
|
|
|
|
unsigned int repeat = 100;
|
|
|
|
isc_time_t start;
|
|
start = isc_time_now_hires();
|
|
|
|
for (unsigned int n = 0; n < repeat; n++) {
|
|
static uint8_t wire[4 * 1024];
|
|
dns_compress_t cctx;
|
|
|
|
isc_buffer_init(&buf, wire, sizeof(wire));
|
|
dns_compress_init(&cctx, isc_g_mctx, 0);
|
|
|
|
for (unsigned int i = 0; i < count; i++) {
|
|
dns_name_t *name = dns_fixedname_name(&fixedname[i]);
|
|
result = dns_name_towire(name, &cctx, &buf);
|
|
if (result == ISC_R_NOSPACE) {
|
|
dns_compress_invalidate(&cctx);
|
|
dns_compress_init(&cctx, isc_g_mctx, 0);
|
|
isc_buffer_init(&buf, wire, sizeof(wire));
|
|
} else {
|
|
CHECKRESULT(result, "dns_name_towire");
|
|
}
|
|
}
|
|
dns_compress_invalidate(&cctx);
|
|
}
|
|
|
|
isc_time_t finish;
|
|
finish = isc_time_now_hires();
|
|
|
|
uint64_t microseconds = isc_time_microdiff(&finish, &start);
|
|
printf("time %f / %u\n", (double)microseconds / 1000000.0, repeat);
|
|
|
|
printf("names %u\n", count);
|
|
|
|
return 0;
|
|
}
|