Exemplo n.º 1
0
json_t prf_cmd_profilergantt(const char* param1, const char* param2)
{
    PROTECT_CMD();

    /* protect front buffer during data creation */
    mt_mutex_lock(&g_prf.samples_mtx);
    struct prf_samples* s = (struct prf_samples*)g_prf.samples_front;

    json_t root = json_create_obj();
    json_t data = json_create_obj();
    json_additem_toobj(root, "data", data);

    json_t jsamples = json_create_arr();
    json_additem_toobj(data, "duration", json_create_num(s->duration));
    json_additem_toobj(data, "samples", jsamples);

    struct linked_list* l = s->nodes;
    while (l != NULL)   {
        prf_create_node_json(jsamples, (struct prf_node*)l->data);
        l = l->next;
    }

    mt_mutex_unlock(&g_prf.samples_mtx);
    return root;
}
Exemplo n.º 2
0
void* mem_realloc(void *p, size_t size, const char *source, uint line, uint id)
{
    ASSERT(g_mem);

    void* ptr;
    if (g_mem->trace)     {
        mt_mutex_lock(&g_mem->lock);
        if (g_mem->stats.limit_bytes != 0 &&
            (size + g_mem->stats.alloc_bytes) > g_mem->stats.limit_bytes)
        {
            return NULL;
        }

        ptr = mem_realloc_withtrace(p, size);
        if (ptr != NULL)    {
            struct mem_trace_data* trace = get_trace_data(ptr);
#if defined(_DEBUG_)
            path_getfullfilename(trace->filename, source);
            trace->line = line;
#endif
            trace->size = size;
            trace->mem_id = id;

            mem_addto_ids(id, size);
        }
        mt_mutex_unlock(&g_mem->lock);
    }	else	{
        ptr = malloc_withsize(size);
    }
    return ptr;
}
Exemplo n.º 3
0
void mem_free(void* ptr)
{
    ASSERT(g_mem);
	if (g_mem->trace)	{
		mt_mutex_lock(&g_mem->lock);
        mem_removefrom_ids(ptr);
		mem_free_withtrace(ptr);
		mt_mutex_unlock(&g_mem->lock);
	}	else	{
		free_withsize(ptr);
	}
}
Exemplo n.º 4
0
void prf_presentsamples(fl64 ft)
{
    if (!g_prf.init)
        return;

    /* save whole frame duration for built sampels */
    g_prf.samples_back->duration = (float)(ft*1000.0);

    /* block presenting front buffer until we are done with json data creation */
    if (mt_mutex_try(&g_prf.samples_mtx))   {
        swapptr((void**)&g_prf.samples_back, (void**)&g_prf.samples_front);
        mt_mutex_unlock(&g_prf.samples_mtx);
    }

    /* reset back buffer stack allocator */
    struct prf_samples* s = g_prf.samples_back;
    mem_stack_reset(&s->alloc);
    s->node_cur = NULL;
    s->nodes = NULL;
}