105 lines
4.8 KiB
C++
105 lines
4.8 KiB
C++
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <assert.h>
|
|
#include <stdint.h>
|
|
|
|
#include "fieldstat/fieldstat_easy.h"
|
|
#include "stellar/stellar.h"
|
|
#include <stellar/session_mq.h>
|
|
|
|
#include "dns_decoder.h"
|
|
#include "dns_decoder_perf_dummy.h"
|
|
|
|
struct dns_decoder_context;
|
|
struct dns_decoder_plugin_env;
|
|
|
|
enum PERF_TAG
|
|
{
|
|
PERF_TAG_QUESTION,
|
|
PERF_TAG_RESOURCE_RECORD,
|
|
PERF_TAG_MAX
|
|
};
|
|
|
|
struct perf_main_env
|
|
{
|
|
int worker_thread_num;
|
|
int fs_id[PERF_TAG_MAX];
|
|
struct fieldstat_tag fs_tag[PERF_TAG_MAX];
|
|
struct session *ss;
|
|
};
|
|
|
|
// form dns_decoder_test.cpp
|
|
extern "C" void *dns_decoder_test_init(struct stellar *st);
|
|
extern "C" void *dns_decoder_init(struct stellar *st);
|
|
|
|
void perf_resource_record_decode()
|
|
{
|
|
|
|
}
|
|
|
|
static void main_stat_init(struct perf_main_env *main_env)
|
|
{
|
|
struct fieldstat_easy *fs4_instance=fieldstat_easy_new(1, "dns_decoder_perf_test", NULL, 0);
|
|
fieldstat_easy_enable_auto_output(fs4_instance, "./metrics/dns_decoder_perf_test.json", 1);
|
|
|
|
main_env->fs_tag[PERF_TAG_QUESTION].key="question";
|
|
main_env->fs_tag[PERF_TAG_QUESTION].type=TAG_DOUBLE;
|
|
main_env->fs_tag[PERF_TAG_QUESTION].value_double=0.00001;
|
|
main_env->fs_id[PERF_TAG_QUESTION]=fieldstat_easy_register_histogram(fs4_instance, "question", 1, 99999999, 5);
|
|
|
|
main_env->fs_tag[PERF_TAG_RESOURCE_RECORD].key="resource_record";
|
|
main_env->fs_tag[PERF_TAG_RESOURCE_RECORD].type=TAG_DOUBLE;
|
|
main_env->fs_tag[PERF_TAG_RESOURCE_RECORD].value_double=0.00001;
|
|
main_env->fs_id[PERF_TAG_RESOURCE_RECORD]=fieldstat_easy_register_histogram(fs4_instance, "resource-record", 1, 99999999, 5);
|
|
}
|
|
|
|
size_t hex_string_to_byte_array(const char *hex_str, size_t hex_str_sz, unsigned char *byte_array, size_t byte_array_sz)
|
|
{
|
|
size_t offset=0;
|
|
for(size_t i=0; i<hex_str_sz; i+=2)
|
|
{
|
|
sscanf(hex_str+i, "%2hhx", &byte_array[offset++]);
|
|
|
|
}
|
|
|
|
return offset;
|
|
}
|
|
|
|
int main(int argc, char *argv[])
|
|
{
|
|
struct perf_main_env *main_env=(struct perf_main_env *)calloc(1, sizeof(struct perf_main_env));
|
|
|
|
main_stat_init(main_env);
|
|
struct stellar *main_st=stellar_init(main_env->worker_thread_num);
|
|
|
|
struct stellar_packet *response=(struct stellar_packet *)calloc(1, sizeof(struct stellar_packet));
|
|
|
|
const char *response_hex_str="ce268000000100000006001404646174610862696c6963646e3203636f6d0000410001c011000200010002a300000c036e733305646e737635c01ac011000200010002a3000006036e7334c03320434b30504f4a4d473837344c4a5245463745464e38343330515649543842534dc01a003200010001518000230101000000146501a0c25720ee156f6c4e39636b3ada0312d92a000722000000000290c04d002e00010001518000b700320802000151806188b454617f5b5c3cbd03636f6d001f77dc4c5796eda9ced317925c67d91c52922152424c9dca024948c1169e8429053fdf50a23370d9c3dc79de909f2f79475b2c731d6060d1db7b5d294b8ee43c91a57b8a4afa06c25fb13127bfca3fb353c7d5a38eaf093e12ffa1e33bc80bd7118851ca730ed22bd27b6f16673b86b44898785c6e13b3dd3620750492e47bb8ca823ffa6e25225ffa5408184c25e4ff423497802deed0586629d78103b3e6e72039454d4644425347524c48514f4d4736515441534e534c4151343438454b4644c01a003200010001518000220101000000144bad0970b67bda0a716dcd12979d4451b22f7ac50006200000000012c160002e00010001518000b700320802000151806188bdde617f64e63cbd03636f6d00a9de4aee30c79978429e76969d02d2bd4c8942f1b4329a643e9d7703e9fd46dd9ab32c4feffe1f9fbed3418e40d42a00fe2c1c2cac66e1c718bf508c4f603171f9ea18e8e79a533d136c26907576ab033dc48e4ff3b355346c33ac54a359c9572c308c923f910e470315dd4de40bd3b443b7caa34309b22146dca1ed6f4758a476052fc8a33829216c5abe88f21981dfe8ae9b2b204958aac575bfaa9847af3ec02f000100010002a300000481d3b0d4c02f000100010002a3000004a20e12bcc02f000100010002a3000004a20e18fbc02f000100010002a3000004a20e19fbc02f000100010002a300000412c20289c02f000100010002a3000004b7c0c95ec02f000100010002a3000004dfa69710c02f001c00010002a300001024024e0014301102000091362b2bba61c02f000100010002a3000004344dee5cc02f000100010002a30000043d97b433c047000100010002a300000465e2dc0cc047000100010002a300000481d3b097c047000100010002a3000004a20e18f8c047000100010002a3000004a20e19f8c047000100010002a3000004b7c0a477c047000100010002a3000004dfa6977ec047001c00010002a300001024024e00102012640000913629b6fc32c047000100010002a300000434c69f92c047000100010002a30000043b2478930000291000000080000000";
|
|
response->payload_sz=hex_string_to_byte_array(response_hex_str, strlen(response_hex_str), response->payload, sizeof(response->payload));
|
|
printf("query.payload_sz=%zu\n", response->payload_sz);
|
|
|
|
for(size_t i=0; i<response->payload_sz; i++)
|
|
{
|
|
printf("%02x ", response->payload[i]);
|
|
if(i>0 && (i%16==0))
|
|
{
|
|
printf("\n");
|
|
}
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
while(1)
|
|
{
|
|
for(int i=0; i<main_env->worker_thread_num; i++)
|
|
{
|
|
struct session *ss=stellar_session_new(main_st, i);
|
|
session_mq_publish_message_by_name(ss, DNS_MESSAGE_TOPIC, response);
|
|
stellar_session_free(ss);
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
} |