浏览代码

Merge pull request #81 from Sajmani/master

profile.parseGoCount: accept non-space characters in profile type.
Raul Silvera 8 年前
父节点
当前提交
e52d3f70f6
共有 2 个文件被更改,包括 39 次插入1 次删除
  1. 1
    1
      profile/legacy_profile.go
  2. 38
    0
      profile/legacy_profile_test.go

+ 1
- 1
profile/legacy_profile.go 查看文件

29
 )
29
 )
30
 
30
 
31
 var (
31
 var (
32
-	countStartRE = regexp.MustCompile(`\A(\w+) profile: total \d+\z`)
32
+	countStartRE = regexp.MustCompile(`\A(\S+) profile: total \d+\z`)
33
 	countRE      = regexp.MustCompile(`\A(\d+) @(( 0x[0-9a-f]+)+)\z`)
33
 	countRE      = regexp.MustCompile(`\A(\d+) @(( 0x[0-9a-f]+)+)\z`)
34
 
34
 
35
 	heapHeaderRE = regexp.MustCompile(`heap profile: *(\d+): *(\d+) *\[ *(\d+): *(\d+) *\] *@ *(heap[_a-z0-9]*)/?(\d*)`)
35
 	heapHeaderRE = regexp.MustCompile(`heap profile: *(\d+): *(\d+) *\[ *(\d+): *(\d+) *\] *@ *(heap[_a-z0-9]*)/?(\d*)`)

+ 38
- 0
profile/legacy_profile_test.go 查看文件

264
 		}
264
 		}
265
 	}
265
 	}
266
 }
266
 }
267
+
268
+func TestParseGoCount(t *testing.T) {
269
+	for _, test := range []struct {
270
+		in  string
271
+		typ string
272
+	}{
273
+		{
274
+			in: `# ignored comment
275
+
276
+threadcreate profile: total 123
277
+`,
278
+			typ: "threadcreate",
279
+		},
280
+		{
281
+			in: `
282
+# ignored comment
283
+goroutine profile: total 123456
284
+`,
285
+			typ: "goroutine",
286
+		},
287
+		{
288
+			in: `
289
+sub/dir-ect_o.ry profile: total 999
290
+`,
291
+			typ: "sub/dir-ect_o.ry",
292
+		},
293
+	} {
294
+		t.Run(test.typ, func(t *testing.T) {
295
+			p, err := parseGoCount([]byte(test.in))
296
+			if err != nil {
297
+				t.Fatalf("parseGoCount(%q) = %v", test.in, err)
298
+			}
299
+			if typ := p.PeriodType.Type; typ != test.typ {
300
+				t.Fatalf("parseGoCount(%q).PeriodType.Type = %q want %q", test.in, typ, test.typ)
301
+			}
302
+		})
303
+	}
304
+}