本文整理汇总了C#中BrightstarProfiler.Step方法的典型用法代码示例。如果您正苦于以下问题:C# BrightstarProfiler.Step方法的具体用法?C# BrightstarProfiler.Step怎么用?C# BrightstarProfiler.Step使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BrightstarProfiler
的用法示例。
在下文中一共展示了BrightstarProfiler.Step方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Retrieve
public byte[] Retrieve(ulong pageId, BrightstarProfiler profiler)
{
using (profiler.Step("PageStore.Retrieve"))
{
if (!_readonly && pageId >= _newPageOffset)
{
var newPage = _newPages[(int) (pageId - _newPageOffset)];
return newPage.Data;
}
var page = PageCache.Instance.Lookup(_path, pageId) as FilePage;
if (page != null)
{
profiler.Incr("PageCache Hit");
return page.Data;
}
using (profiler.Step("Load Page"))
{
profiler.Incr("PageCache Miss");
using (profiler.Step("Create FilePage"))
{
// Lock on stream to prevent attempts to concurrently load a page
lock (_stream)
{
page = new FilePage(_stream, pageId, _pageSize);
}
}
using (profiler.Step("Add FilePage To Cache"))
{
PageCache.Instance.InsertOrUpdate(_path, page);
}
return page.Data;
}
}
}
示例2: GetNode
public INode GetNode(ulong nodeId, BrightstarProfiler profiler)
{
using (profiler.Step("BPlusTree.GetNode"))
{
INode ret;
if (_nodeCache.TryGetValue(nodeId, out ret))
{
profiler.Incr("NodeCache Hit");
return ret;
}
profiler.Incr("NodeCache Miss");
using (profiler.Step("Load Node"))
{
var nodePage = _pageStore.Retrieve(nodeId, profiler);
var header = BitConverter.ToInt32(nodePage.Data, 0);
if (header < 0)
{
ret = MakeInternalNode(nodePage, ~header);
#if DEBUG_BTREE
_config.BTreeDebug("{0}: Loaded INTERNAL node from page {1}. {2}",_config.DebugId, nodePage.Id, ret.ToString());
#endif
}
else
{
ret = MakeLeafNode(nodePage, header);
#if DEBUG_BTREE
_config.BTreeDebug("{0}: Loaded LEAF node from page {1}. {2}", _config.DebugId, nodePage.Id, ret.ToString());
#endif
}
_nodeCache.Add(ret);
return ret;
}
}
}
示例3: GetNode
public INode GetNode(ulong nodeId, BrightstarProfiler profiler)
{
using (profiler.Step("BPlusTree.GetNode"))
{
INode ret;
if (_modifiedNodes.TryGetValue(nodeId, out ret))
{
profiler.Incr("NodeCache Hit");
return ret;
}
if (_nodeCache.TryGetValue(nodeId, out ret))
{
profiler.Incr("NodeCache Hit");
return ret;
}
profiler.Incr("NodeCache Miss");
using (profiler.Step("Load Node"))
{
var nodePage = _pageStore.Retrieve(nodeId, profiler);
var header = BitConverter.ToInt32(nodePage, 0);
if (header < 0)
{
ret = new InternalNode(nodeId, nodePage, ~header, _config);
}
else
{
ret = new LeafNode(nodeId, nodePage, header, _config);
}
_nodeCache.Add(ret);
return ret;
}
}
}
示例4: GetResource
/// <summary>
/// Retrieve the resource at the specified page and segment offset
/// </summary>
/// <param name="pageId">The ID of the page that holds the resource to be retrieved</param>
/// <param name="segment">The index of the segment within the page that holds the start of the resource</param>
/// <param name="profiler"></param>
/// <returns>The resource</returns>
public string GetResource(ulong pageId, byte segment, BrightstarProfiler profiler)
{
using (profiler.Step("ResourceTable.GetResource"))
{
var currentPage = _pageStore.Retrieve(pageId, profiler);
int resourceLength = BitConverter.ToInt32(currentPage, segment*_segmentSize);
int totalLength = resourceLength + 4;
int segmentsToLoad = totalLength/_segmentSize;
if (totalLength%_segmentSize > 0) segmentsToLoad++;
var buffer = new byte[segmentsToLoad*_segmentSize];
byte segmentIndex = segment;
for (int i = 0; i < segmentsToLoad; i++)
{
if (segmentIndex == _pointerSegment)
{
ulong nextPageId = BitConverter.ToUInt64(currentPage, _pageStore.PageSize - 8);
currentPage = _pageStore.Retrieve(nextPageId, profiler);
segmentIndex = 0;
}
Array.Copy(currentPage, segmentIndex*_segmentSize, buffer, i*_segmentSize, _segmentSize);
segmentIndex++;
}
return Encoding.UTF8.GetString(buffer, 4, resourceLength);
}
}
示例5: TestSimpleJoinQuery
public void TestSimpleJoinQuery()
{
var sparqlQuery =
@"PREFIX bsbm: <http://www4.wiwiss.fu-berlin.de/bizer/bsbm/v01/vocabulary/>
SELECT ?review WHERE {
?review bsbm:reviewFor ?product .
?product bsbm:productFeature <http://www4.wiwiss.fu-berlin.de/bizer/bsbm/v01/instances/ProductFeature2330> .
} LIMIT 3";
// Warm-up
var client = BrightstarService.GetClient("type=embedded;storesDirectory=stores");
for (int i = 0; i < 5; i++)
{
client.ExecuteQuery("SparqlPerformance", sparqlQuery);
}
// Profile
var profiler = new BrightstarProfiler("SimpleJoinQuery");
for (int i = 0; i < 1000; i++)
{
using (profiler.Step("ExecuteQuery"))
{
client.ExecuteQuery("SparqlPerformance", sparqlQuery);
}
}
Console.WriteLine(profiler.GetLogString());
}
示例6: ConcurrentGraphIndex
public ConcurrentGraphIndex(IPageStore pageStore, ulong rootPage, BrightstarProfiler profiler)
{
using (profiler.Step("Load ConcurrentGraphIndex"))
{
_pageStore = pageStore;
_graphUriIndex = new Dictionary<string, int>();
_allEntries = new List<GraphIndexEntry>();
Read(rootPage, profiler);
}
}
示例7: CreateEmptyPageStore
public static IPageStore CreateEmptyPageStore(string fileName, PersistenceType persistenceType = PersistenceType.AppendOnly, BrightstarProfiler profiler = null)
{
using (profiler.Step("Create Empty Page Store"))
{
using (profiler.Step("Delete Existing"))
{
if (PersistenceManager.FileExists(fileName)) PersistenceManager.DeleteFile(fileName);
//if (File.Exists(fileName)) File.Delete(fileName);
}
using (profiler.Step("Create New Page Store"))
{
if (persistenceType == PersistenceType.AppendOnly)
{
return new AppendOnlyFilePageStore(PersistenceManager, fileName, 4096, false, false);
}
return new BinaryFilePageStore(PersistenceManager, fileName, 4096, false, 1);
}
}
}
示例8: AddRelatedResource
/// <summary>
/// Adds a related resource index entry
/// </summary>
/// <param name="txnId"> </param>
/// <param name="resourceId">The resource ID of the "start" resource</param>
/// <param name="predicateId">The resource ID of the predicate that relates the resources</param>
/// <param name="relatedResourceId">The resource ID of the "related" resource</param>
/// <param name="graphId">The resource ID of the graph containing the relationship</param>
/// <param name="profiler"></param>
public void AddRelatedResource(ulong txnId, ulong resourceId, ulong predicateId, ulong relatedResourceId, int graphId, BrightstarProfiler profiler = null)
{
using (profiler.Step("Add Related Resource"))
{
var predicateIndex = AssertPredicateIndex(txnId, predicateId, profiler);
var key = MakePredicateIndexKey(resourceId, graphId, relatedResourceId);
try
{
using (profiler.Step("Insert Into Predicate Index"))
{
predicateIndex.Insert(txnId, key, null, profiler: profiler);
}
}
catch (DuplicateKeyException)
{
// Ignore duplicate key exceptions
}
}
}
示例9: Store
public Store(string storeLocation, IPageStore dataPageStore, IResourceTable resourceTable, ulong storePageId, BrightstarProfiler profiler)
{
using (profiler.Step("Load Store"))
{
DirectoryPath = storeLocation;
_pageStore = dataPageStore;
_resourceTable = resourceTable;
var storePage = _pageStore.Retrieve(storePageId, profiler);
Load(storePage, profiler);
}
}
示例10: OpenPageStore
public static IPageStore OpenPageStore(string fileName, bool readOnly, PersistenceType persistenceType = PersistenceType.AppendOnly, ulong txnId = 1UL, BrightstarProfiler profiler = null)
{
using (profiler.Step("Open Page Store"))
{
if (persistenceType == PersistenceType.AppendOnly)
{
return new AppendOnlyFilePageStore(PersistenceManager, fileName, 4096, readOnly, false);
}
return new BinaryFilePageStore(PersistenceManager, fileName, 4096, readOnly, txnId);
}
}
示例11: EnumerateRelatedResources
/// <summary>
/// Enumerates the resources related to a start resource by a specific predicate
/// </summary>
/// <param name="resourceId">The resource ID of the start resource</param>
/// <param name="predicateId">The resource ID of the predicate that relates the resources. If set to Constants.NullUlong, returns relationships for all predicates</param>
/// <param name="graphId">The resource ID of the graph containing the relationships. If set to Constants.NullUlong, returns relationships from all graphs</param>
/// <param name="profiler"></param>
/// <returns></returns>
public IEnumerable<IRelatedResource> EnumerateRelatedResources(ulong resourceId, ulong predicateId = StoreConstants.NullUlong, int graphId = -1, BrightstarProfiler profiler = null)
{
using (profiler.Step("EnumerateRelatedResources"))
{
if (predicateId != StoreConstants.NullUlong)
{
byte[] minKey = MakePredicateIndexKey(resourceId,
graphId < 0 ? 0 : graphId,
UInt64.MinValue);
byte[] maxKey = MakePredicateIndexKey(resourceId,
graphId < 0 ? Int32.MaxValue : graphId,
UInt64.MaxValue);
var predicateIndex = GetPredicateIndex(predicateId, profiler);
if (predicateIndex != null)
{
foreach (var r in predicateIndex.Scan(minKey, maxKey, profiler).Select(
x =>
new RelatedResource(predicateId, GetGraphIdFromKey(x.Key),
GetRelatedResourceIdFromKey(x.Key))))
{
yield return r;
}
}
}
else
{
foreach (var entry in Scan(0ul, UInt64.MaxValue, profiler))
{
// Load the predicate index into the cache
GetPredicateIndex(entry.Key,BitConverter.ToUInt64(entry.Value, 0), profiler);
// Then a recursive call to enumerate the index tree
foreach (var r in EnumerateRelatedResources(resourceId, entry.Key, graphId, profiler))
{
yield return r;
}
}
}
}
}
示例12: AssertResourceInIndex
/// <summary>
/// Ensures that the specified resource is in the resource index and returns its resource ID
/// </summary>
/// <param name="txnId">The ID of the current update transaction</param>
/// <param name="resourceValue">The resource string value</param>
/// <param name="isLiteral">Boolean flag indicating if the resource is a literal (true) or a URI (false)</param>
/// <param name="dataType">The resource data-type URI</param>
/// <param name="langCode">The resource language string</param>
/// <param name="addToCache">Boolean flag indicating if newly indexed resources should be added to the local cache</param>
/// <param name="profiler"></param>
/// <returns>The resource ID for the resource</returns>
public ulong AssertResourceInIndex(ulong txnId, string resourceValue, bool isLiteral = false, string dataType = null, string langCode = null, bool addToCache = true, BrightstarProfiler profiler = null)
{
using (profiler.Step("AssertResourceInIndex"))
{
// Normalize language code to null if it is an empty string
if (String.IsNullOrEmpty(langCode))
{
langCode = null;
}
// Retrieve the resource ID for the datatype URI (if any)
var dataTypeId = String.IsNullOrEmpty(dataType)
? StoreConstants.NullUlong
: AssertResourceInIndex(txnId, dataType, profiler:profiler);
var hashString = isLiteral ? MakeHashString(resourceValue, dataType, langCode) : resourceValue;
ulong resourceId;
if (_resourceIdCache.TryGetValue(hashString, out resourceId))
{
return resourceId;
}
// Get a ulong resource ID for the language code string
var langCodeId = String.IsNullOrEmpty(langCode)
? StoreConstants.NullUlong
: AssertResourceInIndex(txnId, langCode, true, profiler:profiler);
resourceId = AssertResourceInBTree(txnId, resourceValue, isLiteral, dataTypeId, langCodeId,
StringExtensions.GetBrightstarHashCode(hashString), profiler);
if (addToCache)
{
_resourceIdCache.Add(hashString, resourceId);
}
return resourceId;
}
}
示例13: AssertGraphId
/// <summary>
/// Finds or creates a new ID for the graph with the specified graph URI
/// </summary>
/// <param name="graphUri">The graph URI to lookup</param>
/// <param name="profiler"></param>
/// <returns>The ID assigned to the graph</returns>
public int AssertGraphId(string graphUri, BrightstarProfiler profiler = null)
{
if (String.IsNullOrEmpty(graphUri))
{
throw new ArgumentException("Graph URI must not be null or an empty string", "graphUri");
}
if (graphUri.Length > short.MaxValue)
{
throw new ArgumentException(
String.Format("Graph URI string exceeds maximum allowed length of {0} bytes", short.MaxValue), "graphUri");
}
#if WINDOWS_PHONE
lock(_lock)
{
int entryId;
if (_graphUriIndex.TryGetValue(graphUri, out entryId) && !_allEntries[entryId].IsDeleted)
{
return entryId;
}
var newId = _allEntries.Count;
var entry = new GraphIndexEntry(newId, graphUri, false);
_allEntries.Add(entry);
_graphUriIndex.Add(graphUri, newId);
return newId;
}
#else
using (profiler.Step("Assert Graph Id"))
{
_lock.EnterUpgradeableReadLock();
try
{
int entryId;
if (_graphUriIndex.TryGetValue(graphUri, out entryId) && !_allEntries[entryId].IsDeleted)
{
return entryId;
}
_lock.EnterWriteLock();
try
{
var newId = _allEntries.Count;
var entry = new GraphIndexEntry(newId, graphUri, false);
_allEntries.Add(entry);
_graphUriIndex.Add(graphUri, newId);
return newId;
}
finally
{
_lock.ExitWriteLock();
}
}
finally
{
_lock.ExitUpgradeableReadLock();
}
}
#endif
}
示例14: InterlockedLoad
/// <summary>
/// Performs the actual load of prefixes from a page.
/// </summary>
/// <param name="page"></param>
/// <param name="profiler"></param>
/// <remarks>Calls to this method should be made inside a critical section of code protected with a mutex or reader/writer lock</remarks>
private void InterlockedLoad(byte[] page, BrightstarProfiler profiler)
{
using (profiler.Step("PrefixManager.InterlockedLoad"))
{
int offset = 0;
while (offset < _pageStore.PageSize)
{
ushort prefixLength = BitConverter.ToUInt16(page, offset);
offset += 2;
if (prefixLength == ushort.MaxValue)
{
ulong nextPageId = BitConverter.ToUInt64(page, offset);
if (nextPageId == 0)
{
// End of data
return;
}
page = _pageStore.Retrieve(nextPageId, profiler);
offset = 0;
}
else
{
var prefix = Encoding.UTF8.GetString(page, offset, prefixLength);
offset += prefixLength;
var uriLen = BitConverter.ToUInt16(page, offset);
offset += 2;
var uri = Encoding.UTF8.GetString(page, offset, uriLen);
offset += uriLen;
_prefixMappings[uri] = prefix;
_shortValueMappings[prefix] = uri;
}
}
}
}
示例15: Insert
public void Insert(ulong transactionId, string resource, out ulong pageId, out byte segmentId, BrightstarProfiler profiler)
{
using (profiler.Step("ResourceTable.Insert"))
{
var byteCount = Encoding.UTF8.GetByteCount(resource);
var resourceBytes = new byte[byteCount + 4];
BitConverter.GetBytes(byteCount).CopyTo(resourceBytes, 0);
Encoding.UTF8.GetBytes(resource, 0, resource.Length, resourceBytes, 4);
lock (_writeLock)
{
if (_nextSegment == _pointerSegment)
{
StartNewPage(transactionId, profiler);
}
pageId = _currentPage;
segmentId = _nextSegment;
for (int i = 0; i < (byteCount + 4); i += _segmentSize)
{
_pageStore.Write(transactionId, _currentPage, resourceBytes, i, _nextSegment*_segmentSize,
_segmentSize < (byteCount + 4 - i) ? _segmentSize : (byteCount + 4 - i),
profiler);
_nextSegment++;
if (_nextSegment == _pointerSegment)
{
StartNewPage(transactionId, profiler);
}
}
}
}
}