Example #1
0
Eterm
erts_lc_dump_graph(void)
{
    const char* basename = "lc_graph.";
    char filename[40];
    lc_matrix_t* tot = &tot_lc_matrix;
    lc_thread_t* thr;
    int i, j, name_max = 0;
    FILE* ff;

    lc_lock_threads();
    for (thr = lc_threads; thr; thr = thr->next) {
        collect_matrix(&thr->matrix);
    }
    lc_unlock_threads();

    sys_strcpy(filename, basename);
    sys_get_pid(filename + strlen(basename),
                sizeof(filename) - strlen(basename));
    ff = fopen(filename, "w");
    if (!ff)
        return am_error;

    for (i = 1; i < ERTS_LOCK_ORDER_SIZE; i++) {
        int len = strlen(erts_lock_order[i].name);
        if (name_max < len)
            name_max = len;
    }
    fputs("%This file was generated by erts_debug:lc_graph()\n\n", ff);
    fputs("%{ThisLockName, ThisLockId, LockedDirectlyBeforeThis, LockedIndirectlyBeforeThis}\n", ff);
    fprintf(ff, "[{%*s, %2d}", name_max, "\"NO LOCK\"", 0);
    for (i = 1; i < ERTS_LOCK_ORDER_SIZE; i++) {
        char* delim = "";
        fprintf(ff, ",\n {%*s, %2d, [", name_max, erts_lock_order[i].name, i);
        for (j = 0; j < ERTS_LOCK_ORDER_SIZE; j++) {
            if (tot->m[i][j] & 1) {
                fprintf(ff, "%s%d", delim, j);
                delim = ",";
            }
        }
        fprintf(ff, "], [");
        delim = "";
        for (j = 0; j < ERTS_LOCK_ORDER_SIZE; j++) {
            if (tot->m[i][j] == 2) {
                fprintf(ff, "%s%d", delim, j);
                delim = ",";
            }
        }
        fputs("]}", ff);
    }
    fputs("].", ff);
    fclose(ff);
    erts_fprintf(stderr, "Created file '%s' in current working directory\n",
                 filename);
    return am_ok;
}
Example #2
0
BIF_RETTYPE os_getpid_0(BIF_ALIST_0)
{
     char pid_string[21]; /* enough for a 64 bit number */
     int n;
     Eterm* hp;
     sys_get_pid(pid_string, sizeof(pid_string)); /* In sys.c */
     n = sys_strlen(pid_string);
     hp = HAlloc(BIF_P, n*2);
     BIF_RET(buf_to_intlist(&hp, pid_string, n, NIL));
}
Example #3
0
void erts_mtrace_init(char *receiver, char *nodename)
{
    char hostname[MAXHOSTNAMELEN + 1];
    char pid[21]; /* enough for a 64 bit number */

    socket_desc = ERTS_SOCK_INVALID_SOCKET;
    erts_mtrace_enabled = receiver != NULL;

    if (erts_mtrace_enabled) {
	unsigned a, b, c, d, p;
	byte ip_addr[4];
	Uint16 port;

        erts_mtx_init(&mtrace_buf_mutex, "mtrace_buf", NIL,
            ERTS_LOCK_FLAGS_PROPERTY_STATIC | ERTS_LOCK_FLAGS_CATEGORY_DEBUG);
        erts_mtx_init(&mtrace_op_mutex, "mtrace_op", NIL,
            ERTS_LOCK_FLAGS_PROPERTY_STATIC | ERTS_LOCK_FLAGS_CATEGORY_DEBUG);

	socket_desc = erts_sock_open();
	if (socket_desc == ERTS_SOCK_INVALID_SOCKET) {
	    disable_trace(1, "Failed to open socket", erts_sock_errno());
	    return;
	}

	if (5 != sscanf(receiver, "%u.%u.%u.%u:%u", &a, &b, &c, &d, &p)
	    || a >= (1 << 8) || b >= (1 << 8)|| c >= (1 << 8) || d >= (1 << 8)
	    || p >= (1 << 16)) {
	    disable_trace(1, "Invalid receiver address", 0);
	    return;
	}

	ip_addr[0] = (byte) a;
	ip_addr[1] = (byte) b;
	ip_addr[2] = (byte) c;
	ip_addr[3] = (byte) d; 

	port = (Uint16) p;

	if (!erts_sock_connect(socket_desc, ip_addr, 4, port)) {
	    disable_trace(1, "Failed to connect to receiver",
			  erts_sock_errno());
	    return;
	}
	tracep = trace_buffer;
	endp = trace_buffer + TRACE_BUF_SZ;
        /* gethostname requires that the len is max(hostname) + 1 */
	if (erts_sock_gethostname(hostname, MAXHOSTNAMELEN + 1) != 0)
	    hostname[0] = '\0';
	hostname[MAXHOSTNAMELEN] = '\0';
	sys_get_pid(pid, sizeof(pid));
	write_trace_header(nodename ? nodename : "", pid, hostname);
	erts_mtrace_update_heap_size();
    }
}
Example #4
0
Eterm
os_getpid_0(Process* p)
{
     char pid_string[21]; /* enough for a 64 bit number */
     int n;
     Eterm* hp;
     sys_get_pid(pid_string); /* In sys.c */
     n = sys_strlen(pid_string);
     hp = HAlloc(p, n*2);
     BIF_RET(buf_to_intlist(&hp, pid_string, n, NIL));
}