public static void LogMemAndLinenumber() { StackFrame st = new StackFrame(1, true); float privateMB = Process.GetCurrentProcess().PrivateMemorySize64 / 1000000f; DebugMessageLogger.LogEvent("Memory Use {0}mb at {1}", privateMB, st); }
public string[] ZipFolder(string folder, string outputFile, int MaxSizeMB) { string[] list = new string[0]; try { StringBuilder sb = new StringBuilder(); sb.AppendFormat("a -tzip \"{0}\" -v{1}m", outputFile, MaxSizeMB); sb.AppendFormat(" \"{0}\"", folder); //_ZipAsyncCallback = callback; DebugMessageLogger.LogEventLevel("Running: {0} {1}", 0, exeLoc, sb.ToString()); ProcessStartInfo info = new ProcessStartInfo(exeLoc, sb.ToString()); info.RedirectStandardOutput = true; info.CreateNoWindow = true; info.UseShellExecute = false; _ZipProcess = Process.Start(info); _reader = _ZipProcess.StandardOutput; ProcessOutputReader(); //find all files in the format outputFile.??? var d = new DirectoryInfo(Path.GetDirectoryName(outputFile)); FileInfo[] infos = d.GetFiles(Path.GetFileName(outputFile) + ".*"); list = new string[infos.Length]; if (infos.Length == 1) { File.Move(infos[0].FullName, outputFile); list[0] = outputFile; } else { for (int i = 0; i < infos.Length; i++) { list[i] = infos[i].FullName; } } DebugMessageLogger.LogEvent("Z7Wrapper - Zip Folder {0} to {1} Files of limit {2}MB", folder, list.Length, MaxSizeMB); return(list); } catch (Exception ee) { DebugMessageLogger.LogError(ee); } return(list); }
public static bool GetDimensionsOfImageFromJpegData(byte[] jpegdata, out int width, out int height) { bool success = false; width = 0; height = 0; int loc = 0; try { int trys = 0; while (success == false && loc != -1 && loc < 2000 && trys < 20) { loc = ByteArrayUtils.IndexOf(jpegdata, new byte[] { 0xFF, 0xC0 }, loc, 2000); if (loc > 0) { byte[] heightbyte = new byte[] { jpegdata[loc + 6], jpegdata[loc + 5] }; //make BigEndian byte[] widthbyte = new byte[] { jpegdata[loc + 8], jpegdata[loc + 7] }; height = BitConverter.ToInt16(heightbyte, 0); width = BitConverter.ToInt16(widthbyte, 0); if (height > 0 && height < 65535 && width > 0 && width < 65535) { success = true; } else { success = false; loc += 2; trys++; } } } if (success == false) { DebugMessageLogger.LogEvent("Failed to recover good height ({0}) and width ({1}) from jpeg data. Tried {2} times", width, height, trys); } } catch (Exception ee) { success = false; DebugMessageLogger.LogError(ee); } return(success); }
public static void LogTeamviewerID() { try { var key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey( @"SOFTWARE\Wow6432Node\TeamViewer"); foreach (var subkeyname in key.GetSubKeyNames()) { var subkey = key.OpenSubKey(subkeyname); var clientID = subkey.GetValue("ClientID"); DebugMessageLogger.LogEvent("Teamviewer {0} Client ID: {1}", subkeyname, clientID); } } catch (Exception ee) { } }
public static void StartDiagnosticMode() { try { _recordMemUsageRegularly = false; try { if (_diagnosticMemoryThread != null) { _diagnosticMemoryThread.Abort(); } } catch (Exception eeee) { } _recordMemUsageRegularly = true; _diagnosticMemoryThread = new Thread(new ThreadStart(() => { try { while (_recordMemUsageRegularly) { long totmem = GC.GetTotalMemory(true); float privateMB = Process.GetCurrentProcess().PrivateMemorySize64 / 1000000f; DebugMessageLogger.LogEvent("Diagnostic Mode: Private Bytes Usage: {0} MB, GC: {1} MB", privateMB.ToString("n"), (totmem / 1000000f).ToString("n")); Kinesense.Interfaces.Threading.ThreadSleepMonitor.Sleep(10000); } } catch (Exception eee) { DebugMessageLogger.LogError(eee); } })); _diagnosticMemoryThread.Start(); } catch (Exception ee) { DebugMessageLogger.LogError(ee); } }
public static void RunCleanup(TimeSpan olderThan) { Task.Factory.StartNew(() => { try { Thread.CurrentThread.Name = "Run Cleanup"; DateTime now = DateTime.Now; DebugMessageLogger.LogEvent("Looking for log files older than {0} ago", olderThan); List <string> paths = new List <string>(); paths.Add(LogsFolder); foreach (var dir in Directory.GetDirectories(LogsFolder)) { if (!dir.Contains("CommonViewingLogs")) //dont delete viewing logs { paths.Add(dir); } } foreach (var dir in paths) { foreach (var file in Directory.GetFiles(dir, "*.log")) { TimeSpan howold = now - new FileInfo(file).LastWriteTime; if (howold > olderThan) { DebugMessageLogger.LogEvent("Deleting file {0} which is {1} days old", file, howold.Days); File.Delete(file); } } } } catch (Exception ee) { DebugMessageLogger.LogError(ee); } }); }
public static void LogClick() { DebugMessageLogger.LogEvent("--USER CLICK--- {0}", new StackFrame(1, true)); }
private static void ConvertExceptionToText(Exception e, string extra, int logLevel, string threadSignature) { try { //make sure log is in english Thread.CurrentThread.CurrentCulture = _logCulture; StringBuilder sb = new StringBuilder(); sb.AppendFormat("\r\n\r\n{0} [{1}] [{2}] {3}\r\n", DateTime.Now.ToString(TimeStampFormat), _instanceID, logLevel.ToString(), threadSignature); Exception printException = e; while (printException != null) { sb.AppendFormat("{0}\r\n", printException); sb.AppendFormat("Source: {0}\r\n", printException.Source); sb.AppendFormat("HasInnerException = {0}\r\n", (printException.InnerException != null)); printException = printException.InnerException; } if (!String.IsNullOrEmpty(extra)) { sb.AppendFormat("ExtraInfo: {0}\r\n", extra); } sb.Append("\r\n\r\n"); string message = sb.ToString(); if (message != previousMessage) { if (repeatcount > 1) { WriteToFile(string.Format("\r\nPrevious message written {0} times\r\n", repeatcount)); } previousMessage = message; repeatcount = 0; WriteToFile(message); } else { repeatcount++; } exceptionCount++; if (exceptionCount % 10 == 0) { long totmem = 0; Task t = Task.Factory.StartNew( () => { Thread.CurrentThread.Name = "Log Memory Use"; try { totmem = GC.GetTotalMemory(true); float privateMB = Process.GetCurrentProcess().PrivateMemorySize64 / 1000000f; DebugMessageLogger.LogEvent("Exception count: {0} Private Bytes Usage: {1} MB, GC: {2} MB", exceptionCount, privateMB.ToString("n"), (totmem / 1000000f).ToString("n")); } catch (Exception eeex) { } } ); //t.Wait(200); //Calculate Memoryusage //if (exceptionCount % 50 == 0) //{ // if ((DateTime.Now - _LastHDDCheckTime).TotalSeconds > 300) // { // _LastHDDCheckTime = DateTime.Now; // // check DB HDD // Task.Factory.StartNew(() => // { // try // { // long res = Useful.CheckHDDSize.HowMuchDBSpaceLeft(); // if (res != -1 && (res / (1 << 30)) < 1) // { // LogEventLevel("################## WARNING < 1 GB DB Space Available ####################", 0); // } // if (CheckHDDSize.DBDrive != null) // LogEventLevel("Database Drive " + CheckHDDSize.DBDrive.RootDirectory + " has " + (res / (1024 * 1024)).ToString() + "Mb space left", 0); // } // catch (Exception er) // { // Kinesense.Interfaces.DebugMessageLogger.LogError(er); // } // }); // // Check temp HDD // Task.Factory.StartNew(() => // { // try // { // long res = Useful.CheckHDDSize.HowMuchTEMPSpaceLeft(); // if (res != -1 && (res / (1 << 30)) < 1) // { // LogEventLevel("################## WARNING < 1 GB DB Space Available ####################", 0); // } // if (CheckHDDSize.TEMPDrive != null) // LogEventLevel("Temp Drive " + CheckHDDSize.TEMPDrive.RootDirectory + " has " + (res / (1024 * 1024)).ToString() + "Mb space left", 0); // } // catch (Exception er) // { // Kinesense.Interfaces.DebugMessageLogger.LogError(er); // } // }); // } //} } else if (e is System.OutOfMemoryException || (e.InnerException != null && e.InnerException is System.OutOfMemoryException)) { if ((DateTime.Now - _MostRecentMemoryTest).TotalSeconds > 60) { long totmem = 0; Task t = Task.Factory.StartNew(() => { totmem = GC.GetTotalMemory(true); float privateMB = Process.GetCurrentProcess().PrivateMemorySize64 / 1000000f; DebugMessageLogger.LogEvent("OutOfMemoryException Private Bytes Usage: {0} MB, GC: {1} MB", privateMB.ToString("n"), (totmem / 1000000f).ToString("n")); }); t.Wait(200); _MostRecentMemoryTest = DateTime.Now; } //Calculate Memoryusage } } catch (Exception ee) { //System.Windows.MessageBox.Show(ee.Message); } finally { Thread.CurrentThread.CurrentCulture = _currentculture; } }
/// <summary> /// This method looks for the index at the end of the frame packet. This should be in the format DateTime.Int /// following a final "--videoboundary" /// </summary> /// <param name="buffer"></param> /// <param name="stampA"></param> /// <param name="stampB"></param> /// <returns></returns> public static List <KeyValuePair <DateTime, int> > GetTimeStampsFromFrameIndex(byte[] buffer, DateTime start, TimeSpan duration) { List <KeyValuePair <DateTime, int> > times = new List <KeyValuePair <DateTime, int> >(); long utcmask = ((long)DateTimeKind.Utc << 62); long localantimask = ~((long)DateTimeKind.Local << 62); DateTime end = start + duration; //this is because the gob start time from the db can be slightly off the first frame time DateTime startLimit = start.AddSeconds(-120); DateTime endLimit = end.AddSeconds(120); TimeSpan?offset = null; //long unspmask = ~((long)3 << 62); try { ASCIIEncoding encoder = new ASCIIEncoding(); string stamp = "--videoboundary--"; byte[] stampbytes = encoder.GetBytes(stamp); int index_of_index = -1; int pos = buffer.Length; while (index_of_index == -1 && pos > 0) { pos -= 5000; index_of_index = ByteArrayUtils.IndexOf(buffer, stampbytes, pos, buffer.Length - pos); } if (index_of_index == -1) { throw new IOException("Invalid buffer"); } pos = index_of_index + stampbytes.Length; while (pos < buffer.Length - 12) { long bytes = BitConverter.ToInt64(buffer, pos); bytes = bytes | utcmask; bytes = bytes & localantimask; //bytes = bytes & unspmask; DateTime time = DateTime.FromBinary(bytes); //this fixes the timezone issue //time = ChangeDateTimeKind(time, DateTimeKind.Utc); //rationality check, for timezone and daylight savings problems if (time < startLimit || time > endLimit) { if (offset.HasValue == false) { long roundedticks = (long)((time.Ticks / 10000) * 10000); long diff = time.Ticks - roundedticks; if (diff > 5000) ///to unround the number (workaround for a bug on some pcs) { roundedticks += 10000; } DateTime roundedTime = new DateTime(roundedticks); //assume first frame offset = start - roundedTime; DebugMessageLogger.LogEvent("Time is off in this Frame Packet - adjusting by {0}", offset); } time = time + offset.Value; } int bytepos = BitConverter.ToInt32(buffer, pos + 8); //sometimes there are blank bytes at the end of the file. Don't record these as index entries. //if (bytepos > 0) times.Add(new KeyValuePair <DateTime, int>(time, bytepos)); pos += 12; } } catch (Exception ee) { DebugMessageLogger.LogError(ee); } return(times); }