Esempio n. 1
0
        public ExecutingQuery(long queryId, ClientConnectionInfo clientConnection, string username, string queryText, MapValue queryParameters, IDictionary <string, object> transactionAnnotationData, System.Func <long> activeLockCount, PageCursorCounters pageCursorCounters, long threadExecutingTheQueryId, string threadExecutingTheQueryName, SystemNanoClock clock, CpuClock cpuClock, HeapAllocation heapAllocation)
        {
            if (!InstanceFieldsInitialized)
            {
                InitializeInstanceFields();
                InstanceFieldsInitialized = true;
            }
            // Capture timestamps first
            this._cpuTimeNanosWhenQueryStarted = cpuClock.CpuTimeNanos(threadExecutingTheQueryId);
            this._startTimeNanos       = clock.Nanos();
            this._startTimestampMillis = clock.Millis();
            // then continue with assigning fields
            this._queryId            = queryId;
            this._clientConnection   = clientConnection;
            this._pageCursorCounters = pageCursorCounters;
            this._username           = username;

            ISet <string> passwordParams = new HashSet <string>();

            this._queryText                   = QueryObfuscation.ObfuscateText(queryText, passwordParams);
            this._queryParameters             = QueryObfuscation.ObfuscateParams(queryParameters, passwordParams);
            this._transactionAnnotationData   = transactionAnnotationData;
            this._activeLockCount             = activeLockCount;
            this._initialActiveLocks          = activeLockCount();
            this._threadExecutingTheQueryId   = threadExecutingTheQueryId;
            this._threadExecutingTheQueryName = threadExecutingTheQueryName;
            this._cpuClock       = cpuClock;
            this._heapAllocation = heapAllocation;
            this._clock          = clock;
            this._heapAllocatedBytesWhenQueryStarted = heapAllocation.AllocatedBytes(this._threadExecutingTheQueryId);
        }
Esempio n. 2
0
            public void Free(IntPtr handle)
            {
                _largestFreeBlock = -1;
                var ptr = (HeapAllocation *)handle;

                HeapAllocation.Free(ptr - 1);
            }
        public void AddAllocation(int a_start, int a_length)
        {
            if (_heapAllocs.ContainsKey(a_start))
            {
                _heapFrees.Add(_heapAllocs[a_start]);

                _heapAllocs[a_start] = new HeapAllocation(a_start, a_length);
            }
            else
            {
                _heapAllocs.Add(a_start, new HeapAllocation(a_start, a_length));
            }
        }
Esempio n. 4
0
            public HeapPage(ILoggerFactory logFactory, IAllocator allocator, int size)
            {
                _logger    = logFactory.CreateLogger <HeapPage>();
                _allocator = allocator;
                _handle    = allocator.Take((int)size);
                Size       = size;
                _heap      = (HeapAllocation *)_handle.Address;
                *_heap = new HeapAllocation(size);

                // _enableLogging = enableLogging;
                // if (_enableLogging)
                //     _stackTrace = new string[_heap->Blocks];
            }
Esempio n. 5
0
            public bool TryTake(out IntPtr handle, uint size)
            {
                var blocks = (size + (HeapAllocation.HeapSize - 1)) >> 5;

                Assert.GreatherThan(blocks, 0);

                if (_largestFreeBlock > -1 && blocks > _largestFreeBlock)
                {
                    handle = IntPtr.Zero;
                    return(false);
                }

                //var id = 0u;
                var ptr         = _heap;
                var largestFree = 0u;

                while (ptr != null)
                {
                    //_logger.LogDebug($"Alloc {{ Heap: {*ptr} }}");
                    if (ptr->IsFree)
                    {
                        var freeBlocks = ptr->Blocks;
                        //TODO: we could remember this block and look for a better one if we wanted to
                        if (freeBlocks >= blocks)
                        {
                            HeapAllocation.Split(ptr, blocks);
                            handle            = new IntPtr((void *)(ptr + 1));
                            _largestFreeBlock = -1;
                            return(true);
                        }

                        if (freeBlocks > largestFree)
                        {
                            largestFree = freeBlocks;
                        }
                    }

                    //TODO: We should generate an ID for faster look up times
                    //id++;
                    //id += ptr->Blocks;

                    ptr = ptr->Next;
                }

                handle            = IntPtr.Zero;
                _largestFreeBlock = (int)largestFree;
                return(false);
            }
Esempio n. 6
0
 internal void Validate()
 {
     HeapAllocation.Validate(_heap);
 }