Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
CSHARP-513: added new server values into SystemProfileInfo.
  • Loading branch information
craiggwilson committed Jul 20, 2012
1 parent 024f1ed commit 3fff8c4
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 8 deletions.
50 changes: 42 additions & 8 deletions Driver/Core/SystemProfileInfo.cs
Expand Up @@ -50,12 +50,14 @@ public class SystemProfileInfo
private bool _idHack;
private string _info;
private int _keyUpdates;
private BsonDocument _lockStatistics;
private bool _moved;
private string _namespace;
private int _numberReturned;
private int _numberScanned;
private int _numberToReturn;
private int _numberToSkip;
private int _numberOfYields;
private string _op;
private BsonDocument _query;
private int _responseLength;
Expand All @@ -65,14 +67,6 @@ public class SystemProfileInfo
private bool _upsert;
private string _user;

// constructors
/// <summary>
/// Initializes a new instance of the SystemProfileInfo class.
/// </summary>
public SystemProfileInfo()
{
}

// public properties
/// <summary>
/// Gets or sets the abbreviated profile info (only used when the profile info would have exceeded 100KB).
Expand Down Expand Up @@ -200,6 +194,12 @@ public int KeyUpdates
set { _keyUpdates = value; }
}

public BsonDocument LockStatistics
{
get { return _lockStatistics; }
set { _lockStatistics = value; }
}

/// <summary>
/// Gets or sets whether moved was true.
/// </summary>
Expand Down Expand Up @@ -254,6 +254,15 @@ public int NumberToSkip
set { _numberToSkip = value; }
}

/// <summary>
/// Gets or sets the number of yields.
/// </summary>
public int NumberOfYields
{
get { return _numberOfYields; }
set { _numberOfYields = value; }
}

/// <summary>
/// Gets or sets the operation.
/// </summary>
Expand Down Expand Up @@ -404,6 +413,9 @@ public class SystemProfileInfoSerializer : BsonBaseSerializer, IBsonDocumentSeri
case "keyUpdates":
profileInfo.KeyUpdates = BsonValue.ReadFrom(bsonReader).ToInt32();
break;
case "lockStatMillis":
profileInfo.LockStatistics = BsonValue.ReadFrom(bsonReader).AsBsonDocument;
break;
case "millis":
profileInfo.Duration = TimeSpan.FromMilliseconds(BsonValue.ReadFrom(bsonReader).ToDouble());
break;
Expand All @@ -425,6 +437,9 @@ public class SystemProfileInfoSerializer : BsonBaseSerializer, IBsonDocumentSeri
case "ntoskip":
profileInfo.NumberToSkip = BsonValue.ReadFrom(bsonReader).ToInt32();
break;
case "numYield":
profileInfo.NumberOfYields = BsonValue.ReadFrom(bsonReader).ToInt32();
break;
case "op":
profileInfo.Op = bsonReader.ReadString();
break;
Expand Down Expand Up @@ -545,6 +560,11 @@ public BsonSerializationInfo GetMemberSerializationInfo(string memberName)
serializer = Int32Serializer.Instance;
nominalType = typeof(int);
break;
case "LockStatistics":
elementName = "lockStatMillis";
serializer = BsonDocumentSerializer.Instance;
nominalType = typeof(BsonDocument);
break;
case "Moved":
elementName = "moved";
serializer = BooleanSerializer.Instance;
Expand Down Expand Up @@ -575,6 +595,11 @@ public BsonSerializationInfo GetMemberSerializationInfo(string memberName)
serializer = Int32Serializer.Instance;
nominalType = typeof(int);
break;
case "NumberOfYields":
elementName = "numYield";
serializer = Int32Serializer.Instance;
nominalType = typeof(int);
break;
case "Op":
elementName = "op";
serializer = StringSerializer.Instance;
Expand Down Expand Up @@ -693,6 +718,10 @@ public BsonSerializationInfo GetMemberSerializationInfo(string memberName)
{
bsonWriter.WriteInt32("nscanned", profileInfo.NumberScanned);
}
if (profileInfo.NumberOfYields != 0)
{
bsonWriter.WriteInt32("numYield", profileInfo.NumberOfYields);
}
if (profileInfo.IdHack)
{
bsonWriter.WriteBoolean("idhack", profileInfo.IdHack);
Expand Down Expand Up @@ -754,6 +783,11 @@ public BsonSerializationInfo GetMemberSerializationInfo(string memberName)
{
bsonWriter.WriteString("abbreviated", profileInfo.Abbreviated);
}
if (profileInfo.LockStatistics != null)
{
bsonWriter.WriteName("lockStatMillis");
profileInfo.LockStatistics.WriteTo(bsonWriter);
}
bsonWriter.WriteEndDocument();
}
}
Expand Down
4 changes: 4 additions & 0 deletions DriverUnitTests/Core/SystemProfileIntoTests.cs
Expand Up @@ -60,12 +60,14 @@ public void TestAll()
IdHack = true,
Info = "info",
KeyUpdates = 4,
LockStatistics = new BsonDocument().Add("timeLocked", new BsonDocument("r", 11L).Add("w", 12L)).Add("timeAcquiring", new BsonDocument("r",12L).Add("w", 12L)),
Moved = true,
Namespace = "ns",
NumberReturned = 5,
NumberScanned = 6,
NumberToReturn = 7,
NumberToSkip = 8,
NumberOfYields = 10,
Op = "op",
Query = new BsonDocument("query", 1),
ResponseLength = 9,
Expand All @@ -91,12 +93,14 @@ public void TestAll()
Assert.AreEqual(info.IdHack, rehydrated.IdHack);
Assert.AreEqual(info.Info, rehydrated.Info);
Assert.AreEqual(info.KeyUpdates, rehydrated.KeyUpdates);
Assert.AreEqual(info.LockStatistics, rehydrated.LockStatistics);
Assert.AreEqual(info.Moved, rehydrated.Moved);
Assert.AreEqual(info.Namespace, rehydrated.Namespace);
Assert.AreEqual(info.NumberReturned, rehydrated.NumberReturned);
Assert.AreEqual(info.NumberScanned, rehydrated.NumberScanned);
Assert.AreEqual(info.NumberToReturn, rehydrated.NumberToReturn);
Assert.AreEqual(info.NumberToSkip, rehydrated.NumberToSkip);
Assert.AreEqual(info.NumberOfYields, rehydrated.NumberOfYields);
Assert.AreEqual(info.Op, rehydrated.Op);
Assert.AreEqual(info.Query, rehydrated.Query);
Assert.AreEqual(info.ResponseLength, rehydrated.ResponseLength);
Expand Down

0 comments on commit 3fff8c4

Please sign in to comment.