implemented cleanup of streams every 10 run. Now it works stable and fast. Next step -- adjust runs_since_streams_clean max value

This commit is contained in:
2025-11-14 02:03:37 +03:00
parent f0f8e4e6e6
commit c33ad367f3
2 changed files with 55 additions and 8 deletions

Binary file not shown.

59
main.c
View File

@ -695,6 +695,43 @@ void insert_marker_to_file(char* logfilename, char* marker_text){
}
void receive_to_file(t_x502_hnd hnd, char* logfilename, uint32_t* inp_buff, uint32_t max_total_words, uint32_t timeout){
// fprintf(logfile_ptr, "0xFF00000 \n");
// fprintf(logfile_ptr, "0xFFFFFFF \n");
// fprintf(logfile_ptr, "0xFF00000 \n");
// uint32_t timeout = 100;
uint32_t recv_Err_code = X502_Recv(hnd, inp_buff, max_total_words, timeout);
printf("receive code: %d\n", recv_Err_code);
if (recv_Err_code > 0){
char logfilename_tmp[300];
snprintf(logfilename_tmp, sizeof(logfilename_tmp), "%s.tmp", logfilename);
printf("tmp file: %s ",logfilename_tmp);
FILE* logfile_ptr = fopen(logfilename_tmp, "a");
//uint32_t recv_Err_code = X502_Recv(hnd, inp_buff, max_total_words, 20000);
uint32_t received_words = recv_Err_code;
for (uint32_t word_I = 0; word_I < received_words; word_I ++){
//printf("%06d 0x%08X\n", word_I, inp_buff[word_I]);
fprintf(logfile_ptr, "0x%08X \n", inp_buff[word_I]);
}
printf("received %ld words\n", received_words);
fclose(logfile_ptr);
rename(logfilename_tmp, logfilename);
}else if (recv_Err_code == 0){
printf("no data received. timeout\n");
}else{
printf("receive error: %d\n======================\n", recv_Err_code);
}
}
/*
void receive_to_file(t_x502_hnd hnd, char* logfilename, uint32_t* inp_buff, uint32_t max_total_words, uint32_t timeout){
char logfilename_tmp[300];
snprintf(logfilename_tmp, sizeof(logfilename_tmp), "%s.tmp", logfilename);
@ -723,7 +760,7 @@ void receive_to_file(t_x502_hnd hnd, char* logfilename, uint32_t* inp_buff, uint
rename(logfilename_tmp, logfilename);
}
*/
@ -864,6 +901,7 @@ int main(int argc, char** argv) {
struct timespec ts;
uint32_t max_total_words = 1000000;
uint32_t *inp_buff = malloc(1024*100*1024*2*4);
uint32_t runs_since_streams_clean = 0;
while(state.run_I < state.runs_N){
max_total_words = 10000000;
timespec_get(&ts, TIME_UTC);
@ -873,11 +911,13 @@ int main(int argc, char** argv) {
snprintf(tmp_data_filename, sizeof(tmp_data_filename), "%s/received_data_%ld.%ld.csv", state.data_path, ts.tv_sec, ts.tv_nsec);
printf("%u/%u dumping to file: %s\n", (unsigned)state.run_I, (unsigned)state.runs_N, tmp_data_filename);
receive_to_file(hnd, tmp_data_filename, inp_buff, max_total_words, state.run_length);
X502_StreamsStop(hnd);
X502_StreamsStart(hnd);
if (runs_since_streams_clean >= 10){
runs_since_streams_clean = 0;
X502_StreamsStop(hnd);
X502_StreamsStart(hnd);
}
state.run_I++;
}
runs_since_streams_clean++; }
free(inp_buff);
X502_Close(hnd);
// освобождаем описатель
@ -907,8 +947,9 @@ int main(int argc, char** argv) {
state.run_I = 0;
char tmp_data_filename[256];
struct timespec ts;
uint32_t max_total_words = 0;
uint32_t max_total_words = 10000000;
uint32_t *inp_buff = malloc(1024*100*1024*2*4);
uint32_t runs_since_streams_clean = 0;
while (1){ //should be infinite. because it is RUN_MODE_INF
//while(state.run_I < state.runs_N){
max_total_words = 10000000;
@ -919,7 +960,13 @@ int main(int argc, char** argv) {
snprintf(tmp_data_filename, sizeof(tmp_data_filename), "%s/received_data_%ld.%ld.csv", state.data_path, ts.tv_sec, ts.tv_nsec);
printf("%u dumping to file: %s\n", (unsigned)state.run_I, tmp_data_filename);
receive_to_file(hnd, tmp_data_filename, inp_buff, max_total_words, state.run_length);
if (runs_since_streams_clean >= 10){
runs_since_streams_clean = 0;
X502_StreamsStop(hnd);
X502_StreamsStart(hnd);
}
state.run_I++;
runs_since_streams_clean++;
}
free(inp_buff);
X502_Close(hnd);