protocol_entry (unsigned char type, gpointer data, int size)
{
int index;
+ gboolean include_worker_index = type != PROTOCOL_ID (binary_protocol_header);
+ int entry_size = size + 1 + (include_worker_index ? 1 : 0); // type + worker_index + size
BinaryProtocolBuffer *buffer;
if (binary_protocol_file == invalid_file_value)
return;
- if (sgen_thread_pool_is_thread_pool_thread (mono_native_thread_id_get ()))
- type |= 0x80;
-
lock_recursive ();
retry:
buffer = binary_protocol_get_buffer (size + 1);
retry_same_buffer:
index = buffer->index;
- if (index + 1 + size > BINARY_PROTOCOL_BUFFER_SIZE)
+ if (index + entry_size > BINARY_PROTOCOL_BUFFER_SIZE)
goto retry;
- if (InterlockedCompareExchange (&buffer->index, index + 1 + size, index) != index)
+ if (InterlockedCompareExchange (&buffer->index, index + entry_size, index) != index)
goto retry_same_buffer;
/* FIXME: if we're interrupted at this point, we have a buffer
entry that contains random data. */
buffer->buffer [index++] = type;
+ /* We should never change the header format */
+ if (include_worker_index) {
+ /*
+ * If the thread is not a worker thread we insert 0, which is interpreted
+ * as gc thread. Worker indexes are 1 based.
+ */
+ buffer->buffer [index++] = (unsigned char) sgen_thread_pool_is_thread_pool_thread (mono_native_thread_id_get ());
+ }
memcpy (buffer->buffer + index, data, size);
index += size;
#include "sgen-entry-stream.h"
#include "sgen-grep-binprot.h"
+static int file_version = 0;
+
#ifdef BINPROT_HAS_HEADER
#define PACKED_SUFFIX p
#else
#define MAX_ENTRY_SIZE (1 << 10)
static int
-read_entry (EntryStream *stream, void *data)
+read_entry (EntryStream *stream, void *data, unsigned char *windex)
{
unsigned char type;
ssize_t size;
if (read_stream (stream, &type, 1) <= 0)
return SGEN_PROTOCOL_EOF;
+
+ if (windex) {
+ if (file_version >= 2) {
+ if (read_stream (stream, windex, 1) <= 0)
+ return SGEN_PROTOCOL_EOF;
+ } else {
+ *windex = !!(WORKER (type));
+ }
+ }
+
switch (TYPE (type)) {
#define BEGIN_PROTOCOL_ENTRY0(method) \
}
}
-#define WORKER_PREFIX(t) (WORKER ((t)) ? "w" : " ")
-
enum { NO_COLOR = -1 };
typedef struct {
}
static void
-print_entry (int type, void *data, int num_nums, int *match_indices, gboolean color_output)
+print_entry (int type, void *data, int num_nums, int *match_indices, gboolean color_output, unsigned char worker_index)
{
const char *always_prefix = is_always_match (type) ? " " : "";
- printf ("%s%s ", WORKER_PREFIX (type), always_prefix);
+ if (worker_index)
+ printf ("w%-2d%s ", worker_index, always_prefix);
+ else
+ printf (" %s ", always_prefix);
switch (TYPE (type)) {
{
#ifdef BINPROT_HAS_HEADER
char data [MAX_ENTRY_SIZE];
- int type = read_entry (stream, data);
+ int type = read_entry (stream, data, NULL);
if (type == SGEN_PROTOCOL_EOF)
return FALSE;
if (type == PROTOCOL_ID (binary_protocol_header)) {
fprintf (stderr, "The file contains a newer version %d. We support up to %d. Please update.\n", str->version, PROTOCOL_HEADER_VERSION);
exit (1);
}
+ file_version = str->version;
return TRUE;
}
}
gboolean dump_all, gboolean pause_times, gboolean color_output, unsigned long long first_entry_to_consider)
{
int type;
+ unsigned char worker_index;
void *data = g_malloc0 (MAX_ENTRY_SIZE);
int i;
gboolean pause_times_stopped = FALSE;
return FALSE;
entry_index = 0;
- while ((type = read_entry (stream, data)) != SGEN_PROTOCOL_EOF) {
+ while ((type = read_entry (stream, data, &worker_index)) != SGEN_PROTOCOL_EOF) {
if (entry_index < first_entry_to_consider)
goto next_entry;
if (pause_times) {
if (dump_all)
printf (match ? "* " : " ");
if (match || dump_all)
- print_entry (type, data, num_nums, match_indices, color_output);
+ print_entry (type, data, num_nums, match_indices, color_output, worker_index);
}
next_entry:
++entry_index;