public void Clear() { m_isRecord = false; luaDiff = null; m_dateTime = ""; m_detailList = null; }
public static LuaDiffInfo DeserializeDiff(BinaryReader br) { LuaDiffInfo diffInfo = LuaDiffInfo.Create(); int addCount = br.ReadInt32(); for (int i = 0; i < addCount; i++) { diffInfo.PushAddRef(ReadString(br), br.ReadInt32()); } int addDetailCount = br.ReadInt32(); for (int i = 0; i < addDetailCount; i++) { string key = ReadString(br); int count = br.ReadInt32(); for (int ii = 0; ii < count; ii++) { diffInfo.PushAddDetail(key, ReadString(br)); } } int rmCount = br.ReadInt32(); for (int i = 0; i < rmCount; i++) { diffInfo.PushRmRef(ReadString(br), br.ReadInt32()); } int rmDetailCount = br.ReadInt32(); for (int i = 0; i < rmDetailCount; i++) { string key = ReadString(br); int count = br.ReadInt32(); for (int ii = 0; ii < count; ii++) { diffInfo.PushRmDetail(key, ReadString(br)); } } int nullCount = br.ReadInt32(); for (int i = 0; i < nullCount; i++) { diffInfo.PushNullRef(ReadString(br), br.ReadInt32()); } int nullDetailCount = br.ReadInt32(); for (int i = 0; i < nullDetailCount; i++) { string key = ReadString(br); int count = br.ReadInt32(); for (int ii = 0; ii < count; ii++) { diffInfo.PushNullDetail(key, ReadString(br)); } } return(diffInfo); }
public static LuaDiffInfo Diff() { IntPtr L = LuaProfiler.mainL; if (L == IntPtr.Zero) { return(null); } isHook = false; Resources.UnloadUnusedAssets(); // 调用C# LuaTable LuaFunction WeakTable的析构 来清理掉lua的 ref GC.Collect(); // 清理掉C#强ref后,顺便清理掉很多弱引用 LuaDLL.lua_gc(L, LuaGCOptions.LUA_GCCOLLECT, 0); if (historyRef == -100) { Debug.LogError("has no history"); return(null); } int oldTop = LuaDLL.lua_gettop(L); LuaDLL.lua_getglobal(L, "miku_handle_error"); LuaDLL.lua_getglobal(L, "miku_diff"); LuaDLL.lua_getref(L, historyRef); if (LuaDLL.lua_type(L, -1) != LuaTypes.LUA_TTABLE) { Debug.LogError(LuaDLL.lua_type(L, -1)); LuaDLL.lua_settop(L, oldTop); historyRef = -100; return(null); } if (LuaDLL.lua_pcall(L, 1, 3, oldTop + 1) == 0) { LuaDLL.lua_remove(L, oldTop + 1); } int nullObjectRef = LuaDLL.luaL_ref(L, LuaIndexes.LUA_REGISTRYINDEX); int rmRef = LuaDLL.luaL_ref(L, LuaIndexes.LUA_REGISTRYINDEX); int addRef = LuaDLL.luaL_ref(L, LuaIndexes.LUA_REGISTRYINDEX); LuaDiffInfo ld = LuaDiffInfo.Create(); SetTable(nullObjectRef, ld.nullRef, ld.nullDetail); SetTable(rmRef, ld.rmRef, ld.rmDetail); SetTable(addRef, ld.addRef, ld.addDetail); LuaDLL.lua_unref(L, nullObjectRef); LuaDLL.lua_unref(L, rmRef); LuaDLL.lua_unref(L, addRef); LuaDLL.lua_settop(L, oldTop); isHook = true; return(ld); }
public static LuaDiffInfo Create() { LuaDiffInfo r = m_pool.GetObject(); r.addRef.Clear(); r.addDetail.Clear(); r.rmRef.Clear(); r.rmDetail.Clear(); r.nullRef.Clear(); return r; }
public void Clear() { m_isRecord = false; m_isStaticRecord = false; luaDiff = null; m_dateTime = ""; m_staticDateTime = ""; m_detailList = null; LuaHook.ClearStaticRecord(); LuaHook.ClearRecord(); }
public static void Diff() { IntPtr L = LuaProfiler.mainL; if (L == IntPtr.Zero) { return; } isHook = false; if (historyRef == -100) { Debug.LogError("has no history"); return; } int oldTop = LuaDLL.lua_gettop(L); LuaDLL.lua_getglobal(L, "miku_handle_error"); LuaDLL.lua_getglobal(L, "miku_diff"); LuaDLL.lua_getref(L, historyRef); if (LuaDLL.lua_type(L, -1) != LuaTypes.LUA_TTABLE) { Debug.LogError(LuaDLL.lua_type(L, -1)); LuaDLL.lua_settop(L, oldTop); historyRef = -100; return; } if (LuaDLL.lua_pcall(L, 1, 3, oldTop + 1) == 0) { LuaDLL.lua_remove(L, oldTop + 1); } int nullObjectRef = LuaDLL.luaL_ref(L, LuaIndexes.LUA_REGISTRYINDEX); int rmRef = LuaDLL.luaL_ref(L, LuaIndexes.LUA_REGISTRYINDEX); int addRef = LuaDLL.luaL_ref(L, LuaIndexes.LUA_REGISTRYINDEX); LuaDiffInfo ld = LuaDiffInfo.Create(); SetNullObject(nullObjectRef, ld.nullRef); SetAddOrRm(rmRef, ld.rmRef, ld.rmDetail); SetAddOrRm(addRef, ld.addRef, ld.addDetail); NetWorkClient.SendMessage(ld); LuaDLL.lua_unref(L, nullObjectRef); LuaDLL.lua_unref(L, rmRef); LuaDLL.lua_unref(L, addRef); LuaDLL.lua_settop(L, oldTop); isHook = true; }
public void DelDiffInfo(LuaDiffInfo info) { luaDiff = info; }
public static LuaDiffInfo Record() { IntPtr L = LuaProfiler.mainL; if (L == IntPtr.Zero) { return(null); } isHook = false; ClearRecord(); Resources.UnloadUnusedAssets(); // 调用C# LuaTable LuaFunction WeakTable的析构 来清理掉lua的 ref GC.Collect(); // 清理掉C#强ref后,顺便清理掉很多弱引用 LuaDLL.lua_gc(L, LuaGCOptions.LUA_GCCOLLECT, 0); int oldTop = LuaDLL.lua_gettop(L); LuaDLL.lua_getglobal(L, "miku_handle_error"); LuaDLL.lua_getglobal(L, "miku_do_record"); LuaDLL.lua_getglobal(L, "_G"); LuaDLL.lua_pushstring(L, ""); LuaDLL.lua_pushstring(L, "_G"); //recrod LuaDLL.lua_newtable(L); historyRef = LuaDLL.luaL_ref(L, LuaIndexes.LUA_REGISTRYINDEX); LuaDLL.lua_getref(L, historyRef); //history LuaDLL.lua_pushnil(L); //null_list LuaDLL.lua_newtable(L); LuaDLL.lua_pushvalue(L, -1); int nullObjectRef = LuaDLL.luaL_ref(L, LuaIndexes.LUA_REGISTRYINDEX); LuaDLL.lua_getref(L, staticHistoryRef); if (LuaDLL.lua_pcall(L, 7, 0, oldTop + 1) == 0) { LuaDLL.lua_remove(L, oldTop + 1); } LuaDLL.lua_settop(L, oldTop); oldTop = LuaDLL.lua_gettop(L); LuaDLL.lua_getglobal(L, "miku_handle_error"); LuaDLL.lua_getglobal(L, "miku_do_record"); LuaDLL.lua_pushvalue(L, LuaIndexes.LUA_REGISTRYINDEX); LuaDLL.lua_pushstring(L, ""); LuaDLL.lua_pushstring(L, "_R"); LuaDLL.lua_getref(L, historyRef); //history LuaDLL.lua_pushnil(L); //null_list LuaDLL.lua_getref(L, nullObjectRef); LuaDLL.lua_getref(L, staticHistoryRef); if (LuaDLL.lua_pcall(L, 7, 0, oldTop + 1) == 0) { LuaDLL.lua_remove(L, oldTop + 1); } LuaDLL.lua_settop(L, oldTop); LuaDiffInfo ld = LuaDiffInfo.Create(); SetTable(nullObjectRef, ld.nullRef, ld.nullDetail); LuaDLL.lua_unref(L, nullObjectRef); isHook = true; return(ld); }
private static void Serialize(NetBase o, BinaryWriter bw) { if (o is Sample) { Sample s = (Sample)o; bw.Write(s.calls); bw.Write(s.frameCount); bw.Write(s.costLuaGC); bw.Write(s.costMonoGC); WriteString(bw, s.name); bw.Write(s.costTime); bw.Write(s.currentLuaMemory); bw.Write(s.currentMonoMemory); bw.Write((ushort)s.childs.Count); // 防止多线程 栈展开故意做的优化,先自己展开28层,后面的就递归 var childs0 = s.childs; for (int i0 = 0, i0max = childs0.Count; i0 < i0max; i0++) { Sample s0 = childs0[i0]; bw.Write(s0.calls); bw.Write(s0.frameCount); bw.Write(s0.costLuaGC); bw.Write(s0.costMonoGC); WriteString(bw, s0.name); bw.Write(s0.costTime); bw.Write(s0.currentLuaMemory); bw.Write(s0.currentMonoMemory); bw.Write((ushort)s0.childs.Count); var childs1 = s0.childs; for (int i1 = 0, i1max = childs1.Count; i1 < i1max; i1++) { Sample s1 = childs1[i1]; bw.Write(s1.calls); bw.Write(s1.frameCount); bw.Write(s1.costLuaGC); bw.Write(s1.costMonoGC); WriteString(bw, s1.name); bw.Write(s1.costTime); bw.Write(s1.currentLuaMemory); bw.Write(s1.currentMonoMemory); bw.Write((ushort)s1.childs.Count); var childs2 = s1.childs; for (int i2 = 0, i2max = childs2.Count; i2 < i2max; i2++) { Sample s2 = childs2[i2]; bw.Write(s2.calls); bw.Write(s2.frameCount); bw.Write(s2.costLuaGC); bw.Write(s2.costMonoGC); WriteString(bw, s2.name); bw.Write(s2.costTime); bw.Write(s2.currentLuaMemory); bw.Write(s2.currentMonoMemory); bw.Write((ushort)s2.childs.Count); var childs3 = s2.childs; for (int i3 = 0, i3max = childs3.Count; i3 < i3max; i3++) { Sample s3 = childs3[i3]; bw.Write(s3.calls); bw.Write(s3.frameCount); bw.Write(s3.costLuaGC); bw.Write(s3.costMonoGC); WriteString(bw, s3.name); bw.Write(s3.costTime); bw.Write(s3.currentLuaMemory); bw.Write(s3.currentMonoMemory); bw.Write((ushort)s3.childs.Count); var childs4 = s3.childs; for (int i4 = 0, i4max = childs4.Count; i4 < i4max; i4++) { Sample s4 = childs4[i4]; bw.Write(s4.calls); bw.Write(s4.frameCount); bw.Write(s4.costLuaGC); bw.Write(s4.costMonoGC); WriteString(bw, s4.name); bw.Write(s4.costTime); bw.Write(s4.currentLuaMemory); bw.Write(s4.currentMonoMemory); bw.Write((ushort)s4.childs.Count); var childs5 = s4.childs; for (int i5 = 0, i5max = childs5.Count; i5 < i5max; i5++) { Sample s5 = childs5[i5]; bw.Write(s5.calls); bw.Write(s5.frameCount); bw.Write(s5.costLuaGC); bw.Write(s5.costMonoGC); WriteString(bw, s5.name); bw.Write(s5.costTime); bw.Write(s5.currentLuaMemory); bw.Write(s5.currentMonoMemory); bw.Write((ushort)s5.childs.Count); var childs6 = s5.childs; for (int i6 = 0, i6max = childs6.Count; i6 < i6max; i6++) { Sample s6 = childs6[i6]; bw.Write(s6.calls); bw.Write(s6.frameCount); bw.Write(s6.costLuaGC); bw.Write(s6.costMonoGC); WriteString(bw, s6.name); bw.Write(s6.costTime); bw.Write(s6.currentLuaMemory); bw.Write(s6.currentMonoMemory); bw.Write((ushort)s6.childs.Count); var childs7 = s6.childs; for (int i7 = 0, i7max = childs7.Count; i7 < i7max; i7++) { Sample s7 = childs7[i7]; bw.Write(s7.calls); bw.Write(s7.frameCount); bw.Write(s7.costLuaGC); bw.Write(s7.costMonoGC); WriteString(bw, s7.name); bw.Write(s7.costTime); bw.Write(s7.currentLuaMemory); bw.Write(s7.currentMonoMemory); bw.Write((ushort)s7.childs.Count); var childs8 = s7.childs; for (int i8 = 0, i8max = childs8.Count; i8 < i8max; i8++) { Sample s8 = childs8[i8]; bw.Write(s8.calls); bw.Write(s8.frameCount); bw.Write(s8.costLuaGC); bw.Write(s8.costMonoGC); WriteString(bw, s8.name); bw.Write(s8.costTime); bw.Write(s8.currentLuaMemory); bw.Write(s8.currentMonoMemory); bw.Write((ushort)s8.childs.Count); var childs9 = s8.childs; for (int i9 = 0, i9max = childs9.Count; i9 < i9max; i9++) { Sample s9 = childs9[i9]; bw.Write(s9.calls); bw.Write(s9.frameCount); bw.Write(s9.costLuaGC); bw.Write(s9.costMonoGC); WriteString(bw, s9.name); bw.Write(s9.costTime); bw.Write(s9.currentLuaMemory); bw.Write(s9.currentMonoMemory); bw.Write((ushort)s9.childs.Count); var childs10 = s9.childs; for (int i10 = 0, i10max = childs10.Count; i10 < i10max; i10++) { Sample s10 = childs10[i10]; bw.Write(s10.calls); bw.Write(s10.frameCount); bw.Write(s10.costLuaGC); bw.Write(s10.costMonoGC); WriteString(bw, s10.name); bw.Write(s10.costTime); bw.Write(s10.currentLuaMemory); bw.Write(s10.currentMonoMemory); bw.Write((ushort)s10.childs.Count); var childs11 = s10.childs; for (int i11 = 0, i11max = childs11.Count; i11 < i11max; i11++) { Sample s11 = childs11[i11]; bw.Write(s11.calls); bw.Write(s11.frameCount); bw.Write(s11.costLuaGC); bw.Write(s11.costMonoGC); WriteString(bw, s11.name); bw.Write(s11.costTime); bw.Write(s11.currentLuaMemory); bw.Write(s11.currentMonoMemory); bw.Write((ushort)s11.childs.Count); var childs12 = s11.childs; for (int i12 = 0, i12max = childs12.Count; i12 < i12max; i12++) { Sample s12 = childs12[i12]; bw.Write(s12.calls); bw.Write(s12.frameCount); bw.Write(s12.costLuaGC); bw.Write(s12.costMonoGC); WriteString(bw, s12.name); bw.Write(s12.costTime); bw.Write(s12.currentLuaMemory); bw.Write(s12.currentMonoMemory); bw.Write((ushort)s12.childs.Count); var childs13 = s12.childs; for (int i13 = 0, i13max = childs13.Count; i13 < i13max; i13++) { Sample s13 = childs13[i13]; bw.Write(s13.calls); bw.Write(s13.frameCount); bw.Write(s13.costLuaGC); bw.Write(s13.costMonoGC); WriteString(bw, s13.name); bw.Write(s13.costTime); bw.Write(s13.currentLuaMemory); bw.Write(s13.currentMonoMemory); bw.Write((ushort)s13.childs.Count); var childs14 = s13.childs; for (int i14 = 0, i14max = childs14.Count; i14 < i14max; i14++) { Sample s14 = childs14[i14]; bw.Write(s14.calls); bw.Write(s14.frameCount); bw.Write(s14.costLuaGC); bw.Write(s14.costMonoGC); WriteString(bw, s14.name); bw.Write(s14.costTime); bw.Write(s14.currentLuaMemory); bw.Write(s14.currentMonoMemory); bw.Write((ushort)s14.childs.Count); var childs15 = s14.childs; for (int i15 = 0, i15max = childs15.Count; i15 < i15max; i15++) { Sample s15 = childs15[i15]; bw.Write(s15.calls); bw.Write(s15.frameCount); bw.Write(s15.costLuaGC); bw.Write(s15.costMonoGC); WriteString(bw, s15.name); bw.Write(s15.costTime); bw.Write(s15.currentLuaMemory); bw.Write(s15.currentMonoMemory); bw.Write((ushort)s15.childs.Count); var childs16 = s15.childs; for (int i16 = 0, i16max = childs16.Count; i16 < i16max; i16++) { Sample s16 = childs16[i16]; bw.Write(s16.calls); bw.Write(s16.frameCount); bw.Write(s16.costLuaGC); bw.Write(s16.costMonoGC); WriteString(bw, s16.name); bw.Write(s16.costTime); bw.Write(s16.currentLuaMemory); bw.Write(s16.currentMonoMemory); bw.Write((ushort)s16.childs.Count); var childs17 = s16.childs; for (int i17 = 0, i17max = childs17.Count; i17 < i17max; i17++) { Sample s17 = childs17[i17]; bw.Write(s17.calls); bw.Write(s17.frameCount); bw.Write(s17.costLuaGC); bw.Write(s17.costMonoGC); WriteString(bw, s17.name); bw.Write(s17.costTime); bw.Write(s17.currentLuaMemory); bw.Write(s17.currentMonoMemory); bw.Write((ushort)s17.childs.Count); var childs18 = s17.childs; for (int i18 = 0, i18max = childs18.Count; i18 < i18max; i18++) { Sample s18 = childs18[i18]; bw.Write(s18.calls); bw.Write(s18.frameCount); bw.Write(s18.costLuaGC); bw.Write(s18.costMonoGC); WriteString(bw, s18.name); bw.Write(s18.costTime); bw.Write(s18.currentLuaMemory); bw.Write(s18.currentMonoMemory); bw.Write((ushort)s18.childs.Count); var childs19 = s18.childs; for (int i19 = 0, i19max = childs19.Count; i19 < i19max; i19++) { Sample s19 = childs19[i19]; bw.Write(s19.calls); bw.Write(s19.frameCount); bw.Write(s19.costLuaGC); bw.Write(s19.costMonoGC); WriteString(bw, s19.name); bw.Write(s19.costTime); bw.Write(s19.currentLuaMemory); bw.Write(s19.currentMonoMemory); bw.Write((ushort)s19.childs.Count); var childs20 = s19.childs; for (int i20 = 0, i20max = childs20.Count; i20 < i20max; i20++) { Sample s20 = childs20[i20]; bw.Write(s20.calls); bw.Write(s20.frameCount); bw.Write(s20.costLuaGC); bw.Write(s20.costMonoGC); WriteString(bw, s20.name); bw.Write(s20.costTime); bw.Write(s20.currentLuaMemory); bw.Write(s20.currentMonoMemory); bw.Write((ushort)s20.childs.Count); var childs21 = s20.childs; for (int i21 = 0, i21max = childs21.Count; i21 < i21max; i21++) { Sample s21 = childs21[i21]; bw.Write(s21.calls); bw.Write(s21.frameCount); bw.Write(s21.costLuaGC); bw.Write(s21.costMonoGC); WriteString(bw, s21.name); bw.Write(s21.costTime); bw.Write(s21.currentLuaMemory); bw.Write(s21.currentMonoMemory); bw.Write((ushort)s21.childs.Count); var childs22 = s21.childs; for (int i22 = 0, i22max = childs22.Count; i22 < i22max; i22++) { Sample s22 = childs22[i22]; bw.Write(s22.calls); bw.Write(s22.frameCount); bw.Write(s22.costLuaGC); bw.Write(s22.costMonoGC); WriteString(bw, s22.name); bw.Write(s22.costTime); bw.Write(s22.currentLuaMemory); bw.Write(s22.currentMonoMemory); bw.Write((ushort)s22.childs.Count); var childs23 = s22.childs; for (int i23 = 0, i23max = childs23.Count; i23 < i23max; i23++) { Sample s23 = childs23[i23]; bw.Write(s23.calls); bw.Write(s23.frameCount); bw.Write(s23.costLuaGC); bw.Write(s23.costMonoGC); WriteString(bw, s23.name); bw.Write(s23.costTime); bw.Write(s23.currentLuaMemory); bw.Write(s23.currentMonoMemory); bw.Write((ushort)s23.childs.Count); var childs24 = s23.childs; for (int i24 = 0, i24max = childs24.Count; i24 < i24max; i24++) { Sample s24 = childs24[i24]; bw.Write(s24.calls); bw.Write(s24.frameCount); bw.Write(s24.costLuaGC); bw.Write(s24.costMonoGC); WriteString(bw, s24.name); bw.Write(s24.costTime); bw.Write(s24.currentLuaMemory); bw.Write(s24.currentMonoMemory); bw.Write((ushort)s24.childs.Count); var childs25 = s24.childs; for (int i25 = 0, i25max = childs25.Count; i25 < i25max; i25++) { Sample s25 = childs25[i25]; bw.Write(s25.calls); bw.Write(s25.frameCount); bw.Write(s25.costLuaGC); bw.Write(s25.costMonoGC); WriteString(bw, s25.name); bw.Write(s25.costTime); bw.Write(s25.currentLuaMemory); bw.Write(s25.currentMonoMemory); bw.Write((ushort)s25.childs.Count); var childs26 = s25.childs; for (int i26 = 0, i26max = childs26.Count; i26 < i26max; i26++) { Sample s26 = childs26[i26]; bw.Write(s26.calls); bw.Write(s26.frameCount); bw.Write(s26.costLuaGC); bw.Write(s26.costMonoGC); WriteString(bw, s26.name); bw.Write(s26.costTime); bw.Write(s26.currentLuaMemory); bw.Write(s26.currentMonoMemory); bw.Write((ushort)s26.childs.Count); var childs27 = s26.childs; for (int i27 = 0, i27max = childs27.Count; i27 < i27max; i27++) { Sample s27 = childs27[i27]; bw.Write(s27.calls); bw.Write(s27.frameCount); bw.Write(s27.costLuaGC); bw.Write(s27.costMonoGC); WriteString(bw, s27.name); bw.Write(s27.costTime); bw.Write(s27.currentLuaMemory); bw.Write(s27.currentMonoMemory); bw.Write((ushort)s27.childs.Count); var childs28 = s27.childs; for (int i28 = 0, i28max = childs28.Count; i28 < i28max; i28++) { Sample s28 = childs28[i28]; Serialize(s28, bw); } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } else if (o is LuaRefInfo) { LuaRefInfo r = (LuaRefInfo)o; bw.Write(r.cmd); bw.Write(Main.frameCount); WriteString(bw, r.name); WriteString(bw, r.addr); bw.Write(r.type); } else if (o is LuaDiffInfo) { LuaDiffInfo ld = (LuaDiffInfo)o; // add var addDict = ld.addRef; bw.Write(addDict.Count); foreach (var item in addDict) { WriteString(bw, item.Key); bw.Write((int)item.Value); } var addDetail = ld.addDetail; bw.Write(addDetail.Count); foreach (var item in addDetail) { WriteString(bw, item.Key); var list = item.Value; bw.Write(list.Count); foreach (var listItem in list) { WriteString(bw, listItem); } } // rm var rmDict = ld.rmRef; bw.Write(rmDict.Count); foreach (var item in rmDict) { WriteString(bw, item.Key); bw.Write((int)item.Value); } var rmDetail = ld.rmDetail; bw.Write(rmDetail.Count); foreach (var item in rmDetail) { WriteString(bw, item.Key); var list = item.Value; bw.Write(list.Count); foreach (var listItem in list) { WriteString(bw, listItem); } } // null var nullDict = ld.nullRef; bw.Write(nullDict.Count); foreach (var item in nullDict) { WriteString(bw, item.Key); bw.Write((int)item.Value); } var nullDetail = ld.nullDetail; bw.Write(nullDetail.Count); foreach (var item in nullDetail) { WriteString(bw, item.Key); var list = item.Value; bw.Write(list.Count); foreach (var listItem in list) { WriteString(bw, listItem); } } } }