OLD | NEW |
| (Empty) |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef NET_BASE_LOAD_LOG_UTIL_H_ | |
6 #define NET_BASE_LOAD_LOG_UTIL_H_ | |
7 | |
8 #include <string> | |
9 #include <vector> | |
10 | |
11 #include "base/basictypes.h" | |
12 #include "net/base/load_log.h" | |
13 | |
14 namespace net { | |
15 | |
16 // The LoadLogUtil utility class contains methods to analyze and visualize | |
17 // LoadLogs. | |
18 | |
19 class LoadLogUtil { | |
20 public: | |
21 struct EventDuration { | |
22 LoadLog::EventType event; | |
23 base::TimeDelta duration; | |
24 }; | |
25 typedef std::vector<EventDuration> EventDurationList; | |
26 | |
27 // Builds a pretty printed ASCII tree showing the chronological order | |
28 // of events. | |
29 // | |
30 // The indentation reflects hiearchy, with the duration of each indented | |
31 // block noted on the right. The timestamp (tick count in milliseconds) | |
32 // is noted in the left column. | |
33 // | |
34 // This detailed view of what went into servicing a request can be used | |
35 // in logs, and is copy-pastable by users, for attaching to bug reports. | |
36 // | |
37 // Example A: | |
38 // | |
39 // t=0: +Event1 [dt = 8] | |
40 // t=1: +Event2 [dt = 0] | |
41 // t=1: EventX | |
42 // t=1: -Event2 | |
43 // t=4: +Event3 [dt = 2] | |
44 // t=6: -Event3 | |
45 // t=6: +Event2 [dt = 1] | |
46 // t=7: -Event2 | |
47 // t=8: EventY | |
48 // t=8: -Event1 | |
49 // | |
50 // Here we can see that: | |
51 // - Event1 started at t=0 and ended at t=8; the duration was 8 time units. | |
52 // - Event2 took place while Event1 was in progress, and was repeated | |
53 // at t=1 and t=6. | |
54 // - EventX took place while (the first) Event2 was in progress. | |
55 // - Event3 started and ended at the same time, taking 0 time. | |
56 // - EventY took place right before Event1 finished, at t=8 | |
57 // | |
58 // In general the rules are: | |
59 // - Log entries added by BeginEvent() are prefixed with a '+' and | |
60 // start an indentation block. | |
61 // - Log entries added by EndEvent() are prefixed with a '-' and | |
62 // finish an indentation block. | |
63 // - Log entries added by AddEvent() have no prefix. | |
64 // - Time units are given as milliseconds. | |
65 // | |
66 static std::string PrettyPrintAsEventTree(const LoadLog* log); | |
67 | |
68 private: | |
69 DISALLOW_IMPLICIT_CONSTRUCTORS(LoadLogUtil); | |
70 }; | |
71 | |
72 } // namespace net | |
73 | |
74 #endif // NET_BASE_LOAD_LOG_UTIL_H_ | |
OLD | NEW |