Use the Concurrency Visualizer markers SDK
This topic shows how to use the Concurrency Visualizer SDK to create spans and write flags, messages, and alerts.
To use C++
Add Concurrency Visualizer SDK support to your application. For more information, see Concurrency Visualizer SDK.
Add an
include
statement and ausing
statement for the SDK.#include <cvmarkersobj.h> using namespace Concurrency::diagnostic;
Add code to create three spans in the default marker series and write a flag, a message, and an alert, one to each span. The methods to write flags, messages, and alerts are members of the marker_series class. The constructor for the span class requires a
marker_series
object, so that each span is associated with a specific marker series. Aspan
ends when it is deleted.marker_series series; span *flagSpan = new span(series, 1, _T("flag span")); series.write_flag(_T("Here is the flag.")); delete flagSpan; span *messageSpan = new span(series, 2, _T("message span")); series.write_flag(_T("Here is the message.")); delete messageSpan; span *alertSpan = new span(series, 3, _T("alert span")); series.write_flag(_T("Here is the alert.")); delete alertSpan;
On the menu bar, choose Analyze, Concurrency Visualizer, Start with Current Project to run the app and display the Concurrency Visualizer. The following illustration shows the three spans and three markers in the Concurrency Visualizer.
Add code to create additional, custom marker series by calling the constructor for
marker_series
that takes a string name for the marker series.marker_series flagSeries(_T("flag series")); span *flagSeriesSpan = new span(flagSeries, 1, _T("flag span")); flagSeries.write_flag(1, _T("flag")); // Sleep to even out the display in the Concurrency Visualizer. Sleep(50); delete flagSeriesSpan; marker_series messageSeries(_T("message series")); span *messageSeriesSpan = new span(messageSeries, 1, _T("message span")); messageSeries.write_message(1, _T("message")); // Sleep to even out the display in the Concurrency Visualizer. Sleep(50); delete messageSeriesSpan;
Start the current project to display the Concurrency Visualizer. The two marker series appear in their own lanes in Threads View. The following illustration shows the two new spans.
To Use Visual Basic or C#
Add Concurrency Visualizer SDK support to your application. For more information, see Concurrency Visualizer SDK.
Add a
using
orImports
statement for the SDK.Add code to create three spans on the default marker series and write a flag, a message, and an alert, one to each span. You create a Span object by calling the static
EnterSpan
method. To write to the default series, you use the static write methods of the Markers class.Span flagSpan = Markers.EnterSpan("flag span"); Markers.WriteFlag("Here is the flag."); flagSpan.Leave(); Span messageSpan = Markers.EnterSpan("message span"); // Sleep for a millisecond to even out the display in the Concurrency Visualizer. System.Threading.Thread.Sleep(1); Markers.WriteMessage("Here is a message"); messageSpan.Leave(); Span alertSpan = Markers.EnterSpan("alert span"); // Sleep for a millisecond to even out the display in the Concurrency Visualizer. System.Threading.Thread.Sleep(1); Markers.WriteAlert("Here is an alert"); alertSpan.Leave();
On the menu bar, choose Analyze, Concurrency Visualizer, Start with Current Project to run the app and display the Concurrency Visualizer. The following illustration shows the three spans and three markers in the Threads View of the Concurrency Visualizer.
Add code to create customer marker series by using the static CreateMarkerSeries method. The MarkerSeries class contains methods for creating spans and writing flags, messages, and alerts.
MarkerSeries flagSeries = Markers.DefaultWriter.CreateMarkerSeries("flag series"); Span flagSeriesSpan = flagSeries.EnterSpan("flag span"); System.Threading.Thread.Sleep(1); flagSeries.WriteFlag(1, "flag"); System.Threading.Thread.Sleep(1); flagSeriesSpan.Leave(); MarkerSeries messageSeries = Markers.DefaultWriter.CreateMarkerSeries("message series"); Span messageSeriesSpan = messageSeries.EnterSpan("message span"); messageSeries.WriteMessage("message"); System.Threading.Thread.Sleep(1); messageSeriesSpan.Leave();
Start the current project to display the Concurrency Visualizer. The three marker series appear in their own lanes in the Threads View. The following illustration shows the three new spans.
Related content
Feedback
https://aka.ms/ContentUserFeedback.
Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see:Submit and view feedback for