Comments (10)
pulling open /tmp/perfetto/sdk/perfetto.cc, I can see a note:
47989 // PERFETTO_DEFINE_CATEGORIES(
47990 // PERFETTO_CATEGORY(base),
47991 // PERFETTO_CATEGORY(v8),
47992 // PERFETTO_CATEGORY(cc));
so it looks like the macro PERFETTO_CATEGORY
should be used, rather than the explicit class perfetto::Category
which doesn't seem to exist. Ok, so that looks like a simple documentation bug.
PERFETTO_DEFINE_CATEGORIES(PERFETTO_CATEGORY("hello"));
Now this fails with:
main.cpp:5:1: error: static_assert failed due to requirement 'kConstExprCategoryRegistry.ValidateCategories()' "Invalid category names found"
PERFETTO_DEFINE_CATEGORIES(PERFETTO_CATEGORY("hello"));
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/tmp/perfetto/sdk/perfetto.h:6917:3: note: expanded from macro 'PERFETTO_DEFINE_CATEGORIES'
PERFETTO_INTERNAL_DECLARE_CATEGORIES(__VA_ARGS__); \
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/tmp/perfetto/sdk/perfetto.h:6714:3: note: expanded from macro 'PERFETTO_INTERNAL_DECLARE_CATEGORIES'
static_assert(kConstExprCategoryRegistry.ValidateCategories(), \
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/tmp/perfetto/sdk/perfetto.h:6402:5: error: static_assert failed due to requirement '18446744073709551615UL != kInvalidCategoryIndex' "A track event used an unknown category. Please add it to PERFETTO_DEFINE_CATEGORIES()."
static_assert(CategoryIndex != kInvalidCategoryIndex,
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
main.cpp:10:3: note: in instantiation of function template specialization 'perfetto::internal::TrackEventCategoryRegistry::Validate<18446744073709551615>' requested here
TRACE_EVENT("hello", "do_sleep");
^
/tmp/perfetto/sdk/perfetto.h:6946:3: note: expanded from macro 'TRACE_EVENT'
PERFETTO_INTERNAL_SCOPED_TRACK_EVENT(category, name, ##__VA_ARGS__)
^
/tmp/perfetto/sdk/perfetto.h:6779:27: note: expanded from macro 'PERFETTO_INTERNAL_SCOPED_TRACK_EVENT'
~EventFinalizer() { TRACE_EVENT_END(category); } \
^
/tmp/perfetto/sdk/perfetto.h:6939:3: note: expanded from macro 'TRACE_EVENT_END'
PERFETTO_INTERNAL_TRACK_EVENT( \
^
/tmp/perfetto/sdk/perfetto.h:6745:7: note: expanded from macro 'PERFETTO_INTERNAL_TRACK_EVENT'
PERFETTO_GET_CATEGORY_INDEX(category)>([&](uint32_t instances) { \
^
/tmp/perfetto/sdk/perfetto.h:6737:53: note: expanded from macro 'PERFETTO_GET_CATEGORY_INDEX'
::perfetto::internal::TrackEventCategoryRegistry::Validate< \
^
2 errors generated.
from perfetto.
@skyostil @betasheet
can you have a look here? maybe our docs are outdated?
from perfetto.
I have a feeling this might be missing a:
PERFETTO_TRACK_EVENT_STATIC_STORAGE();
We should probably add this to the docs :)
FWIW, perfetto::Category should also work, not sure why it doesn't. We have tests that use it:
https://source.chromium.org/chromium/chromium/src/+/master:third_party/perfetto/src/tracing/test/api_integrationtest.cc;l=80
The PERFETTO_CATEGORY macro is deprecated and only expands to perfetto::Category too:
https://source.chromium.org/chromium/chromium/src/+/master:third_party/perfetto/include/perfetto/tracing/track_event.h;l=131
from perfetto.
I think we really need a snippet / example source code that works.
People can figure all the rest but we must have an example .cc file that shows the thing working.
from perfetto.
The issue here is that the v3.1 SDK is fairly old at this point and doesn't match the latest API described by the documentation. The code here needs two changes to match v3.1: category registration and adding the static storage macro as pointed out by @betasheet:
#include <perfetto.h>
#include <unistd.h>
PERFETTO_DEFINE_CATEGORIES(
PERFETTO_CATEGORY(hello));
PERFETTO_TRACK_EVENT_STATIC_STORAGE();
void do_sleep() {
TRACE_EVENT("hello", "do_sleep");
sleep(3);
}
int main(int argv, char** argc) {
perfetto::TracingInitArgs args;
args.backends |= perfetto::kInProcessBackend;
perfetto::Tracing::Initialize(args);
perfetto::TrackEvent::Register();
do_sleep();
}
I checked that this builds with:
c++ -I perfetto/sdk -lpthread hello.cc perfetto/sdk/perfetto.cc
Here's a repo with fully working minimal examples with v3.1: https://github.com/skyostil/perfetto-sdk-example
@primiano -- let's make a new SDK release to bring everything in line. Also, should we somehow merge the above repo and https://github.com/primiano/perfetto-sdk?
from perfetto.
Ahh gotcha.
So, strong yes to a new release and also consolidating the sdk examples.
I am happy to nuke https://github.com/primiano/perfetto-sdk (that was just needed for some pre-sdk work with some other companies) in favour of a living examples/ directory somewhere.
from perfetto.
@nickdesaulniers can you check if this JustWorks with v4.0 we just released?
https://github.com/google/perfetto/tree/v4.0
from perfetto.
With v4.1 we now also have integrated the SDK samples into the repository: https://cs.android.com/android/platform/superproject/+/master:external/perfetto/examples/sdk/README.md
Let me close this this issue. If you run into more problems with the SDK, please open a new issue.
from perfetto.
Was the updated documentation pushed?
https://perfetto.dev/docs/instrumentation/tracing-sdk
https://perfetto.dev/docs/instrumentation/track-events
** EDIT **
Looks like the newest sdk is referenced in the clone command. I was curious about the references to perfetto::Category
though?
Next n00b question, when I run the produced a.out
, I see:
$ ./a.out
[093.170] perfetto.cc:46436 Producer 1 connected
[093.170] perfetto.cc:37317 Producer connected
[093.170] perfetto.cc:48099 Producer 1 registered data source "track_event"
does this write a trace somewhere (using in process mode)? https://perfetto.dev/docs/quickstart/linux-tracing seems to imply that another command line utility is needed?
from perfetto.
Was the updated documentation pushed?
I think so given the updated tag.
Now there are some examples in https://github.com/google/perfetto/tree/master/examples/sdk
Next n00b question, when I run the produced a.out, I see:
Those log statements are only about the initialization. Tracing is not started at that point (you'd see a "Enabling tracing... " message otherwise.
does this write a trace somewhere (using in process mode)? > https://perfetto.dev/docs/quickstart/linux-tracing seems to imply that another command line utility is needed?
Those docs apply only to system-mode and not to in-process mode.
For in-process mode you need to start/stop/save the trace file yourself.
See the example in https://github.com/google/perfetto/blob/master/examples/sdk/example.cc
Where it does perfetto::Tracing::NewTrace()
.
That's what you need to do in in-process mode.
from perfetto.
Related Issues (20)
- Display dma_fence events in a single row HOT 2
- INCLUDE: unknown module 'sched.time_in_state' HOT 6
- What is the method to obtain the duration of different states in slice? HOT 1
- Adding fastrpc related trace events HOT 2
- Counter debug annotations and categories not taken into account HOT 1
- Inconsistent properties displayed for counter values HOT 3
- using sql query via python library, throw a exception that no such table: android_startups HOT 1
- Cannot build for arm, include <features.h> not found HOT 1
- Duplicate queries are being run when loading counter tracks HOT 4
- process_sort_index support or alternative suggestions HOT 1
- How to update interned data after the first packet has been flushed? HOT 1
- Let users set the displayed time range HOT 2
- Slow track loading of rate type counters HOT 2
- Support for stacked counters HOT 2
- Steps necessary for Cuda kernel event tracking. HOT 1
- Request: support Hide process HOT 1
- After converting to systrace, the customized log cannot be saved. HOT 2
- Standalone Bazel build broken after switch to Python tables HOT 3
- BatchTraceProcessor FileNotFoundError: [Errno 2] No such file or directory: '.local/share/perfetto/prebuilts/trace_processor_shell.tmp' on first run HOT 2
- How to disable tracing when not needed? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from perfetto.