Move /trace and /mem to C.
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4724 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
46
src/task.c
46
src/task.c
@ -181,7 +181,6 @@ static JSValue _tf_task_version(JSContext* context, JSValueConst this_val, int a
|
||||
static JSValue _tf_task_platform(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv);
|
||||
static JSValue _tf_task_get_parent(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv);
|
||||
static JSValue _tf_task_exit(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv);
|
||||
static JSValue _tf_task_trace(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv);
|
||||
static JSValue _tf_task_getStats(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv);
|
||||
static JSValue _tf_task_getFile(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv);
|
||||
|
||||
@ -781,22 +780,6 @@ static void _tf_task_release_export(tf_taskstub_t* stub, exportid_t exportId)
|
||||
}
|
||||
}
|
||||
|
||||
static JSValue _tf_task_trace(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv)
|
||||
{
|
||||
tf_task_t* task = JS_GetContextOpaque(context);
|
||||
if (!task->_trace)
|
||||
{
|
||||
return JS_UNDEFINED;
|
||||
}
|
||||
|
||||
tf_trace_begin(task->_trace, __func__);
|
||||
char* trace = tf_trace_export(task->_trace);
|
||||
JSValue result = JS_NewString(context, trace);
|
||||
tf_free(trace);
|
||||
tf_trace_end(task->_trace);
|
||||
return result;
|
||||
}
|
||||
|
||||
static JSValue _tf_task_getStats(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv)
|
||||
{
|
||||
tf_task_t* task = JS_GetContextOpaque(context);
|
||||
@ -938,32 +921,6 @@ static JSValue _tf_task_getHitches(JSContext* context, JSValueConst this_val, in
|
||||
return result;
|
||||
}
|
||||
|
||||
static JSValue _tf_task_getAllocations(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv)
|
||||
{
|
||||
tf_task_t* task = JS_GetContextOpaque(context);
|
||||
tf_trace_begin(task->_trace, __func__);
|
||||
JSValue result = JS_NewObject(context);
|
||||
|
||||
int count = 0;
|
||||
tf_mem_allocation_t* allocation_info = tf_mem_summarize_allocations(&count);
|
||||
|
||||
JSValue allocations = JS_NewArray(context);
|
||||
JS_SetPropertyStr(context, result, "allocations", allocations);
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
JSValue allocation = JS_NewObject(context);
|
||||
JS_SetPropertyStr(context, allocation, "size", JS_NewInt64(context, allocation_info[i].size));
|
||||
JS_SetPropertyStr(context, allocation, "count", JS_NewInt32(context, allocation_info[i].count));
|
||||
const char* stack = tf_util_backtrace_to_string(allocation_info[i].frames, allocation_info[i].frames_count);
|
||||
JS_SetPropertyStr(context, allocation, "stack", JS_NewString(context, stack ? stack : ""));
|
||||
tf_free((void*)stack);
|
||||
JS_SetPropertyUint32(context, allocations, i, allocation);
|
||||
}
|
||||
tf_free(allocation_info);
|
||||
tf_trace_end(task->_trace);
|
||||
return result;
|
||||
}
|
||||
|
||||
static JSValue _tf_task_disconnectionsDebug(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv)
|
||||
{
|
||||
tf_task_t* task = JS_GetContextOpaque(context);
|
||||
@ -1746,11 +1703,10 @@ void tf_task_activate(tf_task_t* task)
|
||||
tf_ssb_server_open(task->_ssb, task->_ssb_port);
|
||||
}
|
||||
|
||||
JS_SetPropertyStr(context, global, "trace", JS_NewCFunction(context, _tf_task_trace, "trace", 1));
|
||||
JS_SetPropertyStr(context, global, "getStats", JS_NewCFunction(context, _tf_task_getStats, "getStats", 0));
|
||||
|
||||
JS_SetPropertyStr(context, global, "getDebug", JS_NewCFunction(context, _tf_task_getDebug, "getDebug", 0));
|
||||
JS_SetPropertyStr(context, global, "getHitches", JS_NewCFunction(context, _tf_task_getHitches, "getHitches", 0));
|
||||
JS_SetPropertyStr(context, global, "getAllocations", JS_NewCFunction(context, _tf_task_getAllocations, "getAllocations", 0));
|
||||
JS_SetPropertyStr(context, global, "disconnectionsDebug", JS_NewCFunction(context, _tf_task_disconnectionsDebug, "disconnectionsDebug", 0));
|
||||
}
|
||||
else
|
||||
|
Reference in New Issue
Block a user