Kể từ ngày 27 tháng 3 năm 2025, bạn nên sử dụng android-latest-release thay vì aosp-main để xây dựng và đóng góp cho AOSP. Để biết thêm thông tin, hãy xem phần Thay đổi đối với AOSP.
Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Tính năng theo dõi Winscope là một phần của khung Android. Trang này trình bày các bước cần thiết để tải xuống, tạo và chạy trình xem dấu vết Winscope cục bộ.
Tạo Winscope cục bộ
Làm theo các bước sau để thiết lập máy tính chạy trình theo dõi Winscope:
Để xem danh sách các lệnh hiện có, hãy chạy: npm run
Tạo tất cả các mục tiêu kiểm thử và mục tiêu phát hành công khai bằng cách sử dụng:
npm run build:prod
Chạy Winscope bằng cách:
npm run start
Xây dựng các phần riêng biệt
Bạn có thể tạo riêng từng phần của Winscope bằng các lệnh sau:
Lệnh
Mô tả
build:trace_processor
Kiểm tra và tạo lại phiên bản mới nhất của trace_processor Perfetto.
build:protos
Biên dịch lại các định nghĩa proto.
Chạy chương trình kiểm thử
Winscope chứa các kiểm thử đơn vị và kiểm thử toàn diện. Để chạy các kiểm thử này, hãy sử dụng npm run
<command>:
Lệnh
Mô tả
test:unit:ci
Chạy các kiểm thử đơn vị ở định dạng ít chi tiết hơn cho CI hoặc lệnh gọi trước khi gửi.
test:unit:dev
Chạy các kiểm thử đơn vị ở định dạng chi tiết hơn cho quá trình phát triển cục bộ . Chế độ này theo dõi các thay đổi và tự động chạy lại các quy trình kiểm thử chính xác.
test:e2e
Chạy các kiểm thử toàn diện, chẳng hạn như các kiểm thử cho giao thức trên nhiều công cụ.
test:presubmit:quiet
Tạo tất cả các kiểm thử đơn vị trước khi gửi, trình kiểm tra và phân tích biểu đồ ở định dạng ít chi tiết hơn cho CI hoặc lệnh gọi trước khi gửi .
test:presubmit
Tạo tất cả các chương trình kiểm thử đơn vị trước khi gửi, trình kiểm tra và phân tích đồ thị ở định dạng chi tiết hơn cho quá trình phát triển cục bộ .
test:all
Chạy tất cả các kiểm thử (đơn vị và toàn bộ), trình kiểm tra lỗi và phân tích biểu đồ ở định dạng chi tiết hơn cho quá trình phát triển cục bộ.
Kiểm thử toàn diện
Trước khi chạy các kiểm thử từ đầu đến cuối, bạn phải khởi động công cụ từ xa và cài đặt đúng phiên bản trình điều khiển Chrome. Trong đoạn mã sau, lệnh run test:e2e sẽ tự động cài đặt trình điều khiển Chrome.
Bảng sau đây liệt kê các lệnh cần thiết và nội dung mô tả của các lệnh đó. Để chạy các lệnh này, hãy sử dụng npm run command:
Lệnh
Mô tả
start:remote_tool_mock
Khởi động mô hình công cụ từ xa để kiểm thử giao thức giữa các công cụ.
install:chromedriver
Cài đặt trình điều khiển Chrome cần thiết để chạy các kiểm thử toàn diện.
Cập nhật mối liên kết @IntDef
@IntDef là một chú giải được dùng trong Android để hạn chế các giá trị có thể có của một số nguyên. Winscope sử dụng một mối liên kết của các chú thích này để hiển thị tên của giá trị thay vì số nguyên.
Để cập nhật mối liên kết @IntDef, hãy làm như sau:
Tạo :framework-minus-apex-intdefs để bộ tiền xử lý chú thích chạy:
mp:framework-minus-apex-intdefs
Sao chép tệp intDefMapping.json đã tạo vào kho lưu trữ được tạo sẵn:
Tải các thay đổi lên Winscope bằng cách sử dụng repo upload.
Các lệnh khác
Ngoài các bản dựng và kiểm thử, tập lệnh Winscope còn có các chức năng khác, như minh hoạ trong bảng. Để chạy các kiểm thử này, hãy sử dụng npm run command:
Lệnh
Mô tả
format:check
Kiểm tra các vấn đề về định dạng mã bằng cách sử dụng prettier.
format:fix
Kiểm tra và tự động khắc phục các vấn đề về định dạng mã bằng cách sử dụng prettier.
eslint:check
Kiểm tra các vấn đề về định dạng mã bằng cách sử dụng eslint.
eslint:fix
Kiểm tra và tự động khắc phục các vấn đề về định dạng mã bằng cách sử dụng eslint.
tslint:check
Kiểm tra các vấn đề về định dạng mã bằng cách sử dụng tslint.
tslint:fix
Kiểm tra và tự động khắc phục các vấn đề về định dạng mã bằng cách sử dụng tslint.
deps_graph:check_cycles
Phân tích mã để tìm các phần phụ thuộc theo chu kỳ.
Khắc phục sự cố
Hãy làm theo các mẹo sau để khắc phục sự cố:
Lỗi ProtocolError: missing required '<FIELD>' hoặc TypeError: Cannot
read property '<PROP>' of null
Điều này xảy ra khi tệp theo dõi được tạo bằng một định nghĩa proto mới, chứa các trường bắt buộc mới.
Đảm bảo bạn đang mở dấu vết trên đúng phiên bản Winscope (master, S hoặc R).
Nếu bạn tạo trường mới trên proto, hãy biên dịch lại các proto trong Winscope bằng cách sử dụng npm run build:protos.
Một số phiên bản phần phụ thuộc đã cài đặt không chính xác (không tạo được)
Huỷ bỏ các thay đổi đối với package.json và package-lock.json. Xoá node_modules. Chạy lại npm install.
Tôi đã thêm một trường mới vào một trong các tệp proto. Làm cách nào để hiển thị thông tin này?
Winscope sử dụng các định nghĩa proto từ thời điểm được biên dịch, vì vậy, các trường mới sẽ không xuất hiện theo mặc định. Để hiện các trường mới, hãy tạo lại các proto bằng cách sử dụng npm run build:protos.
Nội dung và mã mẫu trên trang này phải tuân thủ các giấy phép như mô tả trong phần Giấy phép nội dung. Java và OpenJDK là nhãn hiệu hoặc nhãn hiệu đã đăng ký của Oracle và/hoặc đơn vị liên kết của Oracle.
Cập nhật lần gần đây nhất: 2025-09-03 UTC.
[[["Dễ hiểu","easyToUnderstand","thumb-up"],["Giúp tôi giải quyết được vấn đề","solvedMyProblem","thumb-up"],["Khác","otherUp","thumb-up"]],[["Thiếu thông tin tôi cần","missingTheInformationINeed","thumb-down"],["Quá phức tạp/quá nhiều bước","tooComplicatedTooManySteps","thumb-down"],["Đã lỗi thời","outOfDate","thumb-down"],["Vấn đề về bản dịch","translationIssue","thumb-down"],["Vấn đề về mẫu/mã","samplesCodeIssue","thumb-down"],["Khác","otherDown","thumb-down"]],["Cập nhật lần gần đây nhất: 2025-09-03 UTC."],[],[],null,["Winscope tracing is part of the Android framework. This page outlines the\nsteps required to download, build, and run the Winscope trace viewer locally.\n\nBuild Winscope locally\n\nFollow these steps to set up your PC to run the Winscope tracer:\n\n1. [Download the Android source](/docs/setup/build/building).\n2. Navigate to the Winscope folder:\n\n cd development/tools/winscope\n\n3. Install dependencies using:\n\n npm install\n\n To see a list of available commands, run: `npm run`\n4. Build all prod and test targets using:\n\n npm run build:prod\n\n5. Run Winscope using:\n\n npm run start\n\n| **Note:** You can also download and build Winscope to host on a standard web server to get a shareable link to the tool.\n\nBuild separate parts\n\nYou can build individual parts of Winscope separately using the following\ncommands:\n\n| Command | Description |\n|-------------------------|-----------------------------------------------------------------------------|\n| `build:trace_processor` | Checks out and rebuilds the latest version of Perfetto's `trace_processor`. |\n| `build:protos` | Recompiles the proto definitions. |\n\nRun tests **Tip:** Winscope doesn't build on Soong and can't be built by Tradefed, so it's recommended to have a local Git hook to the tests in your local environment.\n\nWinscope contains unit and end-to-end tests. To run them use `npm run\n\u003ccommand\u003e`:\n\n| Command | Description |\n|------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------|\n| `test:unit:ci` | Runs the unit tests in a less verbose format for CI or presubmit hook. |\n| `test:unit:dev` | Runs the unit tests in a more verbose format for local development. This mode watches for changes and automatically reruns the correct tests. |\n| `test:e2e` | Runs the end-to-end tests, such as those for the cross-tool protocol. |\n| `test:presubmit:quiet` | Builds all presubmit unit tests, linters, and graph analysis in a less verbose format for CI or presubmit hook. |\n| `test:presubmit` | Builds all presubmit unit tests, linters, and graph analysis in a more verbose format for local development. |\n| `test:all` | Runs all tests (unit and end-to-end), linters, and graph analysis in a more verbose format for local development. |\n\nEnd-to-end tests\n\nBefore running end-to-end tests, you must start the remote tool and install the\ncorrect version of the Chrome driver. In the following code snippet, the\n`run test:e2e` command automatically installs the Chrome driver. \n\n $ npm run start\n $ npm run start:remote_tool_mock\n $ npm run test:e2e\n\nThe following table lists the necessary commands and their descriptions. To run\nthem use `npm run `\u003cvar translate=\"no\"\u003ecommand\u003c/var\u003e:\n\n| Command | Description |\n|--------------------------|---------------------------------------------------------------|\n| `start:remote_tool_mock` | Starts the remote tool mock for testing cross tool protocol. |\n| `install:chromedriver` | Installs the Chrome driver necessary to run end-to-end tests. |\n\nUpdate @IntDef mapping\n\n`@IntDef` is an annotation used in Android to restrict the possible values of an\ninteger. Winscope uses a mapping of these annotations to display the name of the\nvalue instead of the integer.\n\nTo update the `@IntDef` mapping, do the following:\n\n1. Build `:framework-minus-apex-intdefs` for the annotation preprocessor to run:\n\n mp :framework-minus-apex-intdefs\n\n2. Copy the generated `intDefMapping.json` file to the prebuilts repository:\n\n $ python3 -c 'import sys,json,collections; print(json.dumps(collections.OrderedDict(sorted(collections.ChainMap(*map(lambda x:json.load(open(x)), sys.argv[1:])).items())), indent=2))' $(find out/soong/.intermediates/frameworks/base -iname intDefMapping.json) \u003e ./development/tools/winscope/src/common/intDefMapping.json\n\n3. Upload the changes in Winscope using `repo upload`.\n\nOther commands\n\nIn addition to build and tests, Winscope scripts contain other capabilities, as\nshown in the table. To run them use `npm run `\u003cvar translate=\"no\"\u003ecommand\u003c/var\u003e:\n\n| Command | Description |\n|---------------------------|----------------------------------------------------------------|\n| `format:check` | Checks for code formatting issues using `prettier`. |\n| `format:fix` | Checks and auto fixes code formatting issues using `prettier`. |\n| `eslint:check` | Checks for code formatting issues using `eslint`. |\n| `eslint:fix` | Checks and auto fixes code formatting issues using `eslint`. |\n| `tslint:check` | Checks for code formatting issues using `tslint`. |\n| `tslint:fix` | Checks and auto fixes code formatting issues using `tslint`. |\n| `deps_graph:check_cycles` | Analyzes the code for cyclical dependencies. |\n\nTroubleshoot\n\nUse the following tips for troubleshooting:\n\n- **Error `ProtocolError: missing required '\u003cFIELD\u003e'` or `TypeError: Cannot\n read property '\u003cPROP\u003e' of null`**\n\n - This occurs when the trace file was created with a new proto definition,\n containing new *required* fields.\n\n 1. Make sure you're opening the trace on the correct Winscope version (master, S, or R).\n 2. If you create the new field on the proto, recompile the protos in\n Winscope using `npm run build:protos`.\n\n | **Note:** You shouldn't need a new required field, because the protos should be backward compatible.\n- **Some installed dependency versions are wrong (build fails)**\n\n - Revert changes to `package.json` and `package-lock.json`. Remove `node_modules`. Run `npm install` again.\n- **I added a new field to one of the proto files. How do I display it?**\n\n - Winscope uses the proto definitions from when it was compiled, so new fields won't appear by default. To show new fields, rebuild the protos using `npm run build:protos`."]]