Commit b3e6d2f3 authored by Mikhail Karpenko's avatar Mikhail Karpenko

Start adding statistics collection, not finished yet

parent 03fde964
...@@ -49,8 +49,9 @@ ...@@ -49,8 +49,9 @@
struct dd_params { struct dd_params {
uint64_t pos_start; uint64_t pos_start;
unsigned long int block_size; unsigned long block_size;
unsigned long int block_count; unsigned long block_count;
unsigned long block_count_init;
}; };
enum sysfs_path_type { enum sysfs_path_type {
...@@ -88,6 +89,7 @@ static int find_state(FILE *f, uint64_t *pos, const rawdev_buffer *rawdev); ...@@ -88,6 +89,7 @@ static int find_state(FILE *f, uint64_t *pos, const rawdev_buffer *rawdev);
static int open_state_file(const rawdev_buffer *rawdev); static int open_state_file(const rawdev_buffer *rawdev);
static int save_state_file(const rawdev_buffer *rawdev); static int save_state_file(const rawdev_buffer *rawdev);
static int get_disk_range_from_driver(struct range *range); static int get_disk_range_from_driver(struct range *range);
static void read_stat(void);
void camogm_init(camogm_state *state, char *pipe_name, uint16_t port_num) void camogm_init(camogm_state *state, char *pipe_name, uint16_t port_num)
{ {
...@@ -166,6 +168,7 @@ int open_files(camogm_state *state) ...@@ -166,6 +168,7 @@ int open_files(camogm_state *state)
int sendImageFrame(camogm_state *state) int sendImageFrame(camogm_state *state)
{ {
int ret;
struct frame_data fdata = {0}; struct frame_data fdata = {0};
if (state->rawdev_op) { if (state->rawdev_op) {
...@@ -177,9 +180,10 @@ int sendImageFrame(camogm_state *state) ...@@ -177,9 +180,10 @@ int sendImageFrame(camogm_state *state)
fdata.cmd |= DRV_CMD_EXIF; fdata.cmd |= DRV_CMD_EXIF;
} }
fdata.cmd |= DRV_CMD_WRITE_TEST; fdata.cmd |= DRV_CMD_WRITE_TEST;
if (write(state->rawdev.sysfs_fd, &fdata, sizeof(struct frame_data)) < 0) { ret = write(state->rawdev.sysfs_fd, &fdata, sizeof(struct frame_data));
D0(fprintf(debug_file, "Can not pass IO vector to driver: %s\n", strerror(errno))); if (ret < 0) {
return -CAMOGM_FRAME_FILE_ERR; // D0(fprintf(debug_file, "Can not pass IO vector to driver (driver may be busy): %s\r", strerror(errno)));
return ret;
} }
} }
...@@ -474,6 +478,15 @@ static int save_state_file(const rawdev_buffer *rawdev) ...@@ -474,6 +478,15 @@ static int save_state_file(const rawdev_buffer *rawdev)
return ret; return ret;
} }
/** Read recent statistics from sysfs */
static void read_stat(void)
{
int fd;
const char *stat_delay_name = "stat_irq_delay";
}
unsigned int select_port(camogm_state *state) unsigned int select_port(camogm_state *state)
{ {
// do not process commands // do not process commands
...@@ -531,6 +544,7 @@ int listener_loop(camogm_state *state, struct dd_params *dd_params) ...@@ -531,6 +544,7 @@ int listener_loop(camogm_state *state, struct dd_params *dd_params)
int curr_port = 0; int curr_port = 0;
int retry_cntr = 0; int retry_cntr = 0;
int ret = 0; int ret = 0;
unsigned long mb_written;
// enter main processing loop // enter main processing loop
while (process) { while (process) {
...@@ -547,16 +561,21 @@ int listener_loop(camogm_state *state, struct dd_params *dd_params) ...@@ -547,16 +561,21 @@ int listener_loop(camogm_state *state, struct dd_params *dd_params)
// file sent OK // file sent OK
dd_params->block_count--; dd_params->block_count--;
break; break;
case CAMOGM_FRAME_FILE_ERR: case EAGAIN:
// we need to wait as the driver queue is full // we need to wait as the driver queue is full
usleep(COMMAND_LOOP_DELAY); // usleep(COMMAND_LOOP_DELAY);
break;
case EIO:
// new statistics sample is ready, read it
read_stat();
break; break;
default: default:
D0(fprintf(debug_file, "%s:line %d - should not get here (rslt=%d)\n", __FILE__, __LINE__, rslt)); D0(fprintf(debug_file, "%s:line %d - should not get here (rslt=%d)\n", __FILE__, __LINE__, rslt));
clean_up(state); clean_up(state);
exit(-1); exit(-1);
} // switch sendImageFrame() } // switch sendImageFrame()
D0(fprintf(debug_file, "Number of counts left: %lu\n", dd_params->block_count)); mb_written = ((uint64_t)dd_params->block_size * ((uint64_t)dd_params->block_count_init - (uint64_t)dd_params->block_count)) / (uint64_t)1048576;
D0(fprintf(debug_file, "\r%lu MiB written, number of counts left: %04lu", mb_written, dd_params->block_count));
} else { } else {
process = 0; process = 0;
} }
...@@ -564,6 +583,7 @@ int listener_loop(camogm_state *state, struct dd_params *dd_params) ...@@ -564,6 +583,7 @@ int listener_loop(camogm_state *state, struct dd_params *dd_params)
usleep(COMMAND_LOOP_DELAY); // make it longer but interruptible by signals? usleep(COMMAND_LOOP_DELAY); // make it longer but interruptible by signals?
} }
} // while (process) } // while (process)
D0(fprintf(debug_file, "\n"));
return ret; return ret;
} }
...@@ -627,6 +647,7 @@ int main(int argc, char *argv[]) ...@@ -627,6 +647,7 @@ int main(int argc, char *argv[])
break; break;
case 'c': case 'c':
dd_params.block_count = strtoul((const char *)optarg, (char **)NULL, 10); dd_params.block_count = strtoul((const char *)optarg, (char **)NULL, 10);
dd_params.block_count_init = dd_params.block_count;
if (errno != 0) { if (errno != 0) {
printf("error parsing block size value: %s\n", strerror(errno)); printf("error parsing block size value: %s\n", strerror(errno));
return EXIT_FAILURE; return EXIT_FAILURE;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment