예제 #1
0
        public async Task <IActionResult> PutGcType([FromRoute] int id, [FromBody] GcType GcType)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != GcType.Id)
            {
                return(BadRequest());
            }

            GcType.ModifiedDate   = DateTime.Now;
            GcType.LastModifiedBy = "leila";

            _context.Entry(GcType).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!GcTypeExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
예제 #2
0
 // remeber type and roots
 protected override void VisitType(int id, string name)
 {
     GcType type = new GcType(id, name);
   
     this.types.Add(type.ID, type);
     this.graph.AddVertex(type);
 }
 private void AddTypeEdge(GcType source, GcType target)
 {
     GcTypeEdge edge;
     if (!this.graph.TryGetEdge(source, target, out edge))
         this.graph.AddEdge(edge = new GcTypeEdge(source, target));
     edge.Count++;
 }
예제 #4
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,LastModifiedBy,CreatedDate,ModifiedDate,Name,Active")] GcType gcType)
        {
            if (id != gcType.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(gcType);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!GcTypeExists(gcType.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(gcType));
        }
예제 #5
0
        internal void GetOrCreateGcType(int typeID)
        {
            GcType t;

            if (!typeIdToGcType.TryGetValue(typeID, out t))
            {
                string typeName = readNewLog.typeName[typeID];
                t = new GcType(typeName, typeID);
                typeIdToGcType[typeID] = t;
            }
        }
예제 #6
0
        public async Task <IActionResult> Create([Bind("Id,LastModifiedBy,CreatedDate,ModifiedDate,Name,Active")] GcType gcType)
        {
            if (ModelState.IsValid)
            {
                _context.Add(gcType);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(gcType));
        }
예제 #7
0
        internal GcType GetOrCreateGcType(string typeName)
        {
            Debug.Assert(typeName != null);
            GcType t = (GcType)typeNameToGcType[typeName];

            if (t == null)
            {
                t = new GcType(typeName);
                typeNameToGcType[typeName] = t;
            }
            return(t);
        }
예제 #8
0
        internal int GetOrCreateGcType(string typeName)
        {
            Debug.Assert(typeName != null);
            GcType t;

            if (!typeNameToGcType.TryGetValue(typeName, out t))
            {
                internalTypeCount++;
                int typeID = -internalTypeCount;
                t = new GcType(typeName, typeID);
                typeNameToGcType[typeName] = t;
                typeIdToGcType[typeID]     = t;
            }
            return(t.typeID);
        }
예제 #9
0
        public async Task <IActionResult> PostGcType([FromBody] GcType GcType)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            GcType.CreatedDate    = DateTime.Now;
            GcType.ModifiedDate   = DateTime.Now;
            GcType.LastModifiedBy = "leila";

            _context.GcType.Add(GcType);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetGcType", new { id = GcType.Id }, GcType));
        }
예제 #10
0
            public int CompareTo(Object o)
            {
                GcType t = (GcType)o;

                if (t.cumulativeSize < this.cumulativeSize)
                {
                    return(-1);
                }
                else if (t.cumulativeSize > this.cumulativeSize)
                {
                    return(1);
                }
                else
                {
                    return(0);
                }
            }
예제 #11
0
        internal Graph BuildTypeGraph1()
        {
            Graph graph = new Graph(this);

            graph.graphType = Graph.GraphType.HeapGraph;

            GcType   rootType   = GetOrCreateGcType("<root>");
            GcObject rootObject = GetOrCreateObject(0);

            rootObject.type       = rootType;
            rootObject.references = roots;

            foreach (GcObject gcObject in idToObject.Values)
            {
                rootObject.size += gcObject.size;
                if (gcObject.references != null)
                {
                    Vertex fromVertex = graph.FindOrCreateVertex(gcObject.type.name, null);

                    foreach (GcObject toObject in gcObject.references)
                    {
                        Vertex toVertex = graph.FindOrCreateVertex(toObject.type.name, null);
                        graph.FindOrCreateEdge(fromVertex, toVertex);
                    }
                }
            }

            CalculateWeightsNonTransitive(graph);

            foreach (Vertex v in graph.vertices.Values)
            {
                v.active = true;
            }
            graph.BottomVertex.active = false;

            return(graph);
        }
예제 #12
0
            public int CompareTo(Object o)
            {
                GcType t = (GcType)o;

                return(t.cumulativeSize - this.cumulativeSize);
            }
예제 #13
0
        internal Graph BuildTypeGraph()
        {
            if (graph == null || FilterForm.filterVersion != graphFilterVersion)
            {
                graph              = new Graph(this);
                graph.graphType    = Graph.GraphType.HeapGraph;
                graphFilterVersion = FilterForm.filterVersion;
            }
            else
            {
                foreach (Vertex v in graph.vertices.Values)
                {
                    if (v.weightHistory == null)
                    {
                        v.weightHistory = new int[1];
                    }
                    else
                    {
                        int[] weightHistory = v.weightHistory;
                        if (weightHistory.Length < historyDepth)
                        {
                            v.weightHistory = new int[weightHistory.Length + 1];
                        }
                        for (int i = v.weightHistory.Length - 1; i > 0; i--)
                        {
                            v.weightHistory[i] = weightHistory[i - 1];
                        }
                    }
                    v.weightHistory[0] = v.weight;
                    v.weight           = v.incomingWeight = v.outgoingWeight = v.basicWeight = v.count = 0;
                    foreach (Edge e in v.outgoingEdges.Values)
                    {
                        e.weight = 0;
                    }
                }
            }

            GcType   rootType   = GetOrCreateGcType("<root>");
            GcObject rootObject = GetOrCreateObject(0);

            rootObject.type       = rootType;
            rootObject.references = roots;

            foreach (GcObject gcObject in idToObject.Values)
            {
                gcObject.level  = int.MaxValue;
                gcObject.vertex = null;
            }

            AssignLevel(null, rootObject, 0);

            AssignInterestLevels();

            int index = 0;

            foreach (GcType gcType in typeNameToGcType.Values)
            {
                gcType.index = index++;
            }
            GcType[] gcTypes = new GcType[index];
            typeHintTable = new int[index];

            foreach (GcType gcType in typeNameToGcType.Values)
            {
                gcTypes[gcType.index] = gcType;
            }

            Vertex[] pathFromRoot = new Vertex[32];
            foreach (GcObject gcObject in idToObject.Values)
            {
                if (gcObject.level == int.MaxValue ||
                    (gcObject.interestLevel & (InterestLevel.Interesting | InterestLevel.Display)) == InterestLevel.Ignore)
                {
                    continue;
                }

                while (pathFromRoot.Length < gcObject.level + 1)
                {
                    pathFromRoot = new Vertex[pathFromRoot.Length * 2];
                }

                for (GcObject pathObject = gcObject; pathObject != null; pathObject = pathObject.parent)
                {
                    if ((pathObject.interestLevel & (InterestLevel.Interesting | InterestLevel.Display)) == InterestLevel.Ignore)
                    {
                        pathFromRoot[pathObject.level] = null;
                    }
                    else
                    {
                        pathFromRoot[pathObject.level] = FindVertex(pathObject, graph);
                    }
                }

                int levels = 0;
                for (int i = 0; i <= gcObject.level; i++)
                {
                    if (pathFromRoot[i] != null)
                    {
                        pathFromRoot[levels++] = pathFromRoot[i];
                    }
                }

                levels = Vertex.SqueezeOutRepetitions(pathFromRoot, levels);

                for (int i = 0; i < levels - 1; i++)
                {
                    Vertex fromVertex = pathFromRoot[i];
                    Vertex toVertex   = pathFromRoot[i + 1];
                    Edge   edge       = graph.FindOrCreateEdge(fromVertex, toVertex);
                    edge.AddWeight(gcObject.size);
                }

                Vertex thisVertex = pathFromRoot[levels - 1];
                thisVertex.basicWeight += gcObject.size;
                thisVertex.count       += 1;
            }

            foreach (Vertex v in graph.vertices.Values)
            {
                if (v.weight < v.outgoingWeight)
                {
                    v.weight = v.outgoingWeight;
                }
                if (v.weight < v.incomingWeight)
                {
                    v.weight = v.incomingWeight;
                }
                if (v.weightHistory == null)
                {
                    v.weightHistory = new int[1];
                }
            }

            foreach (Vertex v in graph.vertices.Values)
            {
                v.active = true;
            }
            graph.BottomVertex.active = false;

            return(graph);
        }
예제 #14
0
        private Vertex FindVertex(GcObject gcObject, Graph graph)
        {
            if (gcObject.vertex != null)
            {
                return(gcObject.vertex);
            }
            string signature = null;

            if (gcObject.parent != null)
            {
                StringBuilder sb = new StringBuilder();
                sb.Append(gcObject.parent.type.name);
                sb.Append("->");
                sb.Append(gcObject.type.name);
                if (gcObject.references != null)
                {
                    sb.Append("->(");

                    ArrayList al              = new ArrayList();
                    string    separator       = "";
                    const int MAXREFTYPECOUNT = 3;
                    int       refTypeCount    = 0;
                    for (int i = 0; i < gcObject.references.Length; i++)
                    {
                        GcObject refObject = gcObject.references[i];
                        GcType   refType   = refObject.type;
                        if (typeHintTable[refType.index] < i && gcObject.references[typeHintTable[refType.index]].type == refType)
                        {
                            ;                                   // we already found this type - ignore further occurrences
                        }
                        else
                        {
                            typeHintTable[refType.index] = i;
                            refTypeCount++;
                            if (refTypeCount <= MAXREFTYPECOUNT)
                            {
                                al.Add(refType.name);
                            }
                            else
                            {
                                break;
                            }
                        }
                    }
                    al.Sort();
                    foreach (string typeName in al)
                    {
                        sb.Append(separator);
                        separator = ",";
                        sb.Append(typeName);
                    }

                    if (refTypeCount > MAXREFTYPECOUNT)
                    {
                        sb.Append(",...");
                    }

                    sb.Append(")");

                    signature = sb.ToString();
                }
            }

            gcObject.vertex = graph.FindOrCreateVertex(gcObject.type.name, signature);

            return(gcObject.vertex);
        }
예제 #15
0
        internal Graph BuildTypeGraph(int allocatedAfterTickIndex, int allocatedBeforeTickIndex, BuildTypeGraphOptions options, FilterForm filterForm)
        {
            Graph graph;

            if (filterForm.filterVersion != 0 ||
                options != BuildTypeGraphOptions.LumpBySignature ||
                allocatedAfterTickIndex > 0 ||
                allocatedBeforeTickIndex < int.MaxValue)
            {
                graph           = new Graph(this);
                graph.graphType = Graph.GraphType.HeapGraph;
                graph.previousGraphTickIndex = allocatedAfterTickIndex;
            }
            else
            {
                Graph previousGraph = cachedGraph;
                if (previousGraph != null && previousGraph.graphSource == this)
                {
                    return(previousGraph);
                }
                cachedGraph       = graph = new Graph(this);
                graph.graphType   = Graph.GraphType.HeapGraph;
                graph.graphSource = this;
                if (previousGraph != null)
                {
                    graph.previousGraphTickIndex = ((ObjectGraph)previousGraph.graphSource).tickIndex;
                    foreach (Vertex v in previousGraph.vertices.Values)
                    {
                        Vertex newV = graph.FindOrCreateVertex(v.name, v.signature, v.moduleName);
                        if (v.weightHistory == null)
                        {
                            newV.weightHistory = new ulong[1];
                        }
                        else
                        {
                            ulong[] weightHistory = v.weightHistory;
                            newV.weightHistory = new ulong[Math.Min(weightHistory.Length + 1, historyDepth)];
                            for (int i = v.weightHistory.Length - 1; i > 0; i--)
                            {
                                newV.weightHistory[i] = weightHistory[i - 1];
                            }
                        }
                        newV.weightHistory[0] = v.weight;
                    }
                }
            }
            graph.typeGraphOptions = options;
            graph.filterVersion    = filterForm.filterVersion;
            if (graph.previousGraphTickIndex < graph.allocatedAfterTickIndex)
            {
                graph.previousGraphTickIndex = graph.allocatedAfterTickIndex;
            }
            graph.allocatedAfterTickIndex  = allocatedAfterTickIndex;
            graph.allocatedBeforeTickIndex = allocatedBeforeTickIndex;

            GcObject rootObject = CreateRootObject();

            for (int i = 0; i < rootCount; i++)
            {
                roots[i].InterestLevel = InterestLevel.Ignore;
            }
            foreach (GcObject gcObject in idToObject.Values)
            {
                gcObject.parent        = null;
                gcObject.vertex        = null;
                gcObject.InterestLevel = InterestLevel.Ignore;
            }

            AssignParents(rootObject);

            int index = 0;

            foreach (GcType gcType in typeIdToGcType.Values)
            {
                gcType.index = index++;
            }
            GcType[] gcTypes = new GcType[index];
            typeHintTable = new int[index];

            foreach (GcType gcType in typeIdToGcType.Values)
            {
                gcTypes[gcType.index] = gcType;
            }

            AssignInterestLevelsToTypes(options, filterForm);
            for (int i = 0; i < rootCount; i++)
            {
                AssignInterestLevelToObject(rootIDs[i], roots[i], options, filterForm);
            }

            foreach (KeyValuePair <ulong, GcObject> keyValuePair in idToObject)
            {
                AssignInterestLevelToObject(keyValuePair.Key, keyValuePair.Value, options, filterForm);
            }
            foreach (GcObject gcObject in idToObject.Values)
            {
                if (gcObject.InterestLevel == InterestLevel.Ignore)
                {
                    CheckForParentMarkingDescendant(gcObject);
                }
            }

            FindVertex(0, rootObject, graph, options);
            for (int i = 0; i < rootCount; i++)
            {
                roots[i].vertex = null;
                FindVertex(rootIDs[i], roots[i], graph, options);
            }

            foreach (KeyValuePair <ulong, GcObject> keyValuePair in idToObject)
            {
                ulong    id       = keyValuePair.Key;
                GcObject gcObject = keyValuePair.Value;
                if (gcObject.parent == null ||
                    (gcObject.InterestLevel & (InterestLevel.Interesting | InterestLevel.Display)) == InterestLevel.Ignore)
                {
                    continue;
                }
                FindVertex(id, gcObject, graph, options);
            }

            Vertex[] pathFromRoot = new Vertex[32];

            foreach (GcObject gcObject in idToObject.Values)
            {
                if (gcObject.parent == null ||
                    (gcObject.InterestLevel & (InterestLevel.Interesting | InterestLevel.Display)) == InterestLevel.Ignore ||
                    gcObject.AllocTickIndex <= allocatedAfterTickIndex ||
                    gcObject.AllocTickIndex >= allocatedBeforeTickIndex)
                {
                    continue;
                }

                int levels = 0;
                for (GcObject pathObject = gcObject; pathObject != null; pathObject = pathObject.parent)
                {
                    if (pathObject.vertex != null)
                    {
                        levels++;
                    }
                }

                while (pathFromRoot.Length < levels + 1)
                {
                    pathFromRoot = new Vertex[pathFromRoot.Length * 2];
                }

                int level = levels;
                for (GcObject pathObject = gcObject; pathObject != null; pathObject = pathObject.parent)
                {
                    if (pathObject.vertex != null)
                    {
                        level--;
                        pathFromRoot[level] = pathObject.vertex;
                    }
                }

                levels = Vertex.SqueezeOutRepetitions(pathFromRoot, levels);

                for (int j = 0; j < levels - 1; j++)
                {
                    Vertex fromVertex = pathFromRoot[j];
                    Vertex toVertex   = pathFromRoot[j + 1];
                    Edge   edge       = graph.FindOrCreateEdge(fromVertex, toVertex);
                    edge.AddWeight(gcObject.Size(this));
                }

                Vertex thisVertex = pathFromRoot[levels - 1];
                thisVertex.basicWeight += gcObject.Size(this);
                thisVertex.count       += 1;
            }

            foreach (Vertex v in graph.vertices.Values)
            {
                if (v.weight < v.outgoingWeight)
                {
                    v.weight = v.outgoingWeight;
                }
                if (v.weight < v.incomingWeight)
                {
                    v.weight = v.incomingWeight;
                }
                if (v.weightHistory == null)
                {
                    v.weightHistory = new ulong[1];
                }
            }

            foreach (Vertex v in graph.vertices.Values)
            {
                v.active = true;
            }
            graph.BottomVertex.active = false;

            return(graph);
        }
예제 #16
0
        internal string SignatureOfObject(ulong id, GcObject gcObject, BuildTypeGraphOptions options)
        {
            StringBuilder sb = new StringBuilder();

            if (gcObject.parent != null)
            {
                switch (options)
                {
                case    BuildTypeGraphOptions.IndividualObjects:
                    if (gcObject.Type(this).name == "Stack" || gcObject.Type(this).name.StartsWith("Stack, "))
                    {
                        if (id < (ulong)readNewLog.funcName.Length)
                        {
                            sb.AppendFormat(readNewLog.funcName[id] + "  " + readNewLog.funcSignature[id]);
                        }
                        else
                        {
                            sb.AppendFormat("Function id = {0}", id);
                        }
                    }
                    else
                    {
                        sb.AppendFormat("Address = {0}, size = {1:n0} bytes", FormatAddress(id), gcObject.Size(this));
                    }
                    break;

                case    BuildTypeGraphOptions.LumpBySignature:
                    sb.Append(gcObject.parent.Type(this).name);
                    sb.Append("->");
                    sb.Append(gcObject.Type(this).name);
                    List <GcObject> references = new List <GcObject>();
                    foreach (GcObject refObject in gcObject.References)
                    {
                        references.Add(refObject);
                    }

                    if (references.Count > 0)
                    {
                        sb.Append("->(");

                        const int     MAXREFTYPECOUNT = 3;
                        List <string> typeNameList    = new List <string>(MAXREFTYPECOUNT);
                        string        separator       = "";
                        int           refTypeCount    = 0;
                        for (int i = 0; i < references.Count; i++)
                        {
                            GcObject refObject = references[i];
                            GcType   refType   = refObject.Type(this);
                            if (typeHintTable[refType.index] < i && references[typeHintTable[refType.index]].Type(this) == refType)
                            {
                                ;       // we already found this type - ignore further occurrences
                            }
                            else
                            {
                                typeHintTable[refType.index] = i;
                                refTypeCount++;
                                if (refTypeCount <= MAXREFTYPECOUNT)
                                {
                                    typeNameList.Add(refType.name);
                                }
                                else
                                {
                                    break;
                                }
                            }
                            i++;
                        }
                        typeNameList.Sort();

                        foreach (string typeName in typeNameList)
                        {
                            sb.Append(separator);
                            separator = ",";
                            sb.Append(typeName);
                        }

                        if (refTypeCount > MAXREFTYPECOUNT)
                        {
                            sb.Append(",...");
                        }

                        sb.Append(")");
                    }
                    break;

                default:
                    Debug.Assert(false);
                    break;
                }
            }
            return(sb.ToString());
        }
예제 #17
0
 public GcMember(GcType referer, int address)
 {
     this.Referer = referer;
     this.Address = address;
 }
예제 #18
0
        internal Vertex FindVertex(GcObject gcObject, Graph graph, BuildTypeGraphOptions options)
        {
            if (gcObject.vertex != null)
            {
                return(gcObject.vertex);
            }
            string        signature = null;
            StringBuilder sb        = new StringBuilder();

            if (gcObject.parent != null)
            {
                switch (options)
                {
                case    BuildTypeGraphOptions.IndividualObjects:
                    sb.AppendFormat("Address = 0x{0:x}, size = {1:n0} bytes", gcObject.id, gcObject.size);
                    break;

                case    BuildTypeGraphOptions.LumpBySignature:
                    sb.Append(gcObject.parent.type.name);
                    sb.Append("->");
                    sb.Append(gcObject.type.name);
                    if (gcObject.references != null)
                    {
                        sb.Append("->(");

                        ArrayList al              = new ArrayList();
                        string    separator       = "";
                        const int MAXREFTYPECOUNT = 3;
                        int       refTypeCount    = 0;
                        for (int i = 0; i < gcObject.references.Length; i++)
                        {
                            GcObject refObject = gcObject.references[i];
                            GcType   refType   = refObject.type;
                            if (typeHintTable[refType.index] < i && gcObject.references[typeHintTable[refType.index]].type == refType)
                            {
                                ;       // we already found this type - ignore further occurrences
                            }
                            else
                            {
                                typeHintTable[refType.index] = i;
                                refTypeCount++;
                                if (refTypeCount <= MAXREFTYPECOUNT)
                                {
                                    al.Add(refType.name);
                                }
                                else
                                {
                                    break;
                                }
                            }
                        }
                        al.Sort();
                        foreach (string typeName in al)
                        {
                            sb.Append(separator);
                            separator = ",";
                            sb.Append(typeName);
                        }

                        if (refTypeCount > MAXREFTYPECOUNT)
                        {
                            sb.Append(",...");
                        }

                        sb.Append(")");
                    }
                    break;

                default:
                    Debug.Assert(false);
                    break;
                }
                signature = sb.ToString();
            }

            gcObject.vertex = graph.FindOrCreateVertex(gcObject.type.name, signature, null);

            return(gcObject.vertex);
        }