+++ /dev/null
-
-/*
- * Copyright(c) 2022 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-using global::System;
-using global::System.IO;
-using global::System.Diagnostics;
-
-namespace Tizen.NUI
-{
- internal class DebugFileLogging : Disposable
- {
- #region Constant Fields
- private string logFolderPath;
- #endregion //Constant Fields
-
- #region Fields
- public static DebugFileLogging Instance => instance;
- private static readonly DebugFileLogging instance = new DebugFileLogging();
- private string filePath;
- private FileStream file;
- #endregion //Fields
-
- #region Constructors
- private DebugFileLogging()
- {
- if (Environment.OSVersion.Platform == PlatformID.Unix || Environment.OSVersion.Platform == PlatformID.MacOSX)
- {
- logFolderPath = Environment.GetEnvironmentVariable("HOME") + "/nui/";
- }
- else
- {
- logFolderPath = Environment.ExpandEnvironmentVariables("%HOMEDRIVE%%HOMEPATH%") + "/owner/share/nui/";
- }
-
- Directory.CreateDirectory(logFolderPath);
-
- using var process = Process.GetCurrentProcess();
- var id = process.Id;
- filePath = logFolderPath + id.ToString();
- file = new FileStream(filePath, FileMode.OpenOrCreate, FileAccess.ReadWrite);
- }
- #endregion //Constructors
-
- #region Methods
- [Conditional("NUI_DISPOSE_DEBUG_ON")]
- internal void WriteLog(string log)
- {
- TimeSpan curr = DateTime.Now.TimeOfDay;
-
- FileStream file = new FileStream(filePath, FileMode.Append, FileAccess.Write);
- StreamWriter write = new StreamWriter(file);
- var time = String.Format("[{0,-13}] ", curr.TotalMilliseconds);
- write.WriteLine(time + log);
- write.Close();
- }
- #endregion //Methods
- }
-}
disposeQueueProcessDisposablesDelegate = new EventThreadCallback.CallbackDelegate(ProcessDisposables);
eventThreadCallback = new EventThreadCallback(disposeQueueProcessDisposablesDelegate);
initialized = true;
-
- DebugFileLogging.Instance.WriteLog("DiposeTest START");
}
}
{
if (disposables.Count > 0)
{
- DebugFileLogging.Instance.WriteLog($"Newly add {disposables.Count} count of disposables. Total disposables count is {incrementallyDisposedQueue.Count + disposables.Count}.\n");
// Move item from end, due to the performance issue.
while (disposables.Count > 0)
{
var disposeCount = fullCollectRequested ? incrementallyDisposedQueue.Count
: Math.Min(incrementallyDisposedQueue.Count, Math.Max(minimumIncrementalCount, incrementallyDisposedQueue.Count * minimumIncrementalRate / 100));
- DebugFileLogging.Instance.WriteLog((fullCollectRequested ? "Fully" : "Incrementally") + $" dispose {disposeCount} disposables. Will remained disposables count is {incrementallyDisposedQueue.Count - disposeCount}.\n");
-
fullCollectRequested = false;
// Dispose item from end, due to the performance issue.
--disposeCount;
var disposable = incrementallyDisposedQueue.Last();
incrementallyDisposedQueue.RemoveAt(incrementallyDisposedQueue.Count - 1);
-
- DebugFileLogging.Instance.WriteLog($"disposable.Dispose(); type={disposable.GetType().FullName}, hash={disposable.GetHashCode()}");
disposable.Dispose();
}
ProcessorController.Instance.Awake();
}
}
-
- DebugFileLogging.Instance.WriteLog($"Incrementally dispose finished.\n");
}
}
}
//to catch derived classes dali native exceptions
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
- DebugFileLogging.Instance.WriteLog($"BaseHandle.contructor with cMemeryOwn:{cMemoryOwn} and cRegister:{cRegister} START");
-
registerMe = cRegister;
swigCMemOwn = cMemoryOwn;
swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
registerMe = false;
}
}
-
- disposeDebuggingCtor();
- DebugFileLogging.Instance.WriteLog($" BaseHandle.contructor with cMemeryOwn and cRegister END");
- DebugFileLogging.Instance.WriteLog($"=============================");
}
internal BaseHandle(global::System.IntPtr cPtr, bool cMemoryOwn)
//to catch derived classes dali native exceptions
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
- DebugFileLogging.Instance.WriteLog($"BaseHandle.contructor with cMemeryOwn:{cMemoryOwn} START");
-
registerMe = swigCMemOwn = cMemoryOwn;
swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
registerMe = false;
}
}
-
- disposeDebuggingCtor();
- DebugFileLogging.Instance.WriteLog($" BaseHandle.contructor with cMemeryOwn END");
- DebugFileLogging.Instance.WriteLog($"=============================");
}
internal BaseHandle(global::System.IntPtr cPtr)
{
- DebugFileLogging.Instance.WriteLog($"BaseHandle.contructor START");
-
registerMe = swigCMemOwn = true;
swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
registerMe = false;
}
}
-
- disposeDebuggingCtor();
- DebugFileLogging.Instance.WriteLog($"BaseHandle.contructor END");
- DebugFileLogging.Instance.WriteLog($"=============================");
}
/// <summary>
var thread = global::System.Threading.Thread.CurrentThread.ManagedThreadId;
var me = this.GetType().FullName;
- DebugFileLogging.Instance.WriteLog("[NUI][BaseHandle] This API called from separate thread. This API must be called from MainThread. \n" +
- $" process:{processId} thread:{thread}, disposing:{disposing}, isDisposed:{this.disposed}, isDisposeQueued:{this.isDisposeQueued}, me:{me}\n");
-
Tizen.Log.Fatal("NUI", $"[NUI][BaseHandle] This API called from separate thread. This API must be called from MainThread. \n" +
$" process:{processId} thread:{thread}, disposing:{disposing}, isDisposed:{this.disposed}, isDisposeQueued:{this.isDisposeQueued}, me:{me}\n");
if (isDisposeQueued)
{
- DebugFileLogging.Instance.WriteLog($"should not be here! (dead code) this will be removed!");
-
Tizen.Log.Fatal("NUI", $"[NUI] should not be here! (dead code) this will be removed!");
//to fix ArtApp black screen issue. this will be enabled after talking with ArtApp team and fixing it.
return;
}
- DebugFileLogging.Instance.WriteLog($"BaseHandle.Dispose({type}) START");
-
if (type == DisposeTypes.Explicit)
{
//Called by User
//Unreference this instance from Registry.
UnregisterFromRegistry();
- disposeDebuggingDispose(type);
-
if (SwigCPtr.Handle != IntPtr.Zero)
{
var nativeSwigCPtr = swigCPtr.Handle;
else
{
var me = this.GetType().FullName;
- DebugFileLogging.Instance.WriteLog($"[ERR] SwigCPtr is NULL, need to check! me:{me}");
Log.Error("NUI", $"[ERR] SwigCPtr is NULL, need to check! me:{me}");
}
disposed = true;
- DebugFileLogging.Instance.WriteLog($"BaseHandle.Dispose({type}) END");
- DebugFileLogging.Instance.WriteLog($"=============================");
NUILog.Debug($"BaseHandle.Dispose({type}) END");
NUILog.Debug($"=============================");
}
{
nativeBindedHolder.Remove(handle);
}
-
- [Conditional("NUI_DISPOSE_DEBUG_ON")]
- private void disposeDebuggingCtor()
- {
- DebugFileLogging.Instance.WriteLog($"type:{GetType()} copyNativeHandle:{swigCPtr.Handle.ToString("X8")}");
- if (this is BaseComponents.View view)
- {
- DebugFileLogging.Instance.WriteLog($"ID:{view.ID} Name:{view.Name}");
- //back trace
- global::System.Diagnostics.StackTrace st = new global::System.Diagnostics.StackTrace(true);
- for (int i = 0; i < st.FrameCount; i++)
- {
- global::System.Diagnostics.StackFrame sf = st.GetFrame(i);
- DebugFileLogging.Instance.WriteLog($"[{i}] {sf.GetMethod()}:{sf.GetFileName()}:{sf.GetFileLineNumber()}");
- }
- }
- }
-
- [Conditional("NUI_DISPOSE_DEBUG_ON")]
- private void disposeDebuggingDispose(DisposeTypes type)
- {
- DebugFileLogging.Instance.WriteLog($"swigCMemOwn:{swigCMemOwn} type:{GetType()} copyNativeHandle:{swigCPtr.Handle.ToString("X8")} HasBody:{HasBody()}");
-
- if (HasBody())
- {
- using var currentProcess = global::System.Diagnostics.Process.GetCurrentProcess();
- var process = currentProcess.Id;
- var thread = global::System.Threading.Thread.CurrentThread.ManagedThreadId;
- var me = this.GetType().FullName;
- var daliId = "unknown";
- var hash = this.GetType().GetHashCode();
- var name = "unknown";
-
- if (this is BaseComponents.View)
- {
- daliId = Interop.Actor.GetId(swigCPtr).ToString();
- name = Interop.Actor.GetName(swigCPtr);
- BaseObject tmp = new BaseObject(Interop.BaseHandle.GetBaseObject(swigCPtr), false);
- var refCnt = tmp.ReferenceCount();
- tmp.Dispose();
- if (refCnt > 2)
- {
- DebugFileLogging.Instance.WriteLog($"[ERR] reference count is over than 2. Could be a memory leak. Need to check! \n" +
- $" process:{process} thread:{thread}, isDisposed:{this.disposed}, isDisposeQueued:{this.isDisposeQueued}, me:{me} \n" +
- $" disposeType:{type}, name:{name}, daliID:{daliId}, hash:{hash}, refCnt:{refCnt}");
-
- Log.Error("NUI", $"[ERR] reference count is over than 2. Could be a memory leak. Need to check! \n" +
- $" process:{process} thread:{thread}, isDisposed:{this.disposed}, isDisposeQueued:{this.isDisposeQueued}, me:{me} \n" +
- $" disposeType:{type}, name:{name}, daliID:{daliId}, hash:{hash}, refCnt:{refCnt}");
- }
- }
- }
- }
-
}
}