Exemple #1
0
bool ksmach_getThreadQueueName(const thread_t thread,
                               char* const buffer,
                               size_t bufLength)
{
    // WARNING: This implementation is no longer async-safe!

    integer_t infoBuffer[THREAD_IDENTIFIER_INFO_COUNT] = {0};
    thread_info_t info = infoBuffer;
    mach_msg_type_number_t inOutSize = THREAD_IDENTIFIER_INFO_COUNT;
    kern_return_t kr = 0;

    kr = thread_info(thread, THREAD_IDENTIFIER_INFO, info, &inOutSize);
    if(kr != KERN_SUCCESS)
    {
        KSLOG_TRACE("Error getting thread_info with flavor THREAD_IDENTIFIER_INFO from mach thread : %s", mach_error_string(kr));
        return false;
    }

    thread_identifier_info_t idInfo = (thread_identifier_info_t)info;
    dispatch_queue_t* dispatch_queue_ptr = (dispatch_queue_t*)idInfo->dispatch_qaddr;
    //thread_handle shouldn't be 0 also, because
    //identifier_info->dispatch_qaddr =  identifier_info->thread_handle + get_dispatchqueue_offset_from_proc(thread->task->bsd_info);
    if(dispatch_queue_ptr == NULL || idInfo->thread_handle == 0 || *dispatch_queue_ptr == NULL)
    {
        KSLOG_TRACE("This thread doesn't have a dispatch queue attached : %p", thread);
        return false;
    }

    dispatch_queue_t dispatch_queue = *dispatch_queue_ptr;
    const char* queue_name = dispatch_queue_get_label(dispatch_queue);
    if(queue_name == NULL)
    {
        KSLOG_TRACE("Error while getting dispatch queue name : %p", dispatch_queue);
        return false;
    }
    KSLOG_TRACE("Dispatch queue name: %s", queue_name);
    size_t length = strlen(queue_name);

    // Queue label must be a null terminated string.
    size_t iLabel;
    for(iLabel = 0; iLabel < length + 1; iLabel++)
    {
        if(queue_name[iLabel] < ' ' || queue_name[iLabel] > '~')
        {
            break;
        }
    }
    if(queue_name[iLabel] != 0)
    {
        // Found a non-null, invalid char.
        KSLOG_TRACE("Queue label contains invalid chars");
        return false;
    }
    bufLength = MIN(length, bufLength - 1);//just strlen, without null-terminator
    strncpy(buffer, queue_name, bufLength);
    buffer[bufLength] = 0;//terminate string
    KSLOG_TRACE("Queue label = %s", buffer);
    return true;
}
Exemple #2
0
__XDISPATCH_USE_NAMESPACE

queue::queue (
    dispatch_queue_t q
)
    : m_native( q ),
      m_label( dispatch_queue_get_label( q ) )
{
    XDISPATCH_ASSERT( m_native );
    dispatch_retain( m_native );
}
Exemple #3
0
static mrb_value
mrb_queue_to_s(mrb_state *mrb, mrb_value self)
{
  dispatch_queue_t q;
  const char *label_str;

  q = (dispatch_queue_t)DATA_PTR(self);
  label_str = dispatch_queue_get_label(q);

  return mrb_str_new_cstr(mrb, label_str);
}
Exemple #4
0
queue::queue (
    dispatch_queue_t q
)
    : object(),
      d( new data )
{
    XDISPATCH_ASSERT( d.get() );
    dispatch_retain( q );
    d->native = q;
    XDISPATCH_ASSERT( d->native );
    d->label = std::string( dispatch_queue_get_label( q ) );
}
Exemple #5
0
void hook_job_complete(void *code, double thread_time, double deadline, double prediction, double execution_time)
{
	(void)code;
	(void)thread_time;
	(void)deadline;
	(void)prediction;
	(void)execution_time;
	
	static double start_time = 0.0;
	static double previous_completion = 0.0;
	
	const char *label = dispatch_queue_get_label(DISPATCH_CURRENT_QUEUE_LABEL);
	
	if (label && strcmp(label, "refresh") == 0) {
		double time = atlas_now();
		if (start_time == 0.0)
			start_time = time;
		if (previous_completion > 0.0)
			printf("%lf %lf\n", time - start_time, time - previous_completion);
		previous_completion = time;
	}
}
Exemple #6
0
static void
fd_tcpinfo_carbon_tick(void *arg)
{
	struct carbon_ctx *ctx = arg;
	dispatch_time_t milestone;
	struct tcp_info i = {0};
	struct tcp_info *info = &i;

	if (ctx->fd < 0) {
		printf("noconn\n");
		goto resched;
	}

	if (fd_tcpinfo(ctx->fd, info) == 0) {
		time_t ts;
		time(&ts);

		const char *qname = dispatch_queue_get_label(ctx->queue);
		char label[1024];

		snprintf(label, sizeof(label), "%s.rtt", qname);
		carbon_dispatch(ctx->queue, ctx->io, label, info->tcpi_rttcur, ts);

		snprintf(label, sizeof(label), "%s.rxpackets", qname);
		carbon_dispatch(ctx->queue, ctx->io, label, info->tcpi_rxpackets, ts);

		snprintf(label, sizeof(label), "%s.txpackets", qname);
		carbon_dispatch(ctx->queue, ctx->io, label, info->tcpi_txpackets, ts);

		printf("%s rtt: %u rxpackets: %llu txpackets: %llu\n", qname, info->tcpi_rttcur, info->tcpi_rxpackets, info->tcpi_txpackets);
	} else {
		perror("getsockopt");
	}

resched:
	milestone = dispatch_time(DISPATCH_TIME_NOW, T_TIMEOUT);
	dispatch_after_f(milestone, ctx->queue, ctx, fd_tcpinfo_carbon_tick);
}
Exemple #7
0
static VALUE 
rb_queue_label(VALUE self, SEL sel)
{
    return rb_str_new2(dispatch_queue_get_label(RQueue(self)->queue));
}