1 #include "babeltrace/ctf/types.h"
2 #include "babeltrace/ctf/metadata.h"
4 void ctf_move_mmap_pos_slow(struct ctf_stream_pos
*pos
, size_t offset
, int whence
)
6 struct ctf_file_stream
*file_stream
=
7 container_of(pos
, struct ctf_file_stream
, pos
);
10 struct packet_index
*index
;
12 struct mmap_stream
*iter
, *tmp
;
13 struct mmap_stream tmp_snapshot
;
15 /* first time we have to mmap the region */
16 if (pos
->mmap_len
== 0) {
17 /* get the len of the mmap region */
18 ret
= kernctl_get_mmap_len(pos
->fd
, &pos
->mmap_len
);
21 perror("kernctl_get_mmap_len");
24 pos
->mmap_real_base
= mmap(NULL
, pos
->mmap_len
, PROT_READ
, MAP_PRIVATE
, pos
->fd
, 0);
25 if (pos
->mmap_real_base
== MAP_FAILED
) {
26 perror("Error mmaping");
32 /* FIXME : put_subbuf should work but fails after nb_subbuf get + put */
33 ret
= kernctl_put_next_subbuf(pos
->fd
);
36 perror("kernctl_put_subbuf");
42 tmp_snapshot
.kconsumerd_fd
= 0;
43 for (i
= 0; i
< available_snapshots
->len
; i
++) {
44 tmp
= g_ptr_array_index(available_snapshots
, 0);
45 if (tmp
->kconsumerd_fd
->wait_fd
== pos
->fd
) {
46 tmp_snapshot
.last_pos
= tmp
->last_pos
;
47 tmp_snapshot
.kconsumerd_fd
= tmp
->kconsumerd_fd
;
48 g_ptr_array_remove_index(available_snapshots
, i
);
53 if (tmp_snapshot
.kconsumerd_fd
== 0) {
57 // fprintf(stderr,"READING FROM SNAPSHOT ON FD %d at %lu\n",
58 // tmp_snapshot.kconsumerd_fd->wait_fd, tmp_snapshot.last_pos);
59 ret
= kernctl_get_subbuf(tmp_snapshot
.kconsumerd_fd
->wait_fd
, &tmp_snapshot
.last_pos
);
62 perror("kernctl_get_subbuf");
66 ret
= kernctl_get_mmap_read_offset(pos
->fd
, &(pos
->mmap_offset
));
69 perror("kernctl_get_mmap_read_offset");
73 /* read only the data in the subbuffer */
74 err
= kernctl_get_subbuf_size(pos
->fd
, &pos
->content_size
);
77 perror("Getting sub-buffer len failed.");
81 pos
->content_size
*= CHAR_BIT
;
82 /* read the whole subbuffer */
83 err
= kernctl_get_padded_subbuf_size(pos
->fd
, &pos
->packet_size
);
86 perror("Getting sub-buffer len failed.");
90 pos
->packet_size
*= CHAR_BIT
;
92 pos
->offset
= 0; /* will read headers */
94 /* map new base. Need mapping length from header. */
95 pos
->base
= pos
->mmap_real_base
+ pos
->mmap_offset
;
97 /* update trace_packet_header and stream_packet_context */
98 if (pos
->prot
!= PROT_WRITE
&& file_stream
->parent
.trace_packet_header
) {
99 /* Read packet header */
100 ret
= generic_rw(&pos
->parent
, &file_stream
->parent
.trace_packet_header
->p
);
103 if (pos
->prot
!= PROT_WRITE
&& file_stream
->parent
.stream_packet_context
) {
104 /* Read packet context */
105 ret
= generic_rw(&pos
->parent
, &file_stream
->parent
.stream_packet_context
->p
);
109 /* read timestamp begin from header */
110 len_index
= struct_declaration_lookup_field_index(
111 file_stream
->parent
.stream_packet_context
->declaration
,
112 g_quark_from_static_string("timestamp_begin"));
113 if (len_index
>= 0) {
114 struct definition_integer
*defint
;
115 struct definition
*field
;
117 field
= struct_definition_get_field_from_index(
118 file_stream
->parent
.stream_packet_context
, len_index
);
119 assert(field
->declaration
->id
== CTF_TYPE_INTEGER
);
120 defint
= container_of(field
, struct definition_integer
, p
);
121 assert(defint
->declaration
->signedness
== FALSE
);
122 file_stream
->parent
.timestamp
= defint
->value
._unsigned
;
123 // fprintf(stderr, "READ TIMESTAMP : %lu\n", file_stream->parent.timestamp);
This page took 0.031233 seconds and 4 git commands to generate.