24 Commits

Author SHA1 Message Date
hopehook
bcab684115 all: use time.Since instead of time.Now().Sub
Change-Id: Ie6ab0d9b0933f8c0dda84e7f8ad879e01c4eb337
Reviewed-on: https://go-review.googlesource.com/c/net/+/437095
Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Run-TryBot: hopehook <hopehook@golangcn.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
2022-10-02 02:25:38 +00:00
Brad Fitzpatrick
915654e7ea trace: tighten the check for duplicate registration
From comment at @santsai at https://github.com/golang/go/issues/24137#issuecomment-452983000

Change-Id: Icf0aff2172811752b240d94e709550b0da353360
Reviewed-on: https://go-review.googlesource.com/c/157378
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: JBD <jbd@google.com>
2019-01-10 20:02:30 +00:00
Brad Fitzpatrick
ccbb57fb48 trace: remove Go 1.6 support
Change-Id: I07355ffab9e0e9437dc43cb99670736fe65bc25a
Reviewed-on: https://go-review.googlesource.com/c/148437
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
2018-11-08 05:43:00 +00:00
Jean de Klerk
f4c29de78a trace: better error message for double init
Fixes golang/go#24137

Change-Id: Ifcf6449aed32071cdb643028347ec814bffd8d06
Reviewed-on: https://go-review.googlesource.com/127121
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-08-01 23:40:40 +00:00
David Howden
d0aafc73d5 trace: fix races on concurrent Trace method calls
This change protects fields mutated by Trace methods with a mutex.
In particular it fixes races caused by concurrent calls to IsError,
and viewing active traces in /debug/requests.

Includes changes from CL/67730.

Updates golang/go#24231

Change-Id: I07db54c2642efe0ea0e3ffeb54ec796ae51e70ef
Reviewed-on: https://go-review.googlesource.com/98535
Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2018-03-08 15:43:19 +00:00
Jaana Burcu Dogan
1816238e22 trace: export /debug/requests and /debug/events handlers
Fixes #20478.

Change-Id: I739b6f1368889b735944d74be2d16b7e09eb11a2
Reviewed-on: https://go-review.googlesource.com/45998
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2017-06-19 21:13:42 +00:00
Brad Fitzpatrick
d212a1ef2d trace: support Go 1.6 again
App Engine is stuck 14 months in the past and doesn't have context.

Updates golang/go#20056

Change-Id: I2cb2a3a75af07728805be8c714e4725f01a17074
Reviewed-on: https://go-review.googlesource.com/41413
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2017-04-23 03:31:48 +00:00
Brad Fitzpatrick
c8c7437759 trace: use standard library context
Fixes golang/go#20056

Change-Id: I139d531ae87273fdc2409d29d63bb9d67680f30a
Reviewed-on: https://go-review.googlesource.com/41290
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2017-04-21 00:26:09 +00:00
Tonis Tiigi
c427ad74c6 trace: initialize templates lazily
Parsing the templates can take a significant amount of
time(30-35ms) so it should not be done on the init phase.

Change-Id: I8f258b8028510e698a97b55faeac0d28a61b7b22
Reviewed-on: https://go-review.googlesource.com/21654
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2017-01-13 21:57:39 +00:00
Tormod Erevik Lea
cac22060de trace: remove internal Google reference from comment
Change-Id: I74ca09e4f4765c1c8d309b8fe1ce25b5e3d8171f
Reviewed-on: https://go-review.googlesource.com/33270
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2016-11-15 15:07:36 +00:00
Radu Berinde
f4b625ec9b trace: don't allocate all events upfront
SetMaxEvent allocates storage for all events, which is very expensive
if we want to set a high value; even with small values, the
unnecessary allocation of the initial slice is measurable.

We improve the performance by having a few events preallocated as part
of the trace, and appending as necessary. We also co-locate the flags
in event which makes it smaller (by a word).

We also add a set of benchmarks; before and after amortized cost
per-event is shown:

name                    old time/op  new time/op  delta
Trace_Default_2-32      1.19µs ± 1%  0.96µs ± 0%  -18.94%
Trace_Default_10-32      579ns ± 0%   635ns ± 1%   +9.82%
Trace_Default_100-32     463ns ± 1%   466ns ± 1%     ~
Trace_Default_1000-32    451ns ± 1%   451ns ± 0%     ~
Trace_Default_10000-32   451ns ± 2%   449ns ± 1%     ~
Trace_10_2-32           1.41µs ± 1%  0.96µs ± 1%  -31.74%
Trace_10_10-32           623ns ± 1%   634ns ± 1%   +1.73%
Trace_10_100-32          469ns ± 1%   466ns ± 1%     ~
Trace_10_1000-32         452ns ± 1%   453ns ± 2%     ~
Trace_10_10000-32        451ns ± 1%   449ns ± 1%     ~
Trace_100_2-32          2.78µs ± 2%  0.97µs ± 1%  -65.28%
Trace_100_10-32          912ns ± 1%   637ns ± 1%  -30.23%
Trace_100_100-32         479ns ± 1%   541ns ± 0%  +12.77%
Trace_100_1000-32        510ns ± 0%   541ns ± 1%   +6.08%
Trace_100_10000-32       514ns ± 1%   540ns ± 0%   +5.14%
Trace_1000_2-32         17.2µs ± 1%   1.0µs ± 1%  -94.39%
Trace_1000_10-32        3.90µs ± 1%  0.64µs ± 0%  -83.68%
Trace_1000_100-32        814ns ± 1%   542ns ± 0%  -33.46%
Trace_1000_1000-32       503ns ± 1%   581ns ± 0%  +15.56%
Trace_1000_10000-32     1.28µs ± 2%  1.03µs ± 1%  -19.68%

Change-Id: I5bbc12153a9f30dff821ef139583cb1c07a11069
Reviewed-on: https://go-review.googlesource.com/30615
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-10-07 14:35:04 +00:00
Brad Fitzpatrick
9b4f494e78 Revert "trace: don't allocate all events upfront"
This reverts commit If7c68bb1809fb92fa5d06cb6640be5e09e1f131f.

Reason for revert: breaks the build for Go 1.6 or below due to use of Go 1.7+ only features.

Original change's description:
> trace: don't allocate all events upfront
> 
> SetMaxEvent allocates storage for all events, which is very expensive
> if we want to set a high value; even with small values, the
> unnecessary allocation of the initial slice is measurable.
> 
> We improve the performance by having a few events preallocated as part
> of the trace, and appending as necessary. We also co-locate the flags
> in event which makes it smaller (by a word).
> 
> We also add a set of benchmarks; before and after amortized cost
> per-event is shown:
> 
> name                 old time/op  new time/op  delta
> Trace/0-2-32         1.19µs ± 1%  0.96µs ± 0%  -18.94%  (p=0.008 n=5+5)
> Trace/0-10-32         579ns ± 0%   635ns ± 1%   +9.82%  (p=0.008 n=5+5)
> Trace/0-100-32        463ns ± 1%   466ns ± 1%     ~     (p=0.190 n=5+5)
> Trace/0-1000-32       451ns ± 1%   451ns ± 0%     ~     (p=0.984 n=5+5)
> Trace/0-10000-32      451ns ± 2%   449ns ± 1%     ~     (p=0.492 n=5+5)
> Trace/10-2-32        1.41µs ± 1%  0.96µs ± 1%  -31.74%  (p=0.008 n=5+5)
> Trace/10-10-32        623ns ± 1%   634ns ± 1%   +1.73%  (p=0.008 n=5+5)
> Trace/10-100-32       469ns ± 1%   466ns ± 1%     ~     (p=0.357 n=5+5)
> Trace/10-1000-32      452ns ± 1%   453ns ± 2%     ~     (p=0.913 n=5+5)
> Trace/10-10000-32     451ns ± 1%   449ns ± 1%     ~     (p=0.175 n=5+5)
> Trace/100-2-32       2.78µs ± 2%  0.97µs ± 1%  -65.28%  (p=0.008 n=5+5)
> Trace/100-10-32       912ns ± 1%   637ns ± 1%  -30.23%  (p=0.008 n=5+5)
> Trace/100-100-32      479ns ± 1%   541ns ± 0%  +12.77%  (p=0.008 n=5+5)
> Trace/100-1000-32     510ns ± 0%   541ns ± 1%   +6.08%  (p=0.008 n=5+5)
> Trace/100-10000-32    514ns ± 1%   540ns ± 0%   +5.14%  (p=0.008 n=5+5)
> Trace/1000-2-32      17.2µs ± 1%   1.0µs ± 1%  -94.39%  (p=0.008 n=5+5)
> Trace/1000-10-32     3.90µs ± 1%  0.64µs ± 0%  -83.68%  (p=0.008 n=5+5)
> Trace/1000-100-32     814ns ± 1%   542ns ± 0%  -33.46%  (p=0.008 n=5+5)
> Trace/1000-1000-32    503ns ± 1%   581ns ± 0%  +15.56%  (p=0.008 n=5+5)
> Trace/1000-10000-32  1.28µs ± 2%  1.03µs ± 1%  -19.68%  (p=0.008 n=5+5)
> 
> Change-Id: If7c68bb1809fb92fa5d06cb6640be5e09e1f131f
> Reviewed-on: https://go-review.googlesource.com/30374
> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
> TryBot-Result: Gobot Gobot <gobot@golang.org>
> Reviewed-by: Ian Lance Taylor <iant@golang.org>
> 

Change-Id: I7cf25464ae836489e0af4a59a4d534a5d25ee352
Reviewed-on: https://go-review.googlesource.com/30650
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2016-10-07 04:33:39 +00:00
Radu Berinde
88c1a61b3d trace: don't allocate all events upfront
SetMaxEvent allocates storage for all events, which is very expensive
if we want to set a high value; even with small values, the
unnecessary allocation of the initial slice is measurable.

We improve the performance by having a few events preallocated as part
of the trace, and appending as necessary. We also co-locate the flags
in event which makes it smaller (by a word).

We also add a set of benchmarks; before and after amortized cost
per-event is shown:

name                 old time/op  new time/op  delta
Trace/0-2-32         1.19µs ± 1%  0.96µs ± 0%  -18.94%  (p=0.008 n=5+5)
Trace/0-10-32         579ns ± 0%   635ns ± 1%   +9.82%  (p=0.008 n=5+5)
Trace/0-100-32        463ns ± 1%   466ns ± 1%     ~     (p=0.190 n=5+5)
Trace/0-1000-32       451ns ± 1%   451ns ± 0%     ~     (p=0.984 n=5+5)
Trace/0-10000-32      451ns ± 2%   449ns ± 1%     ~     (p=0.492 n=5+5)
Trace/10-2-32        1.41µs ± 1%  0.96µs ± 1%  -31.74%  (p=0.008 n=5+5)
Trace/10-10-32        623ns ± 1%   634ns ± 1%   +1.73%  (p=0.008 n=5+5)
Trace/10-100-32       469ns ± 1%   466ns ± 1%     ~     (p=0.357 n=5+5)
Trace/10-1000-32      452ns ± 1%   453ns ± 2%     ~     (p=0.913 n=5+5)
Trace/10-10000-32     451ns ± 1%   449ns ± 1%     ~     (p=0.175 n=5+5)
Trace/100-2-32       2.78µs ± 2%  0.97µs ± 1%  -65.28%  (p=0.008 n=5+5)
Trace/100-10-32       912ns ± 1%   637ns ± 1%  -30.23%  (p=0.008 n=5+5)
Trace/100-100-32      479ns ± 1%   541ns ± 0%  +12.77%  (p=0.008 n=5+5)
Trace/100-1000-32     510ns ± 0%   541ns ± 1%   +6.08%  (p=0.008 n=5+5)
Trace/100-10000-32    514ns ± 1%   540ns ± 0%   +5.14%  (p=0.008 n=5+5)
Trace/1000-2-32      17.2µs ± 1%   1.0µs ± 1%  -94.39%  (p=0.008 n=5+5)
Trace/1000-10-32     3.90µs ± 1%  0.64µs ± 0%  -83.68%  (p=0.008 n=5+5)
Trace/1000-100-32     814ns ± 1%   542ns ± 0%  -33.46%  (p=0.008 n=5+5)
Trace/1000-1000-32    503ns ± 1%   581ns ± 0%  +15.56%  (p=0.008 n=5+5)
Trace/1000-10000-32  1.28µs ± 2%  1.03µs ± 1%  -19.68%  (p=0.008 n=5+5)

Change-Id: If7c68bb1809fb92fa5d06cb6640be5e09e1f131f
Reviewed-on: https://go-review.googlesource.com/30374
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2016-10-06 21:53:57 +00:00
Sam Whited
1f79cc9b4a trace: spelling consistency tweaks
s/customise/customize/
s/authorisation/authorization/

Change-Id: I23afdca1b773ef9572794555dfb768c9ded90ab8
Reviewed-on: https://go-review.googlesource.com/30159
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2016-10-01 16:38:42 +00:00
Nic Day
35ec611a14 net/trace: fix comment typo
Abbreviating "if and only if" to "iff" is against Go style in public
documentation; use expanded form.

Change-Id: I23afdca1b773ef9572794555dfb768c9ded90ab7
Reviewed-on: https://go-review.googlesource.com/22545
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2016-05-01 04:31:21 +00:00
Dave Day
35b06af072 trace: make AuthRequest robust to multiple RemoteAddr formats
Change-Id: Ia61f61d0b9395f383ff622f2d606dcd499f57776
Reviewed-on: https://go-review.googlesource.com/20588
Reviewed-by: David Symonds <dsymonds@golang.org>
2016-03-15 04:27:35 +00:00
Tamir Duberstein
0ab009005d trace: properly set the content type when sending html
Without this, if the responses are compressed, Chrome's content-type
detection will fail and it will attempt to download these pages rather
than render them as HTML.

Change-Id: Ib5f803f335d55a00a759de85d38855ee0ae13ee0
Reviewed-on: https://go-review.googlesource.com/18230
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2016-01-04 18:49:02 +00:00
Michael Gehring
ea47fc708e trace: fix EventLog example
Fixes golang/go#12387

Change-Id: Iecc42d9f809bed10036d1c3af8838c2fbf7ea93d
Reviewed-on: https://go-review.googlesource.com/14014
Reviewed-by: David Symonds <dsymonds@golang.org>
2015-08-29 23:03:18 +00:00
David Symonds
7654728e38 trace: Export Render and RenderEvents functions.
These expose the main HTML rendering functions of this package
for use with alternate HTTP muxes and on alternate paths.

Fixes golang/go#12195.

Change-Id: I679583fd26116bc83ff551a5d2a1d73ffa1e01f0
Reviewed-on: https://go-review.googlesource.com/13825
Reviewed-by: Dave Day <djd@golang.org>
2015-08-24 03:25:21 +00:00
David Symonds
788d8d9e19 trace: Make links in generated HTML be relative to the current path.
This will make it easier to serve /debug/requests off a different path.

This is groundwork towards addressing golang/go#12195.

Change-Id: If29a4c329609df1d5b09a3a88b8bdf1f8b622e49
Reviewed-on: https://go-review.googlesource.com/13824
Reviewed-by: Dave Day <djd@golang.org>
2015-08-24 03:23:39 +00:00
Sameer Ajmani
4a71d18255 net/trace: add event logs.
An event log is typically associated with a long-lived object, like an
RPC connection.  Printf calls record events; Errorf calls record
events marked as errors.  The HTTP endpoint /debug/events organizes
event logs by family (usually the Go type name) and by
time-since-last-error.  The expanded view shows recent events in the
log and the call stack where the event log was created.

Change-Id: I3461e0d63f39ce6495e16300299048e572b3aa19
Reviewed-on: https://go-review.googlesource.com/12025
Reviewed-by: David Symonds <dsymonds@golang.org>
2015-08-10 02:23:08 +00:00
David Symonds
38f3db3860 trace: Add NewContext and FromContext functions.
These will be the standard way for inserting a Trace into a Context,
and retrieving it later. NewContext will typically only be used by
top-level context creators (e.g. the gRPC package).

Change-Id: Ifb6fc81f46a71bb965196f664714d3042a9aea18
2015-06-22 16:16:26 +10:00
David Symonds
dfe268fd2b trace: Fix IPv6 local address detection.
net.SplitHostPort produces "::1", not "[::1]".

Change-Id: I5270e427ab25c2fbcae3593de47d5dd48cd92479
Reviewed-on: https://go-review.googlesource.com/10743
Reviewed-by: jcd . <jcd@golang.org>
2015-06-05 05:57:43 +00:00
David Symonds
e562cdb856 trace: New package.
Package trace implements tracing of requests.
It exports an HTTP interface on /debug/requests,
and higher level packages (e.g. an RPC system)
can construct and annotate traces.

Change-Id: I67e981ed28bc6a15e4ad5a02217500505896ce1c
Reviewed-on: https://go-review.googlesource.com/10741
Reviewed-by: Nigel Tao <nigeltao@golang.org>
2015-06-05 01:29:25 +00:00