Exemplo n.º 1
0
void LockStats<CounterType>::report(BSONObjBuilder* builder) const {
    // All indexing below starts from offset 1, because we do not want to report/account
    // position 0, which is a sentinel value for invalid resource/no lock.
    for (int i = 1; i < ResourceTypesCount; i++) {
        _report(builder, resourceTypeName(static_cast<ResourceType>(i)), _stats[i]);
    }

    _report(builder, "oplog", _oplogStats);
}
Exemplo n.º 2
0
static int
_cb(struct skynet_context * ctx, void * ud, int type, int session, uint32_t source, const void * msg, size_t sz) {
	struct gate *g = ud;
	if (type == PTYPE_TEXT) {
		_ctrl(ctx, g , msg , (int)sz);
		return 0;
	}
	assert(type == PTYPE_RESPONSE);
	struct mread_pool * m = g->pool;
	int connection_id = mread_poll(m,100);	// timeout : 100ms
	if (connection_id < 0) {
		skynet_command(ctx, "TIMEOUT", "1");
	} else {
		int id = g->map[connection_id].uid;
		if (id == 0) {
			id = _gen_id(g, connection_id);
			int fd = mread_socket(m , connection_id);
			struct sockaddr_in remote_addr;
			socklen_t len = sizeof(struct sockaddr_in);
			getpeername(fd, (struct sockaddr *)&remote_addr, &len);
			_report(g, ctx, "%d open %d %s:%u",id,fd,inet_ntoa(remote_addr.sin_addr),ntohs(remote_addr.sin_port));
		}
		uint8_t * plen = mread_pull(m,g->header_size);
		if (plen == NULL) {
			if (mread_closed(m)) {
				_remove_id(g,id);
				_report(g, ctx, "%d close", id);
			}
			goto _break;
		}
		// big-endian
		int len ;
		if (g->header_size == 2) {
			len = plen[0] << 8 | plen[1];
		} else {
			len = plen[0] << 24 | plen[1] << 16 | plen[2] << 8 | plen[3];
		}

		void * data = mread_pull(m, len);
		if (data == NULL) {
			if (mread_closed(m)) {
				_remove_id(g,id);
				_report(g, ctx, "%d close", id);
			}
			goto _break;
		}

		_forward(ctx, g, id, data, len);
		mread_yield(m);
_break:
		skynet_command(ctx, "TIMEOUT", "0");
	}
	return 0;
}
int isr_report (ISREPORT *rep)
{   /* --- report the current item set */
    int r = 0;                    /* number of reported item sets */
    int k;                        /* number of perfect extensions */
    int min, max;                 /* min. and max. item set size */

    assert(rep);                  /* check the function argument */
    if (rep->cnt > rep->max)      /* if the item set is too large, */
        return 0;                   /* abort the function */
    k   = (int)(rep->pxpp -rep->pexs);
    max = rep->cnt +k;            /* get number of perfect extensions */
    min = rep->min;               /* and check whether the minimum size */
    if (max < min) return 0;      /* can be reached with perfect exts. */
    if (rep->closed) {            /* if to report only closed item sets */
        if (max > rep->max) max = rep->max;
        if (max > rep->min) rep->min = max;
    }                             /* adapt the minimal item set size */
    if (rep->cnt >= rep->min)     /* if the item set is large enough, */
        r += _output(rep);          /* report and count it */
    if ((k > 0)                   /* if there are perfect extensions */
            &&  (rep->cnt < rep->max))    /* and maximum size not yet reached, */
        r += _report(rep, k);       /* recursively add and report them */
    rep->min  = min;              /* restore the minimum item set size */
    return r;                     /* return number of rep. item sets */
}  /* isr_report() */
Exemplo n.º 4
0
int pvs(struct cmd_context *cmd, int argc, char **argv)
{
	report_type_t type;

	if (arg_count(cmd, segments_ARG))
		type = PVSEGS;
	else
		type = PVS;

	return _report(cmd, argc, argv, type);
}
static int _report (ISREPORT *rep, int k)
{   /* --- recursively report item sets */
    int r = 0;                    /* counter for reported item sets */

    assert(rep && (k > 0));       /* check the function arguments */
    while (--k >= 0) {            /* traverse the perfect extensions */
        rep->items[rep->cnt++] = rep->pexs[k];
        if (rep->supps) rep->supps[rep->cnt] = rep->supps[rep->cnt-1];
        else            rep->sdbls[rep->cnt] = rep->sdbls[rep->cnt-1];
        if (rep->cnt >= rep->min)   /* if it has the req. min. size, */
            r += _output(rep);        /* report and count the item set */
        if ((k > 0)                 /* if another item can be added */
                &&  (rep->cnt +k >= rep->min)
                &&  (rep->cnt    <  rep->max))
            r += _report(rep, k);     /* recurse for remaining item sets */
        if (--rep->cnt < rep->pfx)  /* remove the current item again */
            rep->pfx = rep->cnt;      /* and adapt the valid prefix */
    }                             /* if necessary */
    return r;                     /* return number of rep. item sets */
}  /* _report() */
Exemplo n.º 6
0
static void
dispatch_socket_message(struct gate *g, const struct skynet_socket_message * message, int sz) {
	struct skynet_context * ctx = g->ctx;
	switch(message->type) {
	case SKYNET_SOCKET_TYPE_DATA: {
		int id = hashid_lookup(&g->hash, message->id);
		if (id>=0) {
			struct connection *c = &g->conn[id];
			dispatch_message(g, c, message->id, message->buffer, message->ud);
		} else {
			skynet_error(ctx, "Drop unknown connection %d message", message->id);
			skynet_socket_close(ctx, message->id);
			skynet_free(message->buffer);
		}
		break;
	}
	case SKYNET_SOCKET_TYPE_CONNECT: {
		if (message->id == g->listen_id) {
			// start listening
			break;
		}
		int id = hashid_lookup(&g->hash, message->id);
		if (id<0) {
			skynet_error(ctx, "Close unknown connection %d", message->id);
			skynet_socket_close(ctx, message->id);
		}
		break;
	}
	case SKYNET_SOCKET_TYPE_CLOSE:
	case SKYNET_SOCKET_TYPE_ERROR: {
		int id = hashid_remove(&g->hash, message->id);
		if (id>=0) {
			struct connection *c = &g->conn[id];
			databuffer_clear(&c->buffer,&g->mp);
			memset(c, 0, sizeof(*c));
			c->id = -1;
			_report(g, "%d close", message->id);
		}
		break;
	}
	case SKYNET_SOCKET_TYPE_ACCEPT:
		// report accept, then it will be get a SKYNET_SOCKET_TYPE_CONNECT message
		assert(g->listen_id == message->id);
		if (hashid_full(&g->hash)) {
			skynet_socket_close(ctx, message->ud);
		} else {
			struct connection *c = &g->conn[hashid_insert(&g->hash, message->ud)];
			if (sz >= sizeof(c->remote_name)) {
				sz = sizeof(c->remote_name) - 1;
			}
			c->id = message->ud;
			memcpy(c->remote_name, message+1, sz);
			c->remote_name[sz] = '\0';
			_report(g, "%d open %d %s:0",c->id, c->id, c->remote_name);
			skynet_error(ctx, "socket open: %x", c->id);
		}
		break;
	case SKYNET_SOCKET_TYPE_WARNING:
		skynet_error(ctx, "fd (%d) send buffer (%d)K", message->id, message->ud);
		break;
	}
}
Exemplo n.º 7
0
int vgs(struct cmd_context *cmd, int argc, char **argv)
{
	return _report(cmd, argc, argv, VGS);
}
Exemplo n.º 8
0
 std::string report() final {
     return _report() + " " + timer.str();
 }