From: Pierre-Marc Fournier Date: Tue, 7 Apr 2009 01:00:50 +0000 (-0400) Subject: ustd: use commit_seq to get buffers from crashed process X-Git-Tag: v1.9.1~1010 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=53107b8f0fcc8f46a12f926b37a6a87eeccac887;p=lttng-ust.git ustd: use commit_seq to get buffers from crashed process it works! --- diff --git a/ustd/lowlevel.c b/ustd/lowlevel.c index f386089e..7c5dc3d9 100644 --- a/ustd/lowlevel.c +++ b/ustd/lowlevel.c @@ -1,3 +1,5 @@ +#include + #include "tracer.h" #include "ustd.h" #include "localerr.h" @@ -18,8 +20,8 @@ void finish_consuming_dead_subbuffer(struct buffer_info *buf) DBG("consumed offset is %ld", consumed_offset); DBG("write offset is %ld", write_offset); - long first_subbuf = write_offset / buf->subbuf_size; - long last_subbuf = consumed_offset / buf->subbuf_size; + long first_subbuf = consumed_offset / buf->subbuf_size; + long last_subbuf = write_offset / buf->subbuf_size; if(last_subbuf - first_subbuf > buf->n_subbufs) { DBG("an overflow has occurred, nothing can be recovered"); @@ -27,21 +29,38 @@ void finish_consuming_dead_subbuffer(struct buffer_info *buf) } for(i_subbuf=first_subbuf; ; i_subbuf++, i_subbuf %= buf->n_subbufs) { - long commit_count = local_read(<t_buf->commit_count[i_subbuf]); + void *tmp; + long commit_seq = local_read(<t_buf->commit_seq[i_subbuf]); unsigned long valid_length = buf->subbuf_size; long n_subbufs_order = get_count_order(buf->n_subbufs); - long commit_count_mask = (~0UL >> n_subbufs_order); + long commit_seq_mask = (~0UL >> n_subbufs_order); + + if((commit_seq & commit_seq_mask) == 0) + break; /* check if subbuf was fully written */ - if (((commit_count - buf->subbuf_size) & commit_count_mask) + if (!((commit_seq - buf->subbuf_size) & commit_seq_mask) - (USTD_BUFFER_TRUNC(consumed_offset, buf) >> n_subbufs_order) != 0) { struct ltt_subbuffer_header *header = (struct ltt_subbuffer_header *)((char *)buf->mem)+i_subbuf*buf->subbuf_size; - valid_length = buf->subbuf_size - header->lost_size; + valid_length = (unsigned long)buf->subbuf_size - header->lost_size; } + else { + struct ltt_subbuffer_header *header = (struct ltt_subbuffer_header *)((char *)buf->mem)+i_subbuf*buf->subbuf_size; + + valid_length = commit_seq; + header->lost_size = buf->subbuf_size-valid_length; + assert(i_subbuf == last_subbuf); + } + + patient_write(buf->file_fd, buf->mem + i_subbuf * buf->subbuf_size, valid_length); - patient_write(buf->file_fd, buf->mem + i_subbuf * buf->subbuf_size, buf->subbuf_size); + /* pad with empty bytes */ + tmp = malloc(buf->subbuf_size-valid_length); + memset(tmp, 0, buf->subbuf_size-valid_length); + patient_write(buf->file_fd, tmp, buf->subbuf_size-valid_length); + free(tmp); if(i_subbuf == last_subbuf) break;