Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
ProfilingMessage.cs
Go to the documentation of this file.
1 // Copyright (c) 2014 Silicon Studio Corp. (http://siliconstudio.co.jp)
2 // This file is distributed under GPL v3. See LICENSE.md for details.
3 using System;
4 using System.Collections.Generic;
5 using System.Globalization;
6 using System.Text;
7 
8 namespace SiliconStudio.Core.Diagnostics
9 {
10  /// <summary>
11  /// A log message generate by <see cref="Profiler"/>.
12  /// </summary>
14  {
15  /// <summary>
16  /// Initializes a new instance of the <see cref="ProfilingMessage" /> class.
17  /// </summary>
18  /// <param name="profileId">The profile unique identifier.</param>
19  /// <param name="profilingKey">The profile key.</param>
20  /// <param name="profilingType">Type of the profile.</param>
21  public ProfilingMessage(int profileId, ProfilingKey profilingKey, ProfilingMessageType profilingType) : this(profileId, profilingKey, profilingType, null)
22  {
23  }
24 
25  /// <summary>
26  /// Initializes a new instance of the <see cref="ProfilingMessage" /> class.
27  /// </summary>
28  /// <param name="profileId">The profile unique identifier.</param>
29  /// <param name="profilingKey">The profile key.</param>
30  /// <param name="profilingType">Type of the profile.</param>
31  /// <param name="text">The text.</param>
32  public ProfilingMessage(int profileId, ProfilingKey profilingKey, ProfilingMessageType profilingType, string text)
33  : base("Profiler", LogMessageType.Info, text)
34  {
35  if (profilingKey == null) throw new ArgumentNullException("profilingKey");
36 
37  Id = profileId;
38  Key = profilingKey;
39  ProfilingType = profilingType;
40  }
41 
42  /// <summary>
43  /// Gets or sets the unique identifier associated with this profile message.
44  /// </summary>
45  /// <value>The unique identifier.</value>
46  public int Id { get; private set; }
47 
48  /// <summary>
49  /// Gets or sets the profile key.
50  /// </summary>
51  /// <value>The profile key.</value>
52  public ProfilingKey Key { get; private set; }
53 
54  /// <summary>
55  /// Gets the type of the profile.
56  /// </summary>
57  /// <value>The type of the profile.</value>
58  public ProfilingMessageType ProfilingType { get; private set; }
59 
60  /// <summary>
61  /// Gets or sets the time elapsed for this particular profile.
62  /// </summary>
63  /// <value>The elapsed.</value>
64  public TimeSpan ElapsedTime { get; set; }
65 
66  /// <summary>
67  /// Gets attributes attached to this message. May be null.
68  /// </summary>
69  /// <value>The properties.</value>
70  public Dictionary<object, object> Attributes { get; set; }
71 
72  public override string ToString()
73  {
74  var builder = new StringBuilder(Text != null ? string.Format(": {0}",Text) : string.Empty);
75  bool hasElapsed = false;
76  if (ProfilingType != ProfilingMessageType.Begin)
77  {
78  builder.Append(": ");
79 
80  if (ElapsedTime > new TimeSpan(0, 0, 1, 0))
81  {
82  builder.AppendFormat("Elapsed = {0:0.000}m", ElapsedTime.TotalMinutes);
83  }
84  else if (ElapsedTime > new TimeSpan(0, 0, 0, 0, 1000))
85  {
86  builder.AppendFormat("Elapsed = {0:0.000}s", ElapsedTime.TotalSeconds);
87  }
88  else
89  {
90  builder.AppendFormat("Elapsed = {0:0.000}ms", ElapsedTime.TotalMilliseconds);
91  }
92  hasElapsed = true;
93  }
94 
95  if (Attributes != null && Attributes.Count > 0)
96  {
97  if (!hasElapsed)
98  {
99  builder.Append(": ");
100  }
101 
102  foreach (var keyValue in Attributes)
103  {
104  builder.Append(", ").Append(keyValue.Key).Append(" = ").Append(keyValue.Value);
105  }
106  }
107 
108  return string.Format("[{0}] #{1}: {2}: {3}{4}",
109  Module,
110  Id,
111  ProfilingType,
112  Key,
113  builder);
114  }
115  }
116 }
ProfilingMessage(int profileId, ProfilingKey profilingKey, ProfilingMessageType profilingType)
Initializes a new instance of the ProfilingMessage class.
A key to identify a specific profile.
Definition: ProfilingKey.cs:11
ProfilingMessage(int profileId, ProfilingKey profilingKey, ProfilingMessageType profilingType, string text)
Initializes a new instance of the ProfilingMessage class.
ProfilingMessageType
Type of a profiling message.
A log message generate by Profiler.
LogMessageType
Type of a LogMessage.
A base log message used by the logging infrastructure.
Definition: LogMessage.cs:13
An regular info message (level 2).