Is this safe? Creating a custom profiler

  Рет қаралды 9,748

Nathan Baggs

Nathan Baggs

Күн бұрын

#gamedev #gameengine #cpp #indiedev
When making a game with my custom engine I noticed some lag, so I decided to build a custom profiler from scratch to see what was going on.
The engine is written in C++ and supports windows (DirectX and OpenGL), Linux (OpenGL) and macOS (metal).
I use some questionable OS functions to create a profiler.
💭 All views are my own 💭
Link to iris: github.com/irisengine/iris
Models from Quaternius: quaternius.com/

Пікірлер: 43
@MAPster7000
@MAPster7000 Жыл бұрын
Me, learning OpenGL and game engine internals *woah so hardcore* This guy "Oh yes, I wrote profilers for 3 different OS's" o_o awesome =D
@wilykary
@wilykary Жыл бұрын
Game dev is really hard, especially if you build your own custom 3D engine that supports multiple backends 😂
@RandomGuyyy
@RandomGuyyy 11 ай бұрын
Sometimes I feel like UE5 makes it too easy. Contemplating rolling my own engine, I look up channels such as Nathan Baggs. Then I feel a shock that sends me limping back to my safe sandbox like an animal who dared to touch the electric fence.
@nathanbaggs
@nathanbaggs 11 ай бұрын
I’d recommend rolling your own engine as a side project, you can make it as simple or as complex as you want
@wokeupinthefuture
@wokeupinthefuture 4 ай бұрын
great vid as always but i'd like to see more in-depth on your problem solving, like stepping thru source and showing what functions are actually slow, what did you do to increase perf and so on, anyway keep up with this!
@boneyboi
@boneyboi Жыл бұрын
I found ur channel today in recomended and i love ur videos
@nathanbaggs
@nathanbaggs Жыл бұрын
Thanks so much :)
@LukeAvedon
@LukeAvedon 5 ай бұрын
You are my freaking hero. This channel is amazing. Gets me so jazzed about being a programmer like nothing else.
@Supakills101
@Supakills101 Жыл бұрын
If this is just a hobby what the heck do you do as job?! Very impressive.
@nathanbaggs
@nathanbaggs Жыл бұрын
Thanks, glad you enjoyed it.
@penguthepenguinj
@penguthepenguinj 2 ай бұрын
Intresting I remember bukkit (Minecraft plugin server) used to have a timing system similar to the one you described, each action is timed in milliseconds and the highest time can be viewed on its Web interface
@Andrii-zc4dp
@Andrii-zc4dp Жыл бұрын
Linux to suspend use: kill -s SIGSTOP and to resume: kill -s SIGCONT and strace command gets stack trace
@nathanbaggs
@nathanbaggs Жыл бұрын
That's definitely a way to do it externally, but I wanted to profile from within the process itself
@gustavcoetzee5018
@gustavcoetzee5018 Жыл бұрын
Luv it. ❤️
@nathanbaggs
@nathanbaggs Жыл бұрын
Thanks!
@AraSec-hj5mx
@AraSec-hj5mx Жыл бұрын
Hey, I liked your content. One day I wanna be as good as you in programming. I want to learn assembly and c and be very good at them. What books do you recommend?
@nathanbaggs
@nathanbaggs Жыл бұрын
Hey thanks! I don’t have any recommendations for books I’m afraid. But sites like CodeWars and Project Euler have some good exercises for practising
@unLinuxeroMas
@unLinuxeroMas Жыл бұрын
witch software do you use for your animations in your vidios
@nathanbaggs
@nathanbaggs Жыл бұрын
I use OBS for screen recording and edit the videos with Shotcut
@az-kalaak6215
@az-kalaak6215 Жыл бұрын
I was wondering wouldn't it be better to parse the code, inject some clock work, then compile it? taking a snaphot might be rigged because your cpu is waiting for it's pipeline to flush no?
@nathanbaggs
@nathanbaggs Жыл бұрын
When you're doing something as low-level as profiling there'll be intricacies whichever approach you pick. Your suggestion is totally valid but one of the reasons I went with the runtime approach is that I'm producing a library and I didn't want to impose any undue restrictions on the user. With this approach someone just needs to link against the library, call start and they get profiling information. This also means I can integrate it into a UI in the future
@az-kalaak6215
@az-kalaak6215 Жыл бұрын
@@nathanbaggs true, I did not consider this
@itzblinkzy1728
@itzblinkzy1728 Жыл бұрын
hello nice video i was wondering what them is ur vscode
@nathanbaggs
@nathanbaggs Жыл бұрын
Glad you enjoyed it. It’s Dracula
@TheSensationalMr.Science
@TheSensationalMr.Science Жыл бұрын
3:30 wait.... so you couldn't use 'SIGST' (Ctrl-Z for terminal) or 'kill -STOP PID' & 'kill -CONT PID' for linux? or strace as a way to get stack traces? (also for linux) Hope you have a great day & Safe Travels!
@nathanbaggs
@nathanbaggs Жыл бұрын
Sure that’s possible, but I wanted a way for the process itself to capture stack traces. So with this approach I can just run a game and when it exits I can see where it spent it’s time
@charactername263
@charactername263 Жыл бұрын
@@nathanbaggs yes going to shell is heretical, if shell can do it, kernel can do it, code can call kernel, code can do it, shell is a SHELL OUT. WEAK. Very principled to not cop out to shell. Spit on shell abusers.
@guilhem7171
@guilhem7171 Жыл бұрын
I didn't got how you get from "I have a working tool that can stop my program and give me the stack trace" to "I have timing information about how my game run". Did you just get the stack very frequently to have statistical information ? BTW that's great content, want more :-P
@sadlan7228
@sadlan7228 Жыл бұрын
I'm wondering about the same thing
@nathanbaggs
@nathanbaggs Жыл бұрын
Yea I set up an extra thread (which doesn’t get profiled) and repeatedly pause and sample all other threads. The windows implementation is here and you can see the loop github.com/irisengine/iris/blob/2fe26e936abdf0d9eed73e100bd7d3590622ee46/src/core/win32/profiler.cpp#L182 Glad you enjoyed it 😊
@KiritoDev
@KiritoDev Жыл бұрын
Do you think i could port your engine to a platform that doesnt support any profiler?
@nathanbaggs
@nathanbaggs Жыл бұрын
Sure just don’t create the Profiler object in the start() function e.g. github.com/irisengine/iris/blob/2fe26e936abdf0d9eed73e100bd7d3590622ee46/src/core/win32/start.cpp#L90
@phizc
@phizc 12 күн бұрын
Ah, yes, shader compilation stutter. A seemingly all encompasses problem. 😅
@user-dh8oi2mk4f
@user-dh8oi2mk4f Жыл бұрын
Can you explain the problem more in depth?
@nathanbaggs
@nathanbaggs Жыл бұрын
The problem lies in how I’m building and managing “materials” which is just a wrapper around graphics specific shaders. I want to be able to reuse materials where possible but internally that needs improving. So at the moment I recreate the same material (which is slow) several times.
@gustavcoetzee5018
@gustavcoetzee5018 Жыл бұрын
Teach me master
@charactername263
@charactername263 Жыл бұрын
If you are willing to torture yourself with the worst API ever written, you can get hardware counter data using ETW to microbenchmark things like branch mispredicts in usermode. Might make for a nice follow up video.
@nathanbaggs
@nathanbaggs Жыл бұрын
Thanks for the suggestion!
@charactername263
@charactername263 Жыл бұрын
@@nathanbaggs as a followon from my last comment, I think Linux has some equivalent functionality to communicate from usermode to a kernel driver and query performance counters, and is much easier to use.
@charactername263
@charactername263 Жыл бұрын
@@nathanbaggs Having done a bit more research, you can even get InstructionPointers from the ProfSample event, and I think if you did that with like an InstructionRetired Counter, you could have a quite nice sampling profiler for problematic instructions.
@gustavcoetzee5018
@gustavcoetzee5018 Жыл бұрын
Argh. Damn. Harsh
@darthtesla301
@darthtesla301 Жыл бұрын
It's very cathartic when a dev vlog starts with "game dev is hard" 🥲
@nathanbaggs
@nathanbaggs Жыл бұрын
It’s something we can all relate to!
What is the fastest way to calculate sine?
4:23
Nathan Baggs
Рет қаралды 23 М.
Can you fit a whole game on a stamp?
8:27
Nathan Baggs
Рет қаралды 74 М.
1 класс vs 11 класс (неаккуратность)
01:00
Ну Лилит))) прода в онк: завидные котики
00:51
Why Don't You Make Your OWN Game Engine?
7:23
Skeffles
Рет қаралды 4,6 М.
Fixing Multiplayer Of A 25 Year Old Game
12:37
Nathan Baggs
Рет қаралды 96 М.
My programming language
0:25
MGAMES!
Рет қаралды 69 М.
Making a Game With C++ and SDL2
8:14
PolyMars
Рет қаралды 1,6 МЛН
17 Pieces of C# Syntax That Make Your Code Short
12:41
Zoran Horvat
Рет қаралды 18 М.
I Made a Graphics Engine
6:42
Zyger
Рет қаралды 240 М.
Giving Personality to Procedural Animations using Math
15:30
t3ssel8r
Рет қаралды 2,4 МЛН
How to create graphics using Python turtle 🐍🐢 #coding
0:14
Fun with Python
Рет қаралды 848 М.
How Do Hackers Actually Cheat In Games?
12:38
Nathan Baggs
Рет қаралды 29 М.
Reverse Engineering RollerCoaster Tycoon | How does it work?
38:54
Nathan Baggs
Рет қаралды 224 М.