File: README.md

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (107 lines) | stat: -rw-r--r-- 3,508 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# Trace Annotator Tool

## Introduction

A tool to annotate functions with ```c++ TRACE_EVENT```. This tool serves two
workflows:

*  Debugging: bulk add traces to all functions in a directory and after finding
   the bug remove the traces.
*  Adding traces to code: bulk add traces to all functions in a directory,
   review the changes carefully and create a patch.

The goal of this tool is to transfer a function:
```c++
int foo(int bar, int baz) {
  return 42;
}
```
into:
```c++
int foo(int bar, int baz) {
  TRACE_EVENT0("test", "foo");
  return 42;
}
```

In future also argument tracing is to be supported.

This document is based on //docs/clang_tool_refactoring.md

## Building

The following might take approx. 2 hours depending on your computer.

*  Make a new checkout of chromium (suggested, but optional).
*  From chromium/src:
*  ```shell cr build all``` To make sure all files have been generated.
*  ```shell cp -R third_party/llvm-build ~```
*  ```shell tools/clang/scripts/build.py --bootstrap --without-android
   --without-fuchsia --extra-tools trace_annotator```
   *  TODO how to build with plugin 'find-bad-constructs'?

### Rebuild just the tool:

*  ```shell cd third_party/llvm-build/Release+Asserts```
*  ```shell ninja trace_annotator```

Beware that running ```shell gclient sync``` might overwrite the build and
another full build might be necessary. A backup of the binary from
//third_party/llvm-build/Release+Asserts/bin/trace_annotator might be useful.

## Testing

*  ```shell tools/clang/scripts/test_tool.py --apply-edits trace_annotator```

## Running

*  Chrome plugins are not supported yet, run: ```shell gn args out/Debug/``` and
   add: ```clang_use_chrome_plugins = false``` option.
*  Make sure you have up to date compilation database:
   *  To generate it run: ```shell tools/clang/scripts/generate_compdb.py -p
      out/Debug/ > out/Debug/compile_commands.json```
   *  These are the compiler options for individual files (needed to use the
      right version of C++, right library paths...).

*  ```shell DIR="net"; \
      git checkout $DIR && tools/clang/scripts/run_tool.py --tool trace_annotator -p out/Debug/ $DIR \
      | tools/clang/scripts/extract_edits.py \
      | tools/clang/scripts/apply_edits.py -p out/Debug $DIR \
      && git cl format $DIR```

*  Consult documentation of ```//tools/clang/scripts/run_tool.py``` for more
   options.

### Suggestion:

Do not run the tool on //base or anything that has to do with tracing or
synchronization. Or at least do not submit the resulting patch.

### Debugging workflow suggestion:

*  Do some changes.
*  ```shell git add . ; git commit```
*  Run the tool.
*  ```shell git add . ; git commit```
*  Do some more changes (including fixing a bug).
*  ```shell git add . ; git commit```
*  ```shell git rebase -i``` and follow the help.

### Creating tracing patch suggestion:

*  Run the tool.
*  Double check all generated code.
*  Add method annotations for methods that are hidden by compiler options (e.g.,
   if you are on unix then the code in ```c++ #ifdef OS_WIN``` will not be
   annotated.

## TODO

*  Add options:
   *  Whether to add "do not submit" comment (in upper case).
   *  Function name formatting (without namespace(s) / getQualifiedNameAsString /
      with namespaces but without template tags).
   *  Category name.
   *  Make tracing of function arguments.
*  Standalone build of the tool (outside of //third_party to avoid overwriting
   by ```shell gclient sync```).