Skip to content

Commit

Permalink
Remove flamegraph feature because Perfetto has it (#478)
Browse files Browse the repository at this point in the history
  • Loading branch information
gaogaotiantian authored Oct 10, 2024
1 parent e1a2ba9 commit 4b821b3
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 230 deletions.
6 changes: 1 addition & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,11 +212,7 @@ Refer to [async docs](https://viztracer.readthedocs.io/en/stable/concurrency.htm

### Flamegraph

VizTracer can show flamegraph of traced data.

```sh
vizviewer --flamegraph result.json
```
Perfetto supports native flamegraph, just select slices on the UI and choose "Slice Flamegraph".

[![example_img](https://github.com/gaogaotiantian/viztracer/blob/master/img/flamegraph.png)](https://github.com/gaogaotiantian/viztracer/blob/master/img/flamegraph.png)

Expand Down
Binary file modified img/flamegraph.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
115 changes: 0 additions & 115 deletions src/viztracer/flamegraph.py

This file was deleted.

44 changes: 9 additions & 35 deletions src/viztracer/viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
from http import HTTPStatus
from typing import Any, Callable, Dict, List, Optional

from .flamegraph import FlameGraph


dir_lock = threading.Lock()

Expand Down Expand Up @@ -77,9 +75,7 @@ def do_GET(self):
self.server.last_request = self.path
self.server_thread.notify_active()
if self.path.endswith("vizviewer_info"):
info = {
"is_flamegraph": self.server_thread.flamegraph,
}
info = {}
self.send_response(200)
self.send_header("Content-type", "application/json")
self.end_headers()
Expand All @@ -100,13 +96,6 @@ def do_GET(self):
self.path = f"/{filename}"
self.server.trace_served = True
return super().do_GET()
elif self.path.endswith("flamegraph"):
self.send_response(200)
self.send_header("Content-type", "application/json")
self.end_headers()
self.wfile.write(json.dumps(self.server_thread.fg_data).encode("utf-8"))
self.wfile.flush()
self.server.trace_served = True
else:
self.directory = os.path.join(os.path.dirname(__file__), "web_dist")
with chdir_temp(self.directory):
Expand Down Expand Up @@ -276,7 +265,6 @@ def __init__(
path: str,
port: int = 9001,
once: bool = False,
flamegraph: bool = False,
use_external_processor: bool = False,
timeout: float = 10,
quiet: bool = False) -> None:
Expand All @@ -286,7 +274,6 @@ def __init__(
self.timeout = timeout
self.quiet = quiet
self.link = f"http://127.0.0.1:{self.port}"
self.flamegraph = flamegraph
self.use_external_procesor = use_external_processor
self.externel_processor_process: Optional[ExternalProcessorProcess] = None
self.fg_data: Optional[List[Dict[str, Any]]] = None
Expand All @@ -313,17 +300,7 @@ def view(self) -> int:
filename = os.path.basename(self.path)

Handler: Callable[..., HttpHandler]
if self.flamegraph:
if filename.endswith("json"):
with open(self.path, encoding="utf-8", errors="ignore") as f:
trace_data = json.load(f)
fg = FlameGraph(trace_data)
self.fg_data = fg.dump_to_perfetto()
Handler = functools.partial(PerfettoHandler, self)
else:
print(f"Do not support flamegraph for file type {filename}")
return 1
elif filename.endswith("json"):
if filename.endswith("json"):
trace_data = None
if self.use_external_procesor:
Handler = functools.partial(ExternalProcessorHandler, self)
Expand Down Expand Up @@ -378,13 +355,11 @@ def __init__(
path: str,
port: int,
server_only: bool,
flamegraph: bool,
timeout: int,
use_external_processor: bool) -> None:
self.base_path = os.path.abspath(path)
self.port = port
self.server_only = server_only
self.flamegraph = flamegraph
self.timeout = timeout
self.use_external_processor = use_external_processor
self.max_port_number = 10
Expand All @@ -411,7 +386,6 @@ def create_server(self, path: str) -> ServerThread:
t = ServerThread(
path,
port=port,
flamegraph=self.flamegraph,
use_external_processor=self.use_external_processor,
quiet=True)
t.start()
Expand Down Expand Up @@ -474,23 +448,25 @@ def viewer_main() -> int:
parser.add_argument("--timeout", nargs="?", type=int, default=10,
help="Timeout in seconds to stop the server without trace data requests")
parser.add_argument("--flamegraph", default=False, action="store_true",
help="Show flamegraph of data")
help=argparse.SUPPRESS)
parser.add_argument("--use_external_processor", default=False, action="store_true",
help="Use the more powerful external trace processor instead of WASM")

options = parser.parse_args(sys.argv[1:])
f = options.file[0]

if options.flamegraph:
print("--flamegraph is removed because the front-end supports native flamegraph now.")
print("You can select slices in the UI and do 'Slice Flamegraph'.")
return 1

if options.use_external_processor:
# Perfetto trace processor only accepts requests from localhost:10000
options.port = 10000
# external trace process won't work with once or flamegraph or directory
# external trace process won't work with once or directory
if options.once:
print("You can't use --once with --use_external_processor")
return 1
if options.flamegraph:
print("You can't use --flamegraph with --use_external_processor")
return 1
if os.path.isdir(f):
print("You can't use --use_external_processor on a directory")
return 1
Expand All @@ -502,7 +478,6 @@ def viewer_main() -> int:
path=f,
port=options.port,
server_only=options.server_only,
flamegraph=options.flamegraph,
timeout=options.timeout,
use_external_processor=options.use_external_processor,
)
Expand All @@ -517,7 +492,6 @@ def viewer_main() -> int:
path,
port=options.port,
once=options.once,
flamegraph=options.flamegraph,
timeout=options.timeout,
use_external_processor=options.use_external_processor,
)
Expand Down
6 changes: 3 additions & 3 deletions tests/test_cmdline.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,14 +344,14 @@ def test_tracer_entries(self):

def test_trace_self(self):
def check_func(data):
self.assertGreater(len(data["traceEvents"]), 10000)
self.assertGreater(len(data["traceEvents"]), 1000)

example_json_dir = os.path.join(os.path.dirname(__file__), "../", "example/json")
if sys.platform == "win32":
self.template(["viztracer", "--trace_self", "vizviewer", "--flamegraph", "--server_only",
self.template(["viztracer", "--trace_self", "vizviewer", "--server_only",
os.path.join(example_json_dir, "multithread.json")], success=False)
else:
self.template(["viztracer", "--trace_self", "vizviewer", "--flamegraph", "--server_only",
self.template(["viztracer", "--trace_self", "vizviewer", "--server_only",
os.path.join(example_json_dir, "multithread.json")],
send_sig=(signal.SIGTERM, "Ctrl+C"), expected_output_file="result.json", check_func=check_func)

Expand Down
29 changes: 0 additions & 29 deletions tests/test_flamegraph.py

This file was deleted.

Loading

0 comments on commit 4b821b3

Please sign in to comment.