debug
*เนื้อหานี้แปลโดยใช้ AI (เวอร์ชัน Beta) และอาจมีข้อผิดพลาด หากต้องการดูหน้านี้เป็นภาษาอังกฤษ ให้คลิกที่นี่
ข้อมูลสรุป
ฟังก์ชัน
profilebegin(label: string):() |
profileend():() |
setmemorycategory(tag: string):string |
resetmemorycategory():() |
dumpcodesize():() |
เอกสารอ้างอิงเกี่ยวกับ API
ฟังก์ชัน
traceback
traceback
info
info
info
profilebegin
profileend
debug. profileend():()
ส่งค่ากลับ
()
ตัวอย่างโค้ด
สิ้นสุดโปรไฟล์ดีบัก
debug.profilebegin("Outer")
debug.profilebegin("Inner")
-- งานที่ทำที่นี่จะถูกจับเวลาใต้ป้ายทั้งสอง
debug.profileend() -- ปิด "Inner"
debug.profileend() -- ปิด "Outer"getmemorycategory
ส่งค่ากลับ
ตัวอย่างโค้ด
การดีบักการดึงหมวดหมู่หน่วยความจำ
local category = debug.getmemorycategory()
print(type(category)) --> string
-- หมวดหมู่จะติดตามเธรด ดังนั้นหมวดหมู่ใหม่อาจแตกต่างจากหมวดหมู่นี้
local previous = debug.setmemorycategory("Pathfinding")
print(debug.getmemorycategory()) --> Pathfinding
debug.setmemorycategory(previous)setmemorycategory
พารามิเตอร์
ส่งค่ากลับ
ตัวอย่างโค้ด
การตั้งค่าหมวดหมู่หน่วยความจำสำหรับการดีบัก
local original = debug.setmemorycategory("MapGeneration")
print(debug.getmemorycategory()) --> MapGeneration
-- การจัดสรรที่ทำที่นี่จะถูกระบุไว้ภายใต้ "MapGeneration" ใน Developer Console
local tiles = table.create(1000, 0)
-- ค่าที่ส่งกลับคือหมวดหมู่ก่อนหน้า ดังนั้นจึงสามารถกู้คืนได้
print(debug.setmemorycategory(original) == "MapGeneration") --> true
print(#tiles) --> 1000resetmemorycategory
debug. resetmemorycategory():()
ส่งค่ากลับ
()
ตัวอย่างโค้ด
รีเซ็ตหมวดหน่วยความจำสำหรับการดีบัก
local automatic = debug.getmemorycategory()
debug.setmemorycategory("การสร้าง")
print(debug.getmemorycategory()) --> การสร้าง
debug.resetmemorycategory()
print(debug.getmemorycategory() == automatic) --> truedumpcodesize
debug. dumpcodesize():()
ส่งค่ากลับ
()
ตัวอย่างโค้ด
ขนาดโค้ด Debug Dump
-- debug.dumpcodesize() ใช้งานได้เฉพาะจาก Studio Command Bar ซึ่งจะพิมพ์
-- รายงานไปยัง Output โดยมีตารางหนึ่งตารางต่อสคริปต์เนทีฟ ฟังก์ชันที่ใหญ่ที่สุดก่อน:
-- # การวิเคราะห์ขนาดโค้ดเนทีฟ
-- <n> สคริปต์, <n> ฟังก์ชัน, <n> KB หน่วยความจำ, ขนาดโค้ดจำกัด 256 MB
-- ## <ชื่อสคริปต์>
-- <n> ฟังก์ชัน, <n> KB หน่วยความจำ
-- | ฟังก์ชัน | บรรทัด | ขนาดโค้ดเนทีฟ | ขนาดโค้ดเนทีฟ (%) |
-- สคริปต์ที่เริ่มต้นด้วย --!native และได้ทำงานจะปรากฏในรายงาน.
-- จากสคริปต์จะเกิดข้อผิดพลาด ซึ่ง pcall จะจับ
local ok, message = pcall(debug.dumpcodesize)
print(ok) --> false
print(message) --> dumpcodesize สามารถเรียกใช้ได้เฉพาะจาก CommandBar