~halega/+junk/sharpdevelop

« back to all changes in this revision

Viewing changes to src/AddIns/Analysis/Profiler/Controller/Data/UnmanagedCallTreeNode64.cs

  • Committer: sk
  • Date: 2011-09-10 05:17:57 UTC
  • Revision ID: halega@halega.com-20110910051757-qfouz1llya9m6boy
4.1.0.7915 Release Candidate 1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
using System;
 
2
using System.Collections.Generic;
 
3
using System.Collections.ObjectModel;
 
4
using System.Linq;
 
5
namespace ICSharpCode.Profiler.Controller.Data
 
6
{
 
7
        unsafe sealed class UnmanagedCallTreeNode64 : CallTreeNode
 
8
        {
 
9
                FunctionInfo* data;
 
10
                CallTreeNode parent;
 
11
                const ulong CpuCycleMask = 0x7fffffffffffffL;
 
12
                UnmanagedProfilingDataSet dataSet;
 
13
                internal UnmanagedCallTreeNode64(UnmanagedProfilingDataSet dataSet, FunctionInfo* data, CallTreeNode parent)
 
14
                {
 
15
                        this.data = data;
 
16
                        this.dataSet = dataSet;
 
17
                        this.parent = parent;
 
18
                }
 
19
                public override System.Linq.IQueryable<CallTreeNode> Children {
 
20
                        get {
 
21
                                dataSet.VerifyAccess();
 
22
                                List<UnmanagedCallTreeNode64> children = new List<UnmanagedCallTreeNode64>();
 
23
                                TargetProcessPointer64* childrenPtr = FunctionInfo.GetChildren64(data);
 
24
                                for (int i = 0; i <= data->LastChildIndex; i++) {
 
25
                                        FunctionInfo* child = dataSet.GetFunctionInfo(childrenPtr[i]);
 
26
                                        if (child != null)
 
27
                                                children.Add(new UnmanagedCallTreeNode64(dataSet, child, this));
 
28
                                }
 
29
                                children.Sort((a, b) => a.Index.CompareTo(b.Index));
 
30
                                return children.AsQueryable();
 
31
                        }
 
32
                }
 
33
                public override NameMapping NameMapping {
 
34
                        get { return this.dataSet.GetMapping(this.data->Id); }
 
35
                }
 
36
                public override int RawCallCount {
 
37
                        get {
 
38
                                dataSet.VerifyAccess();
 
39
                                return this.data->CallCount;
 
40
                        }
 
41
                }
 
42
                public int Index {
 
43
                        get {
 
44
                                dataSet.VerifyAccess();
 
45
                                return (int)(this.data->TimeSpent >> 56);
 
46
                        }
 
47
                }
 
48
                public override bool IsActiveAtStart {
 
49
                        get {
 
50
                                dataSet.VerifyAccess();
 
51
                                return (this.data->TimeSpent & ((ulong)1 << 55)) != 0;
 
52
                        }
 
53
                }
 
54
                public override long CpuCyclesSpent {
 
55
                        get {
 
56
                                dataSet.VerifyAccess();
 
57
                                return (long)(this.data->TimeSpent & CpuCycleMask);
 
58
                        }
 
59
                }
 
60
                public override long CpuCyclesSpentSelf {
 
61
                        get {
 
62
                                dataSet.VerifyAccess();
 
63
                                long result = (long)(this.data->TimeSpent & CpuCycleMask);
 
64
                                TargetProcessPointer64* childrenPtr = FunctionInfo.GetChildren64(data);
 
65
                                for (int i = 0; i <= data->LastChildIndex; i++) {
 
66
                                        FunctionInfo* child = dataSet.GetFunctionInfo(childrenPtr[i]);
 
67
                                        if (child != null)
 
68
                                                result -= (long)(child->TimeSpent & CpuCycleMask);
 
69
                                }
 
70
                                return result;
 
71
                        }
 
72
                }
 
73
                public override CallTreeNode Parent {
 
74
                        get { return this.parent; }
 
75
                }
 
76
                public override double TimeSpent {
 
77
                        get { return this.CpuCyclesSpent / (1000.0 * this.dataSet.ProcessorFrequency); }
 
78
                }
 
79
                public override double TimeSpentSelf {
 
80
                        get { return this.CpuCyclesSpentSelf / (1000.0 * this.dataSet.ProcessorFrequency); }
 
81
                }
 
82
                public override CallTreeNode Merge(IEnumerable<CallTreeNode> nodes)
 
83
                {
 
84
                        throw new NotImplementedException();
 
85
                }
 
86
                public override IQueryable<CallTreeNode> Callers {
 
87
                        get { return GetCallers().AsQueryable(); }
 
88
                }
 
89
                IEnumerable<CallTreeNode> GetCallers()
 
90
                {
 
91
                        if (parent != null)
 
92
                                yield return parent;
 
93
                }
 
94
                public override bool Equals(CallTreeNode other)
 
95
                {
 
96
                        UnmanagedCallTreeNode64 node = other as UnmanagedCallTreeNode64;
 
97
                        if (node != null) {
 
98
                                return node.data == this.data;
 
99
                        }
 
100
                        return false;
 
101
                }
 
102
                public override int GetHashCode()
 
103
                {
 
104
                        return (new IntPtr(data)).GetHashCode();
 
105
                }
 
106
        }
 
107
}