TL;DR: All ESP32 variants have a 64-bit counter that is used to keep a running count of the number of microseconds that have passed since boot, and that counter can be read with esp_timer_get_time.
https://docs.espressif.com/projects/esp ... _get_timev
esp_timer_get_time is part of the esp_timer package in ESP-IDF, which is the foundation of arduino-esp32. The code is at
https://github.com/espressif/esp-idf/tr ... /esp_timer, but is not a simple function, as the implementation differs in the various versions and architectures. How the counter number is generated is quite complicated and based on ticks (pulses) which typically come from the 40MHz (or 26MHz) piezoelectric crystal. If you are looking for more detail, I would refer you to the technical reference manual for the chip you are using.
https://www.espressif.com/en/support/do ... -documents