modify test data add fluc and plt
This commit is contained in:
@@ -40,6 +40,11 @@ using namespace std;
|
||||
#include "../log4cplus/log4.h"//lnk添加log4
|
||||
#include <cstring>
|
||||
|
||||
//用于测试时防止数据激增
|
||||
#ifndef apr_time_from_msec
|
||||
#define apr_time_from_msec(ms) ((apr_time_t)(ms) * 1000)
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
@@ -6058,142 +6063,173 @@ void rocketmq_test_300(int mpnum,int front_index,int type) {
|
||||
data.mp_id = "0";
|
||||
|
||||
// 读取文件内容
|
||||
std::ifstream file("long_string.txt"); // 文件中存储长字符串
|
||||
std::stringstream buffer;
|
||||
buffer << file.rdbuf();
|
||||
std::string file_contents = buffer.str(); // 获取文件内容
|
||||
std::string base_strText = file_contents;
|
||||
//std::ifstream file("long_string.txt"); // 文件中存储长字符串
|
||||
std::vector<std::string> filenames;
|
||||
filenames.push_back("long_string.txt");
|
||||
filenames.push_back("PLT_string.txt");
|
||||
filenames.push_back("fluc_string.txt");
|
||||
filenames.push_back("qvvr_string.txt");
|
||||
|
||||
// 获取当前时间作为开始时间
|
||||
std::time_t t = std::time(NULL);//获取当前的系统时间(自 1970 年 1 月 1 日以来的秒数,通常称为 UNIX 时间戳)
|
||||
std::tm* time_info = std::localtime(&t);//将 std::time_t(表示当前的 UNIX 时间戳)转换为本地时间(std::tm 结构)
|
||||
time_info->tm_sec = 0; // 清零秒位
|
||||
//time_info->tm_msec = 0; // 清零毫秒位(如果需要更精确,使用高精度时间)
|
||||
for (std::vector<std::string>::iterator it = filenames.begin(); it != filenames.end(); ++it) {
|
||||
const std::string& filename = *it;
|
||||
std::ifstream file(filename.c_str());
|
||||
if (!file.is_open()) {
|
||||
std::cerr << "跳过无法打开的文件: " << filename << std::endl;
|
||||
continue;
|
||||
}
|
||||
|
||||
// 获取当前的时间戳(秒)
|
||||
std::time_t base_time_t = std::mktime(time_info);//将 std::tm 结构(本地时间)转换回 std::time_t(时间戳)
|
||||
std::stringstream buffer;
|
||||
buffer << file.rdbuf();
|
||||
std::string file_contents = buffer.str(); // 获取文件内容
|
||||
std::string base_strText = file_contents;
|
||||
|
||||
// 计算每条消息的时间戳,精确到分钟,毫秒和秒清零
|
||||
long long current_time_ms = static_cast<long long>(base_time_t) * 1000; // 每分钟递增,单位毫秒
|
||||
// 获取当前时间作为开始时间
|
||||
std::time_t t = std::time(NULL);//获取当前的系统时间(自 1970 年 1 月 1 日以来的秒数,通常称为 UNIX 时间戳)
|
||||
std::tm* time_info = std::localtime(&t);//将 std::time_t(表示当前的 UNIX 时间戳)转换为本地时间(std::tm 结构)
|
||||
time_info->tm_sec = 0; // 清零秒位
|
||||
//time_info->tm_msec = 0; // 清零毫秒位(如果需要更精确,使用高精度时间)
|
||||
|
||||
// 设定总的消息数量
|
||||
int total_messages = mpnum;
|
||||
// 获取当前的时间戳(秒)
|
||||
std::time_t base_time_t = std::mktime(time_info);//将 std::tm 结构(本地时间)转换回 std::time_t(时间戳)
|
||||
|
||||
ied_t* ied;
|
||||
ied_usr_t* ied_usr;
|
||||
// 计算每条消息的时间戳,精确到分钟,毫秒和秒清零
|
||||
long long current_time_ms = static_cast<long long>(base_time_t) * 1000; // 每分钟递增,单位毫秒
|
||||
|
||||
// 循环发送 300 条消息
|
||||
if(type == 0){
|
||||
std::cout << " use ledger send msg " << std::endl;
|
||||
for (int i = 0; (total_messages != 0 && g_front_seg_index == 1 && g_node_id == 100) && i < g_node->n_clients; ++i) {
|
||||
// 设定总的消息数量
|
||||
int total_messages = mpnum;
|
||||
|
||||
ied = (ied_t*)g_node->clients[i];
|
||||
if(ied != NULL){
|
||||
ied_usr = (ied_usr_t*)ied->usr_ext;
|
||||
ied_t* ied;
|
||||
ied_usr_t* ied_usr;
|
||||
|
||||
//跳过正常的终端
|
||||
if (shouldSkipTerminal(ied_usr->terminal_id)) {
|
||||
std::cout << ied_usr->terminal_id << " use true message " << std::endl;
|
||||
continue;
|
||||
// 循环发送 300 条消息
|
||||
if(type == 0){
|
||||
std::cout << " use ledger send msg " << std::endl;
|
||||
for (int i = 0; (total_messages > 0 && g_front_seg_index == 1 && g_node_id == 100) && i < g_node->n_clients; ++i) {
|
||||
|
||||
ied = (ied_t*)g_node->clients[i];
|
||||
if(ied != NULL){
|
||||
ied_usr = (ied_usr_t*)ied->usr_ext;
|
||||
|
||||
//跳过正常的终端
|
||||
if (shouldSkipTerminal(ied_usr->terminal_id)) {
|
||||
std::cout << ied_usr->terminal_id << " use true message " << std::endl;
|
||||
continue;
|
||||
}
|
||||
|
||||
for (int j = 0; j < 10 && ied_usr->LD_info[j].mp_id[0] != '\0'; j++){
|
||||
// 修改 Monitor 值
|
||||
char monitor_id[256] = {};
|
||||
strncpy(monitor_id, ied_usr->LD_info[j].mp_id, sizeof(monitor_id) - 1);
|
||||
monitor_id[sizeof(monitor_id) - 1] = '\0';
|
||||
|
||||
data.mp_id = QString(monitor_id);
|
||||
|
||||
data.monitor_id = i + j;
|
||||
|
||||
std::string modified_time = my_to_string(current_time_ms); // 时间转换为整数类型(Unix时间戳)
|
||||
|
||||
// 替换消息中的 Monitor 和 TIME 字段(只匹配字段名,不匹配具体数值)
|
||||
std::string modified_strText = base_strText;
|
||||
|
||||
// 替换 Monitor 字段
|
||||
size_t monitor_pos = modified_strText.find("\"Monitor\"");
|
||||
if (monitor_pos != std::string::npos) {
|
||||
size_t colon_pos = modified_strText.find(":", monitor_pos);
|
||||
size_t quote_pos = modified_strText.find("\"", colon_pos);
|
||||
size_t end_quote_pos = modified_strText.find("\"", quote_pos + 1);
|
||||
if (colon_pos != std::string::npos && quote_pos != std::string::npos && end_quote_pos != std::string::npos) {
|
||||
modified_strText.replace(quote_pos + 1, end_quote_pos - quote_pos - 1, data.mp_id.toStdString());
|
||||
}
|
||||
}
|
||||
|
||||
// 替换 TIME 字段
|
||||
size_t time_pos = modified_strText.find("\"TIME\"");
|
||||
if (time_pos != std::string::npos) {
|
||||
size_t colon_pos = modified_strText.find(":", time_pos);
|
||||
size_t quote_pos = colon_pos;
|
||||
size_t end_quote_pos = modified_strText.find(",", quote_pos + 1);
|
||||
if (colon_pos != std::string::npos && quote_pos != std::string::npos && end_quote_pos != std::string::npos) {
|
||||
modified_strText.replace(quote_pos + 1, end_quote_pos - quote_pos - 1, modified_time);
|
||||
}
|
||||
}
|
||||
|
||||
// 更新数据
|
||||
data.strText = QString::fromStdString(modified_strText);
|
||||
|
||||
// 发送数据
|
||||
my_rocketmq_send(data);
|
||||
|
||||
// 输出调试信息
|
||||
std::cout << "Sent message " << (i + 1) << " with Monitor " << data.monitor_id << " and TIME " << modified_time << std::endl;
|
||||
|
||||
/*int sleeptime = 6000/total_messages;//终端为单位
|
||||
if(sleeptime > 50){
|
||||
apr_sleep(apr_time_from_msec(50)); // 添加毫秒延时
|
||||
}
|
||||
else{
|
||||
apr_sleep(apr_time_from_msec(6000/total_messages)); // 添加毫秒延时
|
||||
}*/
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else{
|
||||
std::cout << " use monitor + number send msg " << std::endl;
|
||||
|
||||
for (int i = 0; (total_messages > 0 && g_front_seg_index == 1 && g_node_id == 100) && i < total_messages; ++i) {
|
||||
|
||||
// 修改 Monitor 值
|
||||
char monitor_id[256] = {};
|
||||
snprintf(monitor_id, sizeof(monitor_id), "testmonitor%05d", i);
|
||||
|
||||
monitor_id[sizeof(monitor_id) - 1] = '\0';
|
||||
data.mp_id = QString(monitor_id);
|
||||
data.monitor_id = i;
|
||||
|
||||
std::string modified_time = my_to_string(current_time_ms); // 时间转换为整数类型(Unix时间戳)
|
||||
// 替换消息中的 Monitor 和 TIME 字段(只匹配字段名,不匹配具体数值)
|
||||
std::string modified_strText = base_strText;
|
||||
// 替换 Monitor 字段
|
||||
size_t monitor_pos = modified_strText.find("\"Monitor\"");
|
||||
if (monitor_pos != std::string::npos) {
|
||||
size_t colon_pos = modified_strText.find(":", monitor_pos);
|
||||
size_t quote_pos = modified_strText.find("\"", colon_pos);
|
||||
size_t end_quote_pos = modified_strText.find("\"", quote_pos + 1);
|
||||
if (colon_pos != std::string::npos && quote_pos != std::string::npos && end_quote_pos != std::string::npos) {
|
||||
modified_strText.replace(quote_pos + 1, end_quote_pos - quote_pos - 1, data.mp_id.toStdString());
|
||||
}
|
||||
}
|
||||
// 替换 TIME 字段
|
||||
size_t time_pos = modified_strText.find("\"TIME\"");
|
||||
if (time_pos != std::string::npos) {
|
||||
size_t colon_pos = modified_strText.find(":", time_pos);
|
||||
size_t quote_pos = colon_pos;
|
||||
size_t end_quote_pos = modified_strText.find(",", quote_pos + 1);
|
||||
if (colon_pos != std::string::npos && quote_pos != std::string::npos && end_quote_pos != std::string::npos) {
|
||||
modified_strText.replace(quote_pos + 1, end_quote_pos - quote_pos - 1, modified_time);
|
||||
}
|
||||
}
|
||||
// 更新数据
|
||||
data.strText = QString::fromStdString(modified_strText);
|
||||
// 发送数据
|
||||
my_rocketmq_send(data);
|
||||
// 输出调试信息
|
||||
std::cout << "Sent message " << (i + 1) << " with Monitor " << data.monitor_id << " and TIME " << modified_time << std::endl;
|
||||
|
||||
/*int sleeptime = 60000/total_messages;//监测点为单位
|
||||
if(sleeptime > 50){
|
||||
apr_sleep(apr_time_from_msec(50)); // 添加毫秒延时
|
||||
}
|
||||
else{
|
||||
apr_sleep(apr_time_from_msec(60000/total_messages)); // 添加毫秒延时
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
for (int j = 0; j < 10 && ied_usr->LD_info[j].mp_id[0] != '\0'; j++){
|
||||
// 修改 Monitor 值
|
||||
char monitor_id[256] = {};
|
||||
strncpy(monitor_id, ied_usr->LD_info[j].mp_id, sizeof(monitor_id) - 1);
|
||||
monitor_id[sizeof(monitor_id) - 1] = '\0';
|
||||
|
||||
data.mp_id = QString(monitor_id);
|
||||
|
||||
data.monitor_id = i + j;
|
||||
|
||||
std::string modified_time = my_to_string(current_time_ms); // 时间转换为整数类型(Unix时间戳)
|
||||
|
||||
// 替换消息中的 Monitor 和 TIME 字段(只匹配字段名,不匹配具体数值)
|
||||
std::string modified_strText = base_strText;
|
||||
|
||||
// 替换 Monitor 字段
|
||||
size_t monitor_pos = modified_strText.find("\"Monitor\"");
|
||||
if (monitor_pos != std::string::npos) {
|
||||
size_t colon_pos = modified_strText.find(":", monitor_pos);
|
||||
size_t quote_pos = modified_strText.find("\"", colon_pos);
|
||||
size_t end_quote_pos = modified_strText.find("\"", quote_pos + 1);
|
||||
if (colon_pos != std::string::npos && quote_pos != std::string::npos && end_quote_pos != std::string::npos) {
|
||||
modified_strText.replace(quote_pos + 1, end_quote_pos - quote_pos - 1, data.mp_id.toStdString());
|
||||
}
|
||||
}
|
||||
|
||||
// 替换 TIME 字段
|
||||
size_t time_pos = modified_strText.find("\"TIME\"");
|
||||
if (time_pos != std::string::npos) {
|
||||
size_t colon_pos = modified_strText.find(":", time_pos);
|
||||
size_t quote_pos = colon_pos;
|
||||
size_t end_quote_pos = modified_strText.find(",", quote_pos + 1);
|
||||
if (colon_pos != std::string::npos && quote_pos != std::string::npos && end_quote_pos != std::string::npos) {
|
||||
modified_strText.replace(quote_pos + 1, end_quote_pos - quote_pos - 1, modified_time);
|
||||
}
|
||||
}
|
||||
|
||||
// 更新数据
|
||||
data.strText = QString::fromStdString(modified_strText);
|
||||
|
||||
// 发送数据
|
||||
my_rocketmq_send(data);
|
||||
|
||||
// 输出调试信息
|
||||
std::cout << "Sent message " << (i + 1) << " with Monitor " << data.monitor_id << " and TIME " << modified_time << std::endl;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else{
|
||||
std::cout << " use monitor + number send msg " << std::endl;
|
||||
|
||||
for (int i = 0; (total_messages != 0 && g_front_seg_index == 1 && g_node_id == 100) && i < total_messages; ++i) {
|
||||
|
||||
// 修改 Monitor 值
|
||||
char monitor_id[256] = {};
|
||||
snprintf(monitor_id, sizeof(monitor_id), "testmonitor%05d", i);
|
||||
|
||||
monitor_id[sizeof(monitor_id) - 1] = '\0';
|
||||
data.mp_id = QString(monitor_id);
|
||||
data.monitor_id = i;
|
||||
|
||||
std::string modified_time = my_to_string(current_time_ms); // 时间转换为整数类型(Unix时间戳)
|
||||
// 替换消息中的 Monitor 和 TIME 字段(只匹配字段名,不匹配具体数值)
|
||||
std::string modified_strText = base_strText;
|
||||
// 替换 Monitor 字段
|
||||
size_t monitor_pos = modified_strText.find("\"Monitor\"");
|
||||
if (monitor_pos != std::string::npos) {
|
||||
size_t colon_pos = modified_strText.find(":", monitor_pos);
|
||||
size_t quote_pos = modified_strText.find("\"", colon_pos);
|
||||
size_t end_quote_pos = modified_strText.find("\"", quote_pos + 1);
|
||||
if (colon_pos != std::string::npos && quote_pos != std::string::npos && end_quote_pos != std::string::npos) {
|
||||
modified_strText.replace(quote_pos + 1, end_quote_pos - quote_pos - 1, data.mp_id.toStdString());
|
||||
}
|
||||
}
|
||||
// 替换 TIME 字段
|
||||
size_t time_pos = modified_strText.find("\"TIME\"");
|
||||
if (time_pos != std::string::npos) {
|
||||
size_t colon_pos = modified_strText.find(":", time_pos);
|
||||
size_t quote_pos = colon_pos;
|
||||
size_t end_quote_pos = modified_strText.find(",", quote_pos + 1);
|
||||
if (colon_pos != std::string::npos && quote_pos != std::string::npos && end_quote_pos != std::string::npos) {
|
||||
modified_strText.replace(quote_pos + 1, end_quote_pos - quote_pos - 1, modified_time);
|
||||
}
|
||||
}
|
||||
// 更新数据
|
||||
data.strText = QString::fromStdString(modified_strText);
|
||||
// 发送数据
|
||||
my_rocketmq_send(data);
|
||||
// 输出调试信息
|
||||
std::cout << "Sent message " << (i + 1) << " with Monitor " << data.monitor_id << " and TIME " << modified_time << std::endl;
|
||||
|
||||
}
|
||||
std::cout << "Finished sending " << total_messages << " messages." << std::endl;
|
||||
}
|
||||
|
||||
std::cout << "Finished sending " << total_messages << " messages." << std::endl;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////lnk实时日志部分20250205
|
||||
|
||||
Reference in New Issue
Block a user