iOS 的线程技术与Mac OS X类似,也是基于 Mach 线程技术实现的,在 Mach 层中thread_basic_info 结构体封装了单个线程的基本信息:
1 2 3 4 5 6 7 8 9 10
structthread_basic_info { time_value_t user_time; /* user run time */ time_value_t system_time; /* system run time */ integer_t cpu_usage; /* scaled cpu usage percentage */ policy_t policy; /* scheduling policy in effect */ integer_t run_state; /* run state (see below) */ integer_t flags; /* various flags (see below) */ integer_t suspend_count; /* suspend count for thread */ integer_t sleep_time; /* number of seconds that thread has been sleeping */ }
一个Mach Task包含它的线程列表。内核提供了task_threads API 调用获取指定 task 的线程列表,然后可以通过thread_info API调用来查询指定线程的信息,在 thread_act.h 中有相关定义。
/* * phys_footprint * Physical footprint: This is the sum of: * + (internal - alternate_accounting) * + (internal_compressed - alternate_accounting_compressed) * + iokit_mapped * + purgeable_nonvolatile * + purgeable_nonvolatile_compressed * + page_table * * internal * The task's anonymous memory, which on iOS is always resident. * * internal_compressed * Amount of this task's internal memory which is held by the compressor. * Such memory is no longer actually resident for the task [i.e., resident in its pmap], * and could be either decompressed back into memory, or paged out to storage, depending * on our implementation. * * iokit_mapped * IOKit mappings: The total size of all IOKit mappings in this task, regardless of clean/dirty or internal/external state]. * * alternate_accounting * The number of internal dirty pages which are part of IOKit mappings. By definition, these pages * are counted in both internal *and* iokit_mapped, so we must subtract them from the total to avoid * double counting. */
Exception Type: 00000020Exception Codes: 0x000000008badf00dHighlighted Thread: 0 Application Specific Information:com.myapp.myapp failed to scene-create in time Elapsed total CPU time (seconds): 4.230 (user 4.230, system 0.000), 10% CPU Elapsed application CPU time (seconds): 1.039, 3% CPU Thread 0 name: Dispatch queue: com.apple.main-threadThread 0:0 libsystem_kernel.dylib 0x36360540 semaphore_wait_trap + 81 libdispatch.dylib 0x36297eee _dispatch_semaphore_wait_slow + 1862 libxpc.dylib 0x364077b8 xpc_connection_send_message_with_reply_sync + 1523 Security 0x2b8dd310 securityd_message_with_reply_sync + 644 Security 0x2b8dd48c securityd_send_sync_and_do + 445 Security 0x2b8ea452 __SecItemCopyMatching_block_invoke + 1666 Security 0x2b8e96f6 SecOSStatusWith + 147 Security 0x2b8ea36e SecItemCopyMatching + 174
3 启动/重启超时 App由于启动/重启的时间超过系统允许的时间限制,造成异常退出。
scene-create watchdog transgression: app exhausted real (wall clock) time allowance of 19.93 seconds, Elapsed total CPU time (seconds): 21.050 (user 21.050, system 0.000)
Do not try to second-guess the JIT compiler.无需过多去帮jit编译器做手工优化。
Be careful with aliasing, esp. when using multiple arrays.变量的别名可能会阻止jit优化掉子表达式,尤其是在使用多个数组的时候。
Reduce the number of live temporary variables.减少存活着的临时变量的数量
Do not intersperse expensive or uncompiled operations.减少使用高消耗或者不支持jit的操作
Lua的API
参考api文档
#define lua_open() luaL_newstate() 开启一个lua状态机
1 2 3 4 5 6 7 8 9
voidlua_settable(lua_State *L, int index); // Does the equivalent to t[k] = v, // where t is the value at the given valid index index, // v is the value at the top of the stack, // and k is the value just below the top.
// This function pops both the key and the value from the stack. // As in Lua, this function may trigger a metamethod // for the “newindex” event (see §2.8).