Skip to content

Commit 3bff2c2

Browse files
committed
Adding support for Tags
1 parent fc2dd85 commit 3bff2c2

8 files changed

Lines changed: 146 additions & 15 deletions

File tree

src/HdrHistogram.UnitTests/HdrHistogram.UnitTests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@
122122
<EmbeddedResource Include="Resources\jHiccup-2.0.6.logV1.hlog" />
123123
<EmbeddedResource Include="Resources\jHiccup-2.0.7S.logV2.hlog" />
124124
<EmbeddedResource Include="Resources\ycsb.logV1.hlog" />
125+
<EmbeddedResource Include="Resources\tagged-Log.logV2.hlog" />
125126
</ItemGroup>
126127
<ItemGroup>
127128
<ProjectReference Include="..\HdrHistogram\HdrHistogram.csproj">

src/HdrHistogram.UnitTests/HistogramAssert.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public static void AreEqual(HistogramBase expected, HistogramBase actual)
1414
public static void AreValueEqual(HistogramBase expected, HistogramBase actual)
1515
{
1616
Assert.AreEqual(expected.TotalCount, actual.TotalCount, "TotalCount property is not equal.");
17+
Assert.AreEqual(expected.Tag, actual.Tag, "Tag property is not equal.");
1718
Assert.AreEqual(expected.StartTimeStamp, actual.StartTimeStamp, "StartTimeStamp property is not equal.");
1819
Assert.AreEqual(expected.EndTimeStamp, actual.EndTimeStamp, "EndTimeStamp property is not equal.");
1920
Assert.AreEqual(expected.LowestTrackableValue, actual.LowestTrackableValue, "LowestTrackableValue property is not equal.");

src/HdrHistogram.UnitTests/HistogramTestBase.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,18 @@ public void Copy_retains_all_public_properties()
337337
HistogramAssert.AreValueEqual(source, copy);
338338
}
339339

340+
[TestCase("No spaces")]
341+
[TestCase("No,commas")]
342+
[TestCase("\r")]
343+
[TestCase("\n")]
344+
[TestCase(" ")]
345+
[TestCase(" ")]
346+
public void Setting_invalid_value_to_Tag_throws(string invalidTagValue)
347+
{
348+
var histogram = Create(DefaultHighestTrackableValue, DefaultSignificantFigures);
349+
Assert.Throws<ArgumentException>(() => histogram.Tag = invalidTagValue);
350+
}
351+
340352
private void CreateAndAdd(HistogramBase source)
341353
{
342354
source.RecordValueWithCount(1, 100);

src/HdrHistogram.UnitTests/Persistence/HistogramLogReaderWriterTestBase.cs

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public void CanRoundTripSingleHistogram(long highestTrackableValue, int signific
5050
Assert.AreEqual(1, actualHistograms.Length);
5151
HistogramAssert.AreValueEqual(histogram, actualHistograms.Single());
5252
}
53-
53+
5454
protected void RoundTripSingleHistogramsWithFullRangesOfCountsAndValues(long count)
5555
{
5656
var value = 1;
@@ -65,10 +65,12 @@ protected void RoundTripSingleHistogramsWithFullRangesOfCountsAndValues(long cou
6565
HistogramAssert.AreValueEqual(histogram, actualHistograms.Single());
6666
}
6767

68-
[Test]
69-
public void CanRoundTripSingleHistogramsWithSparseValues()
68+
[TestCase("ATag")]
69+
[TestCase("AnotherTag")]
70+
public void CanRoundTripSingleHistogramsWithSparseValues(string tag)
7071
{
7172
var histogram = Create(DefaultHighestTrackableValue, DefaultSignificantDigits);
73+
histogram.Tag = tag;
7274
histogram.RecordValue(1);
7375
histogram.RecordValue((long.MaxValue / 2) + 1);
7476

@@ -77,6 +79,7 @@ public void CanRoundTripSingleHistogramsWithSparseValues()
7779
var actualHistograms = data.ReadHistograms();
7880

7981
Assert.AreEqual(1, actualHistograms.Length);
82+
Assert.AreEqual(tag, actualHistograms[0].Tag);
8083
HistogramAssert.AreValueEqual(histogram, actualHistograms.Single());
8184
}
8285

@@ -93,7 +96,7 @@ public void CanAppendHistogram()
9396

9497
byte[] data;
9598
using (var writerStream = new MemoryStream())
96-
using(var log = new HistogramLogWriter(writerStream))
99+
using (var log = new HistogramLogWriter(writerStream))
97100
{
98101
log.Append(histogram1);
99102
log.Append(histogram2);
@@ -105,7 +108,40 @@ public void CanAppendHistogram()
105108
HistogramAssert.AreValueEqual(histogram1, actualHistograms.First());
106109
HistogramAssert.AreValueEqual(histogram2, actualHistograms.Skip(1).First());
107110
}
108-
111+
112+
[TestCase("tagged-Log.logV2.hlog")]
113+
public void CanReadV2TaggedLogs(string logPath)
114+
{
115+
var readerStream = GetEmbeddedFileStream(logPath);
116+
var reader = new HistogramLogReader(readerStream);
117+
int histogramCount = 0;
118+
long totalCount = 0;
119+
var accumulatedHistogramWithNoTag = Create(85899345920838, DefaultSignificantDigits);
120+
var accumulatedHistogramWithTagA = Create(85899345920838, DefaultSignificantDigits);
121+
foreach (var histogram in reader.ReadHistograms())
122+
{
123+
histogramCount++;
124+
Assert.IsInstanceOf<HistogramBase>(histogram, "Expected integer value histograms in log file");
125+
126+
totalCount += histogram.TotalCount;
127+
if (string.IsNullOrEmpty(histogram.Tag))
128+
{
129+
accumulatedHistogramWithNoTag.Add(histogram);
130+
}
131+
else if (histogram.Tag == "A")
132+
{
133+
accumulatedHistogramWithTagA.Add(histogram);
134+
}
135+
}
136+
137+
Assert.AreEqual(42, histogramCount);
138+
Assert.AreEqual(32290, totalCount);
139+
140+
HistogramAssert.AreValueEqual(accumulatedHistogramWithNoTag, accumulatedHistogramWithTagA);
141+
}
142+
143+
144+
109145
[TestCase("jHiccup-2.0.7S.logV2.hlog")]
110146
public void CanReadv2Logs(string logPath)
111147
{
@@ -129,7 +165,7 @@ public void CanReadv2Logs(string logPath)
129165
Assert.AreEqual(1796210687, accumulatedHistogram.GetMaxValue());
130166
Assert.AreEqual(1441812279.474, reader.GetStartTime().SecondsSinceUnixEpoch());
131167
}
132-
168+
133169
[TestCase("jHiccup-2.0.1.logV0.hlog", 0, int.MaxValue, 81, 61256, 1510998015, 1569718271, 1438869961.225)]
134170
[TestCase("jHiccup-2.0.1.logV0.hlog", 19, 25, 25, 18492, 459007, 623103, 1438869961.225)]
135171
[TestCase("jHiccup-2.0.1.logV0.hlog", 45, 34, 34, 25439, 1209008127, 1234173951, 1438869961.225)]
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#[Logged with jHiccup version 2.0.7-SNAPSHOT, manually edited to duplicate contents with Tag=A]
2+
#[Histogram log format version 1.2]
3+
#[StartTime: 1441812279.474 (seconds since epoch), Wed Sep 09 08:24:39 PDT 2015]
4+
"StartTimestamp","Interval_Length","Interval_Max","Interval_Compressed_Histogram"
5+
0.127,1.007,2.769,HISTFAAAAEV42pNpmSzMwMCgyAABTBDKT4GBgdnNYMcCBvsPEBEJISEuATEZMQ4uASkhIR4nrxg9v2lMaxhvMekILGZkKmcCAEf2CsI=
6+
Tag=A,0.127,1.007,2.769,HISTFAAAAEV42pNpmSzMwMCgyAABTBDKT4GBgdnNYMcCBvsPEBEJISEuATEZMQ4uASkhIR4nrxg9v2lMaxhvMekILGZkKmcCAEf2CsI=
7+
1.134,0.999,0.442,HISTFAAAAEJ42pNpmSzMwMAgxwABTBDKT4GBgdnNYMcCBvsPEBEWLj45FTExAT4pBSEBKa6UkAgBi1uM7xjfMMlwMDABAC0CCjM=
8+
Tag=A,1.134,0.999,0.442,HISTFAAAAEJ42pNpmSzMwMAgxwABTBDKT4GBgdnNYMcCBvsPEBEWLj45FTExAT4pBSEBKa6UkAgBi1uM7xjfMMlwMDABAC0CCjM=
9+
2.133,1.001,0.426,HISTFAAAAD942pNpmSzMwMAgwwABTBDKT4GBgdnNYMcCBvsPEBE+Ph4OLgk5OSkeIS4+LgEeswIDo1+MbmdYNASYAA51CSo=
10+
Tag=A,2.133,1.001,0.426,HISTFAAAAD942pNpmSzMwMAgwwABTBDKT4GBgdnNYMcCBvsPEBE+Ph4OLgk5OSkeIS4+LgEeswIDo1+MbmdYNASYAA51CSo=
11+
3.134,1.001,0.426,HISTFAAAAD942pNpmSzMwMAgwwABTBDKT4GBgdnNYMcCBvsPEBExPiEpITEFGTkRKSEeOR6FkCg1hTeMXvNYlHhYABQ5CTo=
12+
Tag=A,3.134,1.001,0.426,HISTFAAAAD942pNpmSzMwMAgwwABTBDKT4GBgdnNYMcCBvsPEBExPiEpITEFGTkRKSEeOR6FkCg1hTeMXvNYlHhYABQ5CTo=
13+
4.135,0.997,0.426,HISTFAAAAD942pNpmSzMwMAgwwABTBDKT4GBgdnNYMcCBvsPEBE2PiERBREpBREhER4+Hj4uvQAdrTlMBldYDDhYAAugCKk=
14+
Tag=A,4.135,0.997,0.426,HISTFAAAAD942pNpmSzMwMAgwwABTBDKT4GBgdnNYMcCBvsPEBE2PiERBREpBREhER4+Hj4uvQAdrTlMBldYDDhYAAugCKk=
15+
5.132,1.002,0.426,HISTFAAAAEF42pNpmSzMwMAgywABTBDKT4GBgdnNYMcCBvsPEBEWPhElOR4pARUpKTkpGQkxq2mMegZnGI0+MZuIcAEAHo8Jvw==
16+
Tag=A,5.132,1.002,0.426,HISTFAAAAEF42pNpmSzMwMAgywABTBDKT4GBgdnNYMcCBvsPEBEWPhElOR4pARUpKTkpGQkxq2mMegZnGI0+MZuIcAEAHo8Jvw==
17+
6.134,0.999,0.442,HISTFAAAAEF42pNpmSzMwMAgxwABTBDKT4GBgdnNYMcCBvsPEBEWIS4FITEhDiEJERE+GT6ZkhZGLbl7jEqrWHREmFgAIbAJMw==
18+
Tag=A,6.134,0.999,0.442,HISTFAAAAEF42pNpmSzMwMAgxwABTBDKT4GBgdnNYMcCBvsPEBEWIS4FITEhDiEJERE+GT6ZkhZGLbl7jEqrWHREmFgAIbAJMw==
19+
7.133,0.999,0.459,HISTFAAAAEJ42pNpmSzMwMCgwAABTBDKD8hndjPYsYDB/gNEhEtMQEBBTk5MQERCRkBEQEWlh9FJbg9jE+MS5ig1LhYmADkkCcE=
20+
Tag=A,7.133,0.999,0.459,HISTFAAAAEJ42pNpmSzMwMCgwAABTBDKD8hndjPYsYDB/gNEhEtMQEBBTk5MQERCRkBEQEWlh9FJbg9jE+MS5ig1LhYmADkkCcE=
21+
8.132,1.000,0.459,HISTFAAAAEB42pNpmSzMwMAgxwABTBDKT4GBgdnNYMcCBvsPEBEWIREgEOIQEuGT4xHg41Oo0pIqu8LYwVImwMfGBAAfkgkw
22+
Tag=A,8.132,1.000,0.459,HISTFAAAAEB42pNpmSzMwMAgxwABTBDKT4GBgdnNYMcCBvsPEBEWIREgEOIQEuGT4xHg41Oo0pIqu8LYwVImwMfGBAAfkgkw
23+
9.132,1.751,1551.892,HISTFAAAAJZ42pNpmSzMwMB0nQECmCCUnwIDA7ObwY4FDPYfYDJMXFxsbGwMbBwszDwsDDxsHFw6RWJMLJMZmcqBMJrJmskSiA2ZZJmkgRBCgmheIORGI1H5rEzMQAyDzFhY2EWRWUwMWCBxQtQQhAIWJiyAaEHyFbKwsLHAADYWAWmiFeKS5gACLsIEzdQICAgBIQShEfhFABXDF+M=
24+
Tag=A,9.132,1.751,1551.892,HISTFAAAAJZ42pNpmSzMwMB0nQECmCCUnwIDA7ObwY4FDPYfYDJMXFxsbGwMbBwszDwsDDxsHFw6RWJMLJMZmcqBMJrJmskSiA2ZZJmkgRBCgmheIORGI1H5rEzMQAyDzFhY2EWRWUwMWCBxQtQQhAIWJiyAaEHyFbKwsLHAADYWAWmiFeKS5gACLsIEzdQICAgBIQShEfhFABXDF+M=
25+
10.883,0.250,0.426,HISTFAAAAD142pNpmSzMwMAgxQABTBDKT4GBgdnNYMcCBvsPEBEeFi4mPg4WLhY2BjY2FhYOBSkpASEtoRA+NgDkCQZR
26+
Tag=A,10.883,0.250,0.426,HISTFAAAAD142pNpmSzMwMAgxQABTBDKT4GBgdnNYMcCBvsPEBEeFi4mPg4WLhY2BjY2FhYOBSkpASEtoRA+NgDkCQZR
27+
11.133,1.003,0.524,HISTFAAAAER42pNpmSzMwMCgyAABTBDKT4GBgdnNYMcCBvsPUBk2HgkZKREpEQUeGSEBAQ6xSYxhCnp7GJ02sWgJsbCwMgEAO0AJSQ==
28+
Tag=A,11.133,1.003,0.524,HISTFAAAAER42pNpmSzMwMCgyAABTBDKT4GBgdnNYMcCBvsPUBk2HgkZKREpEQUeGSEBAQ6xSYxhCnp7GJ02sWgJsbCwMgEAO0AJSQ==
29+
12.136,0.997,0.459,HISTFAAAAEB42pNpmSzMwMAgxwABTBDKT4GBgdnNYMcCBvsPUBk2AT4eCQURHgkuEREOHjERlSQhhWuMSV9Y7ERYWAAa4gko
30+
Tag=A,12.136,0.997,0.459,HISTFAAAAEB42pNpmSzMwMAgxwABTBDKT4GBgdnNYMcCBvsPUBk2AT4eCQURHgkuEREOHjERlSQhhWuMSV9Y7ERYWAAa4gko
31+
13.133,0.998,0.459,HISTFAAAAD942pNpmSzMwMAgxwABTBDKT4GBgdnNYMcCBvsPMBkRIR4RMRk5KQE+PgEhMRmzEjWZJ4whW1hMBNiYAB42CTA=
32+
Tag=A,13.133,0.998,0.459,HISTFAAAAD942pNpmSzMwMAgxwABTBDKT4GBgdnNYMcCBvsPMBkRIR4RMRk5KQE+PgEhMRmzEjWZJ4whW1hMBNiYAB42CTA=
33+
14.131,1.000,0.492,HISTFAAAAEN42pNpmSzMwMCgyAABTBDKT4GBgdnNYMcCBvsPUBkWFhE5GT4FKQkRCR4ZCREpqwmMBhpHGG16WHx42JgYmAA6swk+
34+
Tag=A,14.131,1.000,0.492,HISTFAAAAEN42pNpmSzMwMCgyAABTBDKT4GBgdnNYMcCBvsPUBkWFhE5GT4FKQkRCR4ZCREpqwmMBhpHGG16WHx42JgYmAA6swk+
35+
15.131,1.001,0.442,HISTFAAAAD542pNpmSzMwMAgywABTBDKT4GBgdnNYMcCBvsPMBkuMTEFHgklFRkRATkJERGdKgudfYwRTSwGalwAF2IJOw==
36+
Tag=A,15.131,1.001,0.442,HISTFAAAAD542pNpmSzMwMAgywABTBDKT4GBgdnNYMcCBvsPMBkuMTEFHgklFRkRATkJERGdKgudfYwRTSwGalwAF2IJOw==
37+
16.132,1.001,0.524,HISTFAAAAEZ42pNpmSzMwMCgxAABTBDKT4GBgdnNYMcCBvsPEBE2IQEFCQkpGREpHj4hKS6NU4z7GDMkuBoYDSYw2wiwMLEyAQBQ3wne
38+
Tag=A,16.132,1.001,0.524,HISTFAAAAEZ42pNpmSzMwMCgxAABTBDKT4GBgdnNYMcCBvsPEBE2IQEFCQkpGREpHj4hKS6NU4z7GDMkuBoYDSYw2wiwMLEyAQBQ3wne
39+
17.133,0.998,0.459,HISTFAAAAEB42pNpmSzMwMAgxwABTBDKT4GBgdnNYMcCBvsPUBk2DjElIR4RHiExKQE5IT61iCodtXWMdn0sKVJMTAAekAk0
40+
Tag=A,17.133,0.998,0.459,HISTFAAAAEB42pNpmSzMwMAgxwABTBDKT4GBgdnNYMcCBvsPUBk2DjElIR4RHiExKQE5IT61iCodtXWMdn0sKVJMTAAekAk0
41+
18.131,1.000,0.459,HISTFAAAAEF42pNpmSzMwMAgzwABTBDKT4GBgdnNYMcCBvsPUBkWISERJSUJESklHhEJEREhqwZGLakPjDZdLBYCHCwAKOkJPg==
42+
Tag=A,18.131,1.000,0.459,HISTFAAAAEF42pNpmSzMwMAgzwABTBDKT4GBgdnNYMcCBvsPUBkWISERJSUJESklHhEJEREhqwZGLakPjDZdLBYCHCwAKOkJPg==
43+
19.131,1.000,0.475,HISTFAAAAEF42pNpmSzMwMAgzwABTBDKT4GBgdnNYMcCBvsPUAk2HjkJBSk+Pi4BMT4xIQE9pxIluTOMPhtYbITY2JgAKLoJOQ==
44+
Tag=A,19.131,1.000,0.475,HISTFAAAAEF42pNpmSzMwMAgzwABTBDKT4GBgdnNYMcCBvsPUAk2HjkJBSk+Pi4BMT4xIQE9pxIluTOMPhtYbITY2JgAKLoJOQ==
45+
20.131,1.004,0.475,HISTFAAAAEF42pNpmSzMwMAgxwABTBDKT4GBgdnNYMcCBvsPEBFmPhEJOSEhDi4+ETEeASEhswIVi1+MFjtYvCRYGJgAIP8JNw==
46+
Tag=A,20.131,1.004,0.475,HISTFAAAAEF42pNpmSzMwMAgxwABTBDKT4GBgdnNYMcCBvsPEBFmPhEJOSEhDi4+ETEeASEhswIVi1+MFjtYvCRYGJgAIP8JNw==

src/HdrHistogram/HistogramBase.cs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using System;
1010
using System.Collections.Generic;
1111
using System.Diagnostics;
12+
using System.Text.RegularExpressions;
1213
using System.Threading;
1314
using HdrHistogram.Encoding;
1415
using HdrHistogram.Iteration;
@@ -37,6 +38,7 @@ namespace HdrHistogram
3738
/// </remarks>
3839
public abstract class HistogramBase : IRecorder
3940
{
41+
private static readonly Regex TagValidation = new Regex("[, \\r\\n]", RegexOptions.Compiled);
4042
private static long _instanceIdSequencer = -1;
4143

4244
private readonly int _subBucketHalfCountMagnitude;
@@ -45,6 +47,7 @@ public abstract class HistogramBase : IRecorder
4547
private readonly int _bucketIndexOffset;
4648
private long _maxValue;
4749
private long _minNonZeroValue;
50+
private string _tag;
4851

4952
/// <summary>
5053
/// An identifier for the Histogram. Maybe generated by the Recorder if used.
@@ -81,6 +84,21 @@ public abstract class HistogramBase : IRecorder
8184
/// </summary>
8285
public long EndTimeStamp { get; set; }
8386

87+
/// <summary>
88+
/// Gets or Sets the optional Tag string associated with this histogram.
89+
/// </summary>
90+
public string Tag
91+
{
92+
get { return _tag; }
93+
set
94+
{
95+
if(!string.IsNullOrEmpty(value) && TagValidation.IsMatch(value))
96+
throw new ArgumentException("Tag string cannot contain commas, spaces, or line breaks.");
97+
_tag = value;
98+
}
99+
}
100+
101+
84102
/// <summary>
85103
/// Gets the total number of recorded values.
86104
/// </summary>
@@ -113,7 +131,6 @@ public abstract class HistogramBase : IRecorder
113131
/// </summary>
114132
protected abstract long MaxAllowableCount { get; }
115133

116-
117134

118135
/// <summary>
119136
/// Construct a histogram given the lowest and highest values to be tracked and a number of significant decimal digits.

src/HdrHistogram/HistogramLogReader.cs

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ public sealed class HistogramLogReader : IDisposable, IHistogramLogV1Reader
1515
private static readonly Regex StartTimeMatcher = new Regex(@"#\[StartTime: (?<seconds>\d*\.\d{1,3}) ", RegexOptions.Compiled);
1616
private static readonly Regex BaseTimeMatcher = new Regex(@"#\[BaseTime: (?<seconds>\d*\.\d{1,3}) ", RegexOptions.Compiled);
1717
//Content lines - format = startTimestamp, intervalLength, maxTime, histogramPayload
18-
private static readonly Regex LogLineMatcher = new Regex(@"(?<startTime>\d*\.\d*),(?<interval>\d*\.\d*),(?<max>\d*\.\d*),(?<payload>.*)", RegexOptions.Compiled);
18+
private static readonly Regex UntaggedLogLineMatcher = new Regex(@"(?<startTime>\d*\.\d*),(?<interval>\d*\.\d*),(?<max>\d*\.\d*),(?<payload>.*)", RegexOptions.Compiled);
19+
private static readonly Regex TaggedLogLineMatcher = new Regex(@"((?<tag>Tag=.+),)?(?<startTime>\d*\.\d*),(?<interval>\d*\.\d*),(?<max>\d*\.\d*),(?<payload>.*)", RegexOptions.Compiled);
1920
private readonly TextReader _log;
2021
private double _startTimeInSeconds;
2122

@@ -77,7 +78,8 @@ public IEnumerable<HistogramBase> ReadHistograms()
7778
{
7879
//Content lines - format = startTimestamp, intervalLength, maxTime, histogramPayload
7980

80-
var match = LogLineMatcher.Match(line);
81+
var match = TaggedLogLineMatcher.Match(line);
82+
var tag = ParseTag(match.Groups["tag"].Value);
8183
var logTimeStampInSec = ParseDouble(match, "startTime");
8284
var intervalLength = ParseDouble(match, "interval");
8385
var maxTime = ParseDouble(match, "max"); //Ignored as it can be inferred -LC
@@ -99,7 +101,8 @@ public IEnumerable<HistogramBase> ReadHistograms()
99101
// StartTime), we assume that timestamps in the log are not absolute
100102
baseTimeInSeconds = _startTimeInSeconds;
101103
}
102-
else {
104+
else
105+
{
103106
// Timestamps are absolute
104107
baseTimeInSeconds = 0.0;
105108
}
@@ -113,13 +116,14 @@ public IEnumerable<HistogramBase> ReadHistograms()
113116
byte[] bytes = Convert.FromBase64String(payload);
114117
var buffer = ByteBuffer.Allocate(bytes);
115118
var histogram = DecodeHistogram(buffer, 0);
119+
histogram.Tag = tag;
116120
histogram.StartTimeStamp = (long)(absoluteStartTimeStampSec * 1000.0);
117121
histogram.EndTimeStamp = (long)(absoluteEndTimeStampSec * 1000.0);
118122
yield return histogram;
119123
}
120124
}
121125
}
122-
126+
123127
IEnumerable<HistogramBase> IHistogramLogV1Reader.ReadHistograms()
124128
{
125129
_startTimeInSeconds = 0;
@@ -152,11 +156,12 @@ IEnumerable<HistogramBase> IHistogramLogV1Reader.ReadHistograms()
152156
{
153157
//Content lines - format = startTimestamp, intervalLength, maxTime, histogramPayload
154158

155-
var match = LogLineMatcher.Match(line);
159+
var match = UntaggedLogLineMatcher.Match(line);
156160
var logTimeStampInSec = ParseDouble(match, "startTime");
157161
var intervalLength = ParseDouble(match, "interval");
158162
var maxTime = ParseDouble(match, "max"); //Ignored as it can be inferred -LC
159163
var payload = match.Groups["payload"].Value;
164+
160165

161166
if (!hasStartTime)
162167
{
@@ -173,7 +178,8 @@ IEnumerable<HistogramBase> IHistogramLogV1Reader.ReadHistograms()
173178
// StartTime), we assume that timestamps in the log are not absolute
174179
baseTimeInSeconds = _startTimeInSeconds;
175180
}
176-
else {
181+
else
182+
{
177183
// Timestamps are absolute
178184
baseTimeInSeconds = 0.0;
179185
}
@@ -255,6 +261,16 @@ private static bool IsV1Legend(string line)
255261
return line.Equals(legend);
256262
}
257263

264+
private static string ParseTag(string value)
265+
{
266+
if (string.IsNullOrWhiteSpace(value))
267+
return null;
268+
value = value.Substring(4);
269+
if (string.IsNullOrWhiteSpace(value))
270+
return null;
271+
return value;
272+
}
273+
258274
private static double ParseStartTime(string line)
259275
{
260276
var match = StartTimeMatcher.Match(line);

src/HdrHistogram/HistogramLogWriter.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace HdrHistogram
1111
/// <seealso cref="HistogramLogReader"/>
1212
public sealed class HistogramLogWriter : IDisposable
1313
{
14-
private const string HistogramLogFormatVersion = "1.2";
14+
private const string HistogramLogFormatVersion = "1.3";
1515

1616
private readonly TextWriter _log;
1717
private bool _hasHeaderWritten = false;
@@ -119,7 +119,9 @@ private void WriteHistogram(HistogramBase histogram)
119119
var intervalMax = histogram.GetMaxValue() / maxValueUnitRatio;
120120

121121
var binary = Convert.ToBase64String(compressedArray);
122-
var payload = $"{startTimeStampSec:F3},{intervalLength:F3},{intervalMax:F3},{binary}";
122+
var payload = histogram.Tag == null
123+
? $"{startTimeStampSec:F3},{intervalLength:F3},{intervalMax:F3},{binary}"
124+
: $"Tag={histogram.Tag},{startTimeStampSec:F3},{intervalLength:F3},{intervalMax:F3},{binary}";
123125
_log.WriteLine(payload);
124126
_log.Flush();
125127
}

0 commit comments

Comments
 (0)