Skip to content

Commit d0fda75

Browse files
Merge pull request #476 from m-lab/ss-sandbox-fix-starttime
Combine StartTimeStamp with StartTimeUsec as int64 value
2 parents a67003d + 9d06ba8 commit d0fda75

File tree

2 files changed

+35
-5
lines changed

2 files changed

+35
-5
lines changed

parser/ss.go

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,25 +152,36 @@ func ParseOneLine(snapshot string, var_names []string) (map[string]string, error
152152

153153
func PopulateSnap(ss_value map[string]string) (schema.Web100Snap, error) {
154154
var snap = &schema.Web100Snap{}
155+
var startTimeUsec int64
156+
157+
// First, extract StartTimeUsec value before all others so we can combine
158+
// it with StartTimeStamp below.
159+
if valueStr, ok := ss_value["StartTimeUsec"]; ok {
160+
value, err := strconv.ParseInt(valueStr, 10, 64)
161+
if err == nil {
162+
startTimeUsec = value
163+
}
164+
}
165+
166+
// Process every other snap key.
155167
for key := range ss_value {
156168
// Skip cid and PollTime. They are SideStream-specific fields, not web100 variables.
157169
if key == "cid" || key == "PollTime" {
158170
continue
159171
}
160-
// We do special handling for this variable
172+
// Skip StartTimeUsec because this is not part of the Web100Snap struct.
161173
if key == "StartTimeUsec" {
162-
// TODO: func CalculateStartTimeStamp() to get correct StartTimeStamp value.
163174
continue
164175
}
165176
x := reflect.ValueOf(snap).Elem().FieldByName(key)
166177

167178
switch x.Type().String() {
168179
case "int64":
169-
value, err := strconv.Atoi(ss_value[key])
180+
value, err := strconv.ParseInt(ss_value[key], 10, 64)
170181
if err != nil {
171182
return *snap, err
172183
}
173-
x.SetInt(int64(value))
184+
x.SetInt(value)
174185
case "string":
175186
x.Set(reflect.ValueOf(ss_value[key]))
176187
case "bool":
@@ -183,6 +194,9 @@ func PopulateSnap(ss_value map[string]string) (schema.Web100Snap, error) {
183194
}
184195
}
185196
}
197+
// Combine the StartTimeStamp and StartTimeUsec values.
198+
snap.StartTimeStamp = snap.StartTimeStamp*1000000 + startTimeUsec
199+
186200
// TODO: check whether snap has valid LocalAddress, RemAddress. Return error if not.
187201
return *snap, nil
188202
}

parser/ss_test.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,26 @@ func TestPopulateSnap(t *testing.T) {
2121
ss_value["CERcvd"] = "22"
2222
ss_value["RemAddress"] = "abcd"
2323
ss_value["TimeStampRcvd"] = "0"
24-
_, err := parser.PopulateSnap(ss_value)
24+
ss_value["StartTimeStamp"] = "2222"
25+
ss_value["StartTimeUsec"] = "1111"
26+
snap, err := parser.PopulateSnap(ss_value)
2527
if err != nil {
2628
t.Fatalf("Snap fields not populated correctly.")
2729
}
30+
31+
if snap.TimeStampRcvd != false {
32+
t.Errorf("TimeStampRcvd; got %t; want false", snap.TimeStampRcvd)
33+
}
34+
if snap.RemAddress != "abcd" {
35+
t.Errorf("RemAddress; got %q; want 'abcd'", snap.RemAddress)
36+
}
37+
if snap.CERcvd != 22 {
38+
t.Errorf("CERcvd; got %d; want 22", snap.CERcvd)
39+
}
40+
// Verify StartTimeStamp is combined correctly with StartTimeUsec.
41+
if snap.StartTimeStamp != 2222001111 {
42+
t.Errorf("StartTimeStamp; got %d; want 222001111", snap.StartTimeStamp)
43+
}
2844
}
2945

3046
func TestParseOneLine(t *testing.T) {

0 commit comments

Comments
 (0)