Skip to content

Commit f76e9fc

Browse files
authored
User/ivberg/fix11 LTTng floating point trace load issue (#17)
* Add floating point support Fixes #11
1 parent 2cb8d66 commit f76e9fc

File tree

13 files changed

+449
-73
lines changed

13 files changed

+449
-73
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT License.
3+
4+
using System.Globalization;
5+
using CtfPlayback.Metadata;
6+
using CtfPlayback.Metadata.TypeInterfaces;
7+
8+
namespace CtfPlayback.FieldValues
9+
{
10+
/// <summary>
11+
/// Represents a floating point field from a CTF event
12+
/// </summary>
13+
public class CtfDoubleValue
14+
: CtfFieldValue
15+
{
16+
/// <summary>
17+
/// Constructor
18+
/// </summary>
19+
/// <param name="value">Floating point value</param>
20+
public CtfDoubleValue(double value, ICtfFloatingPointDescriptor descriptor)
21+
: base(CtfTypes.FloatingPoint)
22+
{
23+
this.Value = value;
24+
this.Descriptor = descriptor;
25+
}
26+
27+
/// <summary>
28+
/// Field value
29+
/// </summary>
30+
public double Value { get; }
31+
32+
/// <summary>
33+
/// CTF floating point descriptor associated with the field
34+
/// </summary>
35+
public ICtfFloatingPointDescriptor Descriptor { get; }
36+
37+
/// <summary>
38+
/// Returns a string representation of the field value.
39+
/// Useful when text dumping the contents of an event stream.
40+
/// </summary>
41+
/// <returns>The field value as a string</returns>
42+
public override string GetValueAsString(GetValueAsStringOptions options = GetValueAsStringOptions.NoOptions)
43+
{
44+
return string.Intern(Value.ToString(CultureInfo.InvariantCulture));
45+
}
46+
}
47+
}

CtfPlayback/FieldValues/CtfFloatValue.cs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,37 @@
33

44
using System.Globalization;
55
using CtfPlayback.Metadata;
6+
using CtfPlayback.Metadata.TypeInterfaces;
67

78
namespace CtfPlayback.FieldValues
89
{
910
/// <summary>
10-
/// Represents a float field from a CTF event
11+
/// Represents a floating point field from a CTF event
1112
/// </summary>
1213
public class CtfFloatValue
1314
: CtfFieldValue
1415
{
1516
/// <summary>
1617
/// Constructor
1718
/// </summary>
18-
/// <param name="value">Float value</param>
19-
public CtfFloatValue(float value)
20-
: base(CtfTypes.Float)
19+
/// <param name="value">Floating point value</param>
20+
public CtfFloatValue(float value, ICtfFloatingPointDescriptor descriptor)
21+
: base(CtfTypes.FloatingPoint)
2122
{
2223
this.Value = value;
24+
this.Descriptor = descriptor;
2325
}
2426

2527
/// <summary>
2628
/// Field value
2729
/// </summary>
2830
public float Value { get; }
2931

32+
/// <summary>
33+
/// CTF floating point descriptor associated with the field
34+
/// </summary>
35+
public ICtfFloatingPointDescriptor Descriptor { get; }
36+
3037
/// <summary>
3138
/// Returns a string representation of the field value.
3239
/// Useful when text dumping the contents of an event stream.

CtfPlayback/Metadata/AntlrParser/CtfListener.cs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ internal class CtfListener
3636
private int streamCount;
3737
private int eventCount;
3838
private int integerCount;
39+
private int floatCount;
3940
private int enumCount;
4041
private int stringCount;
4142

@@ -1037,6 +1038,33 @@ public override void EnterTypeSpecifierEmptyInteger(CtfParser.TypeSpecifierEmpty
10371038
$"An integer specifier without a 'size' value is undefined: line={context.Start.Line}.");
10381039
}
10391040

1041+
// Float
1042+
public override void EnterTypeSpecifierFloatingPoint(CtfParser.TypeSpecifierFloatingPointContext context)
1043+
{
1044+
this.PushFloatScope();
1045+
}
1046+
1047+
// See CTF 1.82 section 4.1.7 FLOATING POINT
1048+
public override void ExitTypeSpecifierFloatingPoint(CtfParser.TypeSpecifierFloatingPointContext context)
1049+
{
1050+
this.PopFloatScope(true);
1051+
throw new CtfMetadataException(
1052+
$"An floating_point specifier without fields is undefined: line={context.Start.Line}.");
1053+
}
1054+
1055+
public override void EnterTypeSpecifierFloatingPointWithFields(CtfParser.TypeSpecifierFloatingPointWithFieldsContext context)
1056+
{
1057+
this.PushFloatScope();
1058+
}
1059+
1060+
public override void ExitTypeSpecifierFloatingPointWithFields(CtfParser.TypeSpecifierFloatingPointWithFieldsContext context)
1061+
{
1062+
var propertyBag = this.CurrentScope.PropertyBag;
1063+
this.PopFloatScope(true);
1064+
1065+
context.TypeSpecifier = new CtfFloatingPointDescriptor(propertyBag);
1066+
}
1067+
10401068
// string {}
10411069
public override void ExitTypeSpecifierEmptyString(CtfParser.TypeSpecifierEmptyStringContext context)
10421070
{
@@ -1330,6 +1358,7 @@ private void PopEventScope()
13301358
this.PopScope();
13311359
}
13321360

1361+
// Integer
13331362
private void PushIntegerScope()
13341363
{
13351364
string name = $"[integer]_{this.integerCount}";
@@ -1342,6 +1371,20 @@ private void PopIntegerScope(bool removeFromParent = false)
13421371
this.PopScope(removeFromParent);
13431372
}
13441373

1374+
// Float
1375+
private void PushFloatScope()
1376+
{
1377+
string name = $"[floating_point]_{this.floatCount}";
1378+
this.floatCount++;
1379+
this.PushScope(name);
1380+
}
1381+
1382+
private void PopFloatScope(bool removeFromParent = false)
1383+
{
1384+
this.PopScope(removeFromParent);
1385+
}
1386+
1387+
// String
13451388
private void PushStringScope()
13461389
{
13471390
string name = $"[string]_{this.stringCount}";

CtfPlayback/Metadata/CtfTypes.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,6 @@ public enum CtfTypes
4646
/// <summary>
4747
/// A float CTF descriptor type
4848
/// </summary>
49-
Float
49+
FloatingPoint
5050
}
5151
}

CtfPlayback/Metadata/TypeInterfaces/ICtfFloatDescriptor.cs renamed to CtfPlayback/Metadata/TypeInterfaces/ICtfFloatingPointDescriptor.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
namespace CtfPlayback.Metadata.TypeInterfaces
55
{
66
/// <summary>
7-
/// This interface is not yet implemented
7+
/// Describes the properties of a floating point type.
88
/// </summary>
9-
public interface ICtfFloatDescriptor
9+
public interface ICtfFloatingPointDescriptor
1010
: ICtfTypeDescriptor
1111
{
1212
/// <summary>

CtfPlayback/Metadata/Types/CtfFloatDescriptor.cs

Lines changed: 0 additions & 48 deletions
This file was deleted.

0 commit comments

Comments
 (0)