我有一个跟踪参与者,当被调用时,会触发一个新线程来执行跟踪工作。跟踪工作最终会这样做:
private static readonly ConcurrentDictionary<string, DateTime> TimingsDictionary = new ConcurrentDictionary<string, DateTime>();
private static readonly ConcurrentDictionary<Guid, DateTime> WorkflowTimingsDictionary = new ConcurrentDictionary<Guid, DateTime>();
private void TimeActivityRecord(TrackingRecord record)
{
var activityStateRecord = record as ActivityStateRecord;
if (activityStateRecord != null)
{
if (activityStateRecord.State == ActivityStates.Executing)
{
if (!TimingsDictionary.TryAdd(GetActivityId(activityStateRecord), activityStateRecord.EventTime))
{}
}
if (activityStateRecord.State == ActivityStates.Closed
|| activityStateRecord.State == ActivityStates.Faulted
|| activityStateRecord.State == ActivityStates.Canceled)
{
DateTime startTime;
if (TimingsDictionary.TryRemove(GetActivityId(activityStateRecord), out startTime))
{
timer.TimeAction("Executing workflow step " + activityStateRecord.Activity.Name, activityStateRecord.InstanceId, activityStateRecord.EventTime.Subtract(startTime));
}
}
}
}
private void TimeWorkflowRecords(TrackingRecord record)
{
var workflowInstanceRecord = record as WorkflowInstanceRecord;
if (workflowInstanceRecord != null)
{
if (workflowInstanceRecord.State == WorkflowInstanceStates.Started)
{
if (!WorkflowTimingsDictionary.TryAdd(workflowInstanceRecord.InstanceId, workflowInstanceRecord.EventTime))
{}
}
if (workflowInstanceRecord.State == WorkflowInstanceStates.Completed
|| workflowInstanceRecord.State == WorkflowInstanceStates.Aborted
|| workflowInstanceRecord.State == WorkflowInstanceStates.UnhandledException
|| workflowInstanceRecord.State == WorkflowInstanceStates.Terminated
|| workflowInstanceRecord.State == WorkflowInstanceStates.Canceled)
{
DateTime startTime;
if (WorkflowTimingsDictionary.TryRemove(workflowInstanceRecord.InstanceId, out startTime))
{
timer.TimeAction("Executing workflow", workflowInstanceRecord.InstanceId, workflowInstanceRecord.EventTime.Subtract(startTime));
}
}
}
}
跟踪整个工作流程时间和已配置活动的时间。但是我得到了奇怪的结果,工作流实例本身似乎总是比最长的活动花费更少的时间。有时我的工作流程需要16毫秒,其中的6个活动需要625毫秒,150毫秒,125毫秒,93毫秒,17毫秒,78毫秒。
我做错了什么吗?我觉得我必须错过一些非常明显的东西,但不能为我的生活看到它是什么。
答案 0 :(得分:0)
当然我做了一些愚蠢的事。当我记录从我使用的时间跨度中取出的时间
timespan.Milliseconds
而不是
timespan.TotalMilliseconds
回到学校。或者也许只是睡一觉。