public void RefreshData(CrawledMemorySnapshot unpackedCrawl) { _unpacked = unpackedCrawl; _types.Clear(); foreach (ThingInMemory thingInMemory in _unpacked.allObjects) { string typeName = MemUtil.GetGroupName(thingInMemory); if (typeName.Length == 0) { continue; } MemType theType; if (!_types.ContainsKey(typeName)) { theType = new MemType(); theType.TypeName = MemUtil.GetCategoryLiteral(thingInMemory) + typeName; theType.Category = MemUtil.GetCategory(thingInMemory); theType.Objects = new List <object>(); _types.Add(typeName, theType); } else { theType = _types[typeName]; } MemObject item = new MemObject(thingInMemory, _unpacked); theType.AddObject(item); } RefreshTables(); }
MemType _checkNewTypes(ThingInMemory things, string diffType) { string TypeName = MemUtil.GetGroupName(things); if (TypeName.Length == 0 || things == null || TypeName.Contains(sDiffType.AdditiveType)) { return(null); } string diffTypeName = MemUtil.GetCategoryLiteral(things) + TypeName + diffType; MemType theType; if (!_types.ContainsKey(diffTypeName)) { theType = new MemType(); theType.TypeName = diffTypeName; theType.Category = MemUtil.GetCategory(things); theType.Objects = new List <object>(); _types.Add(diffTypeName, theType); } else { theType = _types[diffTypeName]; } return(theType); }
async Task SaveMemory() { // Close the Popup ShowPopup = false; // Get the current user var user = (await authenticationStateTask).User; // A new forecast will have the Id set to 0 if (objMemories.Id == 0) { MemType objMemType = new MemType(); // Create new forecast Memories objNewMemories = new Memories(); objNewMemories.memDate = System.DateTime.Now; objNewMemories.memType = TypeOfMemories.ToString(); objNewMemories.memText = objMemories.memText; objNewMemories.UserName = user.Identity.Name; // Save the result var result = @Service.CreateMemoriesAsync(objNewMemories); } else { // This is an update var result = @Service.UpdateMemoriesAsync(objMemories); } // Get the forecasts for the current user memories = await @Service.GetMemoriesAsync(user.Identity.Name); }
public void RefreshTables() { if (_unpacked == null) { return; } List <object> qualified = new List <object>(); foreach (var p in _types) { MemType mt = p.Value; // skip this type if category mismatched if (_memTypeCategory != 0 && _memTypeCategory != mt.Category) { continue; } if (!MemUtil.MatchSizeLimit(mt.Size, _memTypeSizeLimiter)) { continue; } qualified.Add(mt); } _typeTable.RefreshData(qualified); _objectTable.RefreshData(null); }
public void SelectThing(ThingInMemory thing) { if (_searchInstanceString == "") { string typeName = MemUtil.GetGroupName(thing); MemType mt = null; if (!_types.TryGetValue(typeName, out mt)) { return; } if (_typeTable.GetSelected() != mt) { _typeTable.SetSelected(mt); _objectTable.RefreshData(mt.Objects); } foreach (var item in mt.Objects) { var mo = item as MemObject; if (mo != null && mo._thing == thing) { if (_objectTable.GetSelected() != mo) { _objectTable.SetSelected(mo); } break; } } } }
public static Dictionary <string, MemType> PopulateTypes(CrawledMemorySnapshot snapshot) { var types = new Dictionary <string, MemType>(); foreach (ThingInMemory thingInMemory in snapshot.allObjects) { string typeName = MemUtil.GetGroupName(thingInMemory); if (typeName.Length == 0) { continue; } MemType theType; if (!types.TryGetValue(typeName, out theType)) { theType = new MemType(); theType.TypeName = MemUtil.GetCategoryLiteral(thingInMemory) + typeName; theType.Category = MemUtil.GetCategory(thingInMemory); theType.Objects = new List <object>(); types.Add(typeName, theType); } MemObject item = new MemObject(thingInMemory, snapshot); theType.Size += item.Size; theType.Count++; theType.Objects.Add(item); } return(types); }
private void MenuSelectMemory_Click(object sender, RoutedEventArgs e) { foreach (var item in MenuSelectMemory.Items) { if (item is MenuItem menu) { menu.IsChecked = false; } } var mi = sender as MenuItem; mi.IsChecked = true; var menuheader = mi.Header.ToString(); if (menuheader == "Flash") { _selectedMemory = MemType.Flash; TabControl1.SelectedIndex = 0; } else if (menuheader == "EEPROM") { _selectedMemory = MemType.EEPROM; TabControl1.SelectedIndex = 1; } else if (menuheader == "All") { _selectedMemory = MemType.ALL; } }
void setUnchangedThings(ThingInMemory thingInMemory) { string typeName = MemUtil.GetGroupName(thingInMemory); if (typeName.Length == 0) { return; } int category = MemUtil.GetCategory(thingInMemory); MemObject item = new MemObject(thingInMemory, _unpacked); if (!_staticDetailInfo.isDetailStaticFileds(typeName, thingInMemory.caption, item.Size)) { MemType theType; Dictionary <string, MemType> unchangedDict; _diffDicts.TryGetValue(sDiffDictKey.unchangedDict, out unchangedDict); if (!unchangedDict.ContainsKey(typeName)) { theType = new MemType(); theType.TypeName = MemUtil.GetCategoryLiteral(thingInMemory) + typeName; theType.Category = category; theType.Objects = new List <object>(); unchangedDict.Add(typeName, theType); } else { theType = unchangedDict[typeName]; } theType.AddObject(item); } }
public static Dictionary <string, MemType> DiffTypes(Dictionary <string, MemType> types1st, Dictionary <string, MemType> types2nd) { Dictionary <string, int> unifiedKeys = new Dictionary <string, int>(); foreach (var p in types1st) { if (!unifiedKeys.ContainsKey(p.Key)) { unifiedKeys.Add(p.Key, p.Value.Category); } } foreach (var p in types2nd) { if (!unifiedKeys.ContainsKey(p.Key)) { unifiedKeys.Add(p.Key, p.Value.Category); } } var retTypes = new Dictionary <string, MemType>(); foreach (var p in unifiedKeys) { var dummyType = new MemType(); dummyType.TypeName = p.Key; dummyType.Category = p.Value; dummyType.Objects = new List <object>(); dummyType.Size = 0; dummyType.Count = 0; // add the dummy one if not exists in either 1st or 2nd if (!types1st.ContainsKey(p.Key)) { types1st.Add(p.Key, dummyType); } if (!types2nd.ContainsKey(p.Key)) { types2nd.Add(p.Key, dummyType); } var t1 = types1st[p.Key]; var t2 = types2nd[p.Key]; // here we reuse the dummy type for the combined output type var diffedType = dummyType; diffedType.Size = t2.Size - t1.Size; diffedType.Count = t2.Count - t1.Count; if (diffedType.Size == 0 && diffedType.Count == 0) { continue; } diffedType.Objects = MemObjectInfoSet.Diff(t1.Objects, t2.Objects); retTypes[p.Key] = diffedType; } return(retTypes); }
public void RefreshTables() { if (_unpacked == null) { return; } if (string.IsNullOrEmpty(_searchString)) { List <object> qualified = new List <object>(); foreach (var p in _types) { MemType mt = p.Value; // skip this type if category mismatched if (_memTypeCategory != 0 && _memTypeCategory != mt.Category) { continue; } if (!MemUtil.MatchSizeLimit(mt.Size, _memTypeSizeLimiter)) { continue; } qualified.Add(mt); } _typeTable.RefreshData(qualified); _objectTable.RefreshData(null); } else { _types.Remove(MemConst.SearchResultTypeString); _searchResultType = new MemType(); _searchResultType.TypeName = MemConst.SearchResultTypeString + " " + _searchString; _searchResultType.Category = 0; _searchResultType.Objects = new List <object>(); string search = _searchString.ToLower(); foreach (ThingInMemory thingInMemory in _unpacked.allObjects) { if (thingInMemory.caption.ToLower().Contains(search)) { _searchResultType.AddObject(new MemObject(thingInMemory, _unpacked)); } } _types.Add(MemConst.SearchResultTypeString, _searchResultType); List <object> qualified = new List <object>(); qualified.Add(_searchResultType); _typeTable.RefreshData(qualified); _objectTable.RefreshData(_searchResultType.Objects); } }
void OnTypeSelected(object selected, int col) { MemType mt = selected as MemType; if (mt == null) { return; } _objectTable.RefreshData(mt.Objects); }
public void RefreshData(CrawledMemorySnapshot unpackedCrawl) { _unpacked = unpackedCrawl; resetDiffDicts(); _categories.Clear(); _staticDetailInfo.clear(); foreach (ThingInMemory thingInMemory in _unpacked.allObjects) { string typeName = MemUtil.GetGroupName(thingInMemory); if (typeName.Length == 0) { continue; } int category = MemUtil.GetCategory(thingInMemory); MemObject item = new MemObject(thingInMemory, _unpacked); if (!_staticDetailInfo.isDetailStaticFileds(typeName, thingInMemory.caption, item.Size)) { MemType theType; Dictionary <string, MemType> unchangedDict; _diffDicts.TryGetValue(sDiffDictKey.unchangedDict, out unchangedDict); if (!unchangedDict.ContainsKey(typeName)) { theType = new MemType(); theType.TypeName = MemUtil.GetCategoryLiteral(thingInMemory) + typeName; theType.Category = category; theType.Objects = new List <object>(); unchangedDict.Add(typeName, theType); } else { theType = unchangedDict[typeName]; } theType.AddObject(item); } MemCategory theCategory; if (!_categories.TryGetValue(category, out theCategory)) { theCategory = new MemCategory(); theCategory.Category = category; _categories.Add(category, theCategory); } theCategory.Size += item.Size; theCategory.Count++; } calculateCategoryInfo(); RefreshTables(); }
private static bool CheckMemType(MEM actualType, MemType flags) { switch (actualType) { case MEM.PRIVATE: return((flags & MemType.Private) != 0); case MEM.IMAGE: return((flags & MemType.Image) != 0); case MEM.MAPPED: return((flags & MemType.Mapped) != 0); default: if (flags == MemType.All) { return(true); } throw new InvalidOperationException("Unknown/Bogus Memory Type!"); } }
public void RefreshTables() { if (_unpacked == null) { return; } List <object> qualified = new List <object>(); // search for instances if (!string.IsNullOrEmpty(_searchInstanceString)) { _types.Remove(MemConst.SearchResultTypeString); _searchResultType = new MemType(); _searchResultType.TypeName = MemConst.SearchResultTypeString + " " + _searchInstanceString; _searchResultType.Category = 0; _searchResultType.Objects = new List <object>(); string search = _searchInstanceString.ToLower(); foreach (ThingInMemory thingInMemory in _unpacked.allObjects) { if (thingInMemory.caption.ToLower().Contains(search)) { _searchResultType.AddObject(new MemObject(thingInMemory, _unpacked)); } } _types.Add(MemConst.SearchResultTypeString, _searchResultType); qualified.Add(_searchResultType); _typeTable.RefreshData(qualified, getSpecialColorDict(qualified)); _objectTable.RefreshData(_searchResultType.Objects); return; } // search for types if (!string.IsNullOrEmpty(_searchTypeString)) { foreach (var p in _types) { MemType mt = p.Value; if (mt.TypeName.ToLower().Contains(_searchTypeString.ToLower())) { qualified.Add(mt); } } _typeTable.RefreshData(qualified, getSpecialColorDict(qualified)); _objectTable.RefreshData(null); return; } // ordinary case - list categorized types and instances foreach (var p in _types) { MemType mt = p.Value; bool isAll = _memTypeCategory == 0; bool isNative = _memTypeCategory == 1 && mt.Category == 1; bool isManaged = _memTypeCategory == 2 && mt.Category == 2; bool isOthers = _memTypeCategory == 3 && (mt.Category == 3 || mt.Category == 4); if (isAll || isNative || isManaged || isOthers) { if (MemUtil.MatchSizeLimit(mt.Size, _memTypeSizeLimiter)) { qualified.Add(mt); } } } _typeTable.RefreshData(qualified, getSpecialColorDict(qualified)); _objectTable.RefreshData(null); }
public static void ShowStringStats(MemType mt) { Dictionary <string, int> counter = new Dictionary <string, int>(); int pathCount = 0; int winPathCount = 0; StringBuilder sb = new StringBuilder(); foreach (var obj in mt.Objects) { MemObject mo = obj as MemObject; if (mo != null) { if (mo.InstanceName.Split(new char[] { '/' }).Length >= 3) { pathCount++; } if (mo.InstanceName.Split(new char[] { '\\' }).Length >= 3) { sb.AppendFormat(" {0}\n", mo.InstanceName); winPathCount++; } if (counter.ContainsKey(mo.InstanceName)) { counter[mo.InstanceName]++; } else { counter.Add(mo.InstanceName, 1); } } } UnityEngine.Debug.LogFormat("path: {0}, winPath: {1}", pathCount, winPathCount); UnityEngine.Debug.LogFormat("all win paths: \n{0}", sb.ToString()); List <KeyValuePair <int, string> > lines = new List <KeyValuePair <int, string> >(); foreach (var p in counter) { if (p.Value >= 2) { lines.Add(new KeyValuePair <int, string>(p.Value, p.Key)); } } lines.Sort((x, y) => x.Key.CompareTo(y.Key) * -1); // would sort all results from the largest to the smallest if (lines.Count > 100) { lines.RemoveRange(100, lines.Count - 100); } UnityEngine.Debug.Log("----- string repetitions -----"); foreach (var line in lines) { try { UnityEngine.Debug.LogFormat(" {0, 5} {1}\n", line.Key, line.Value); } catch (System.Exception ex) { UnityEngine.Debug.LogFormat(" {0, 5} {1}: {2}\n", line.Key, "<invalid string>", ex.Message); } } }
public void RefreshData(CrawledMemorySnapshot unpackedCrawl, CrawledMemorySnapshot preUnpackedCrawl = null) { _unpacked = unpackedCrawl; _preUnpacked = preUnpackedCrawl; _types.Clear(); _categories.Clear(); _staticDetailInfo.clear(); foreach (ThingInMemory thingInMemory in _unpacked.allObjects) { string typeName = MemUtil.GetGroupName(thingInMemory); if (typeName.Length == 0) { continue; } int category = MemUtil.GetCategory(thingInMemory); MemObject item = new MemObject(thingInMemory, _unpacked); if (!_staticDetailInfo.isDetailStaticFileds(typeName, thingInMemory.caption, item.Size)) { MemType theType; if (!_types.ContainsKey(typeName)) { theType = new MemType(); theType.TypeName = MemUtil.GetCategoryLiteral(thingInMemory) + typeName; theType.Category = category; theType.Objects = new List <object>(); _types.Add(typeName, theType); } else { theType = _types[typeName]; } theType.AddObject(item); } MemCategory theCategory; if (!_categories.TryGetValue(category, out theCategory)) { theCategory = new MemCategory(); theCategory.Category = category; _categories.Add(category, theCategory); } theCategory.Size += item.Size; theCategory.Count++; } int[] sizes = new int[MemConst.MemTypeCategories.Length]; int[] counts = new int[MemConst.MemTypeCategories.Length]; foreach (var item in _categories) { sizes[0] += item.Value.Size; counts[0] += item.Value.Count; if (item.Key == 1) { sizes[1] += item.Value.Size; counts[1] += item.Value.Count; } else if (item.Key == 2) { sizes[2] += item.Value.Size; counts[2] += item.Value.Count; } else { sizes[3] += item.Value.Size; counts[3] += item.Value.Count; } } for (int i = 0; i < _categoryLiterals.Length; i++) { _categoryLiterals[i] = string.Format("{0} ({1}, {2})", MemConst.MemTypeCategories[i], counts[i], EditorUtility.FormatBytes(sizes[i])); } freshUnpackInfos(); checkAddtiveThings(); checkNegativeThings(); RefreshTables(); }
public static void ShowTypeStats(MemType mt) { if (mt == null) { Debug.LogError("invalid type, ignored."); return; } if (mt.TypeName.EndsWith("System.String")) // this would excludes 'System.String[]' { ShowStringStats(mt); } // accumulate by 'referenced by' types Dictionary <string, HashSet <MemObject> > referenceMap = new Dictionary <string, HashSet <MemObject> >(); foreach (var obj in mt.Objects) { MemObject mo = obj as MemObject; if (mo != null && mo._thing != null) { foreach (var referencer in mo._thing.referencedBy) { string referencerTypeName = MemUtil.GetGroupName(referencer); HashSet <MemObject> things; if (!referenceMap.TryGetValue(referencerTypeName, out things)) { things = new HashSet <MemObject>(); referenceMap[referencerTypeName] = things; } things.Add(mo); } } } List <KeyValuePair <int, string> > lines = new List <KeyValuePair <int, string> >(); foreach (var p in referenceMap) { HashSet <MemObject> objects = p.Value; int totalSize = 0; foreach (var obj in objects) { totalSize += obj.Size; } lines.Add(new KeyValuePair <int, string>(objects.Count, string.Format("<{0, 80}> {1, 10}, {2, 10}", p.Key, objects.Count, EditorUtility.FormatBytes(totalSize)))); } lines.Sort((x, y) => x.Key.CompareTo(y.Key) * -1); // would sort all results from the largest to the smallest StringBuilder sb = new StringBuilder(); sb.AppendFormat("----- <type: {0}> -----\n", mt.TypeName); sb.AppendFormat(" {0} objects ({1}) are referenced by {2} types listed below:\n", mt.Objects.Count, mt.SizeLiterally, lines.Count); sb.AppendFormat("-----------------------\n"); sb.AppendFormat("<{0, 80}> {1, 10}, {2, 10}\n", "type", "count", "size"); sb.AppendFormat("<{0, 80}> {1, 10}, {2, 10}\n", "----", "-----", "----"); foreach (var line in lines) { sb.AppendLine(line.Value); } UnityEngine.Debug.Log(sb.ToString()); }
private string resolvePackedForJson(CrawledMemorySnapshot packed) { if (packed == null) { return(null); } var _unpacked = packed; _types.Clear(); _categories.Clear(); foreach (ThingInMemory thingInMemory in packed.allObjects) { string typeName = MemUtil.GetGroupName(thingInMemory); if (typeName.Length == 0) { continue; } int category = MemUtil.GetCategory(thingInMemory); MemObject item = new MemObject(thingInMemory, _unpacked); MemType theType; if (!_types.ContainsKey(typeName)) { theType = new MemType(); theType.TypeName = MemUtil.GetCategoryLiteral(thingInMemory) + typeName; theType.Category = category; theType.Objects = new List <object>(); _types.Add(typeName, theType); } else { theType = _types[typeName]; } theType.AddObject(item); } //协议格式: //Data: //"obj" = "TypeName,Category,Count,size" //"info" ="RefCount,size,InstanceName,address,typeDescriptionIndex" //TypeDescs: //InstanceNames: Dictionary <int, string> typeDescDict = new Dictionary <int, string>(); Dictionary <int, string> instanceNameDict = new Dictionary <int, string>(); var jsonData = new JsonData(); foreach (var type in _types) { var typeData = new JsonData(); typeData["Obj"] = type.Key + "," + type.Value.Category + "," + type.Value.Count + "," + type.Value.Size; var objectDatas = new JsonData(); foreach (var obj in type.Value.Objects) { var objectData = new JsonData(); var memObj = obj as MemObject; string dataInfo; var instanceNameHash = memObj.InstanceName.GetHashCode(); if (!instanceNameDict.ContainsKey(instanceNameHash)) { instanceNameDict.Add(instanceNameHash, memObj.InstanceName); } dataInfo = memObj.RefCount + "," + memObj.Size + "," + instanceNameDict[instanceNameHash]; if (type.Value.Category == 2) { var manged = memObj._thing as ManagedObject; var typeDescriptionHash = manged.typeDescription.name.GetHashCode(); if (!typeDescDict.ContainsKey(typeDescriptionHash)) { typeDescDict.Add(typeDescriptionHash, manged.typeDescription.name); } dataInfo += "," + Convert.ToString((int)manged.address, 16) + "," + typeDescriptionHash; } objectData["info"] = dataInfo; objectDatas.Add(objectData); } typeData["memObj"] = objectDatas; jsonData.Add(typeData); } var resultJson = new JsonData(); resultJson["Data"] = jsonData; StringBuilder sb = new StringBuilder(); foreach (var key in typeDescDict.Keys) { sb.Append("[[" + key + "]:" + typeDescDict[key] + "],"); } resultJson["TypeDescs"] = sb.ToString(); sb.Remove(0, sb.Length); foreach (var key in instanceNameDict.Keys) { sb.Append("[[" + key + "]:" + instanceNameDict[key] + "],"); } resultJson["InstanceNames"] = sb.ToString(); return(resultJson.ToJson()); }
public LocLabel( string name, MemType t ) : base(t) { Label = name; }
public Loc( MemType t ) { Type = t; }
public LocRegOffset( int reg, int off, MemType t ) : base(t) { Reg = reg; Offset = off; }
public LocRegIndex( int reg, int index, MemType t ) : base(t) { Reg = reg; IndexReg = index; }