• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2018 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 
19 #include <stdint.h>
20 #include <jni.h>
21 
22 #define TUNINGFORK_MAJOR_VERSION 0
23 #define TUNINGFORK_MINOR_VERSION 1
24 #define TUNINGFORK_PACKED_VERSION ((TUNINGFORK_MAJOR_VERSION<<16)|(TUNINGFORK_MINOR_VERSION))
25 
26 // These are reserved instrumentation keys
27 enum {
28     TFTICK_SYSCPU = 0,
29     TFTICK_SYSGPU = 1
30 };
31 
32 typedef struct {
33     uint8_t* bytes;
34     size_t size;
35     void (*dealloc)(void*);
36 } CProtobufSerialization;
37 
38 // The instrumentation key identifies a tick point within a frame or a trace segment
39 typedef uint16_t TFInstrumentKey;
40 typedef uint64_t TFTraceHandle;
41 typedef uint64_t TFTimePoint;
42 typedef uint64_t TFDuration;
43 
44 #ifdef __cplusplus
45 extern "C" {
46 #endif
47 
48 // init must be called before any other functions
49 void TuningFork_init(const CProtobufSerialization *settings, JNIEnv* env, jobject activity);
50 
51 // Blocking call to get fidelity parameters from the server.
52 // Returns true if parameters could be downloaded within the timeout, false otherwise.
53 // Note that once fidelity parameters are downloaded, any timing information is recorded
54 //  as being associated with those parameters.
55 // If you subsequently call GetFidelityParameters and a new set of parameters is downloaded,
56 // any data that is already collected will be submitted to the backend.
57 // Ownership of 'params' is transferred to the caller, so they must call params->dealloc
58 // when they are done with it.
59 bool TuningFork_getFidelityParameters(const CProtobufSerialization *defaultParams,
60                              CProtobufSerialization *params, size_t timeout_ms);
61 
62 // Protobuf serialization of the current annotation
63 // Returns 0 if the annotation could be set, -1 if not
64 int TuningFork_setCurrentAnnotation(const CProtobufSerialization *annotation);
65 
66 // Record a frame tick that will be associated with the instrumentation key and the current
67 //   annotation
68 void TuningFork_frameTick(TFInstrumentKey id);
69 
70 // Record a frame tick using an external time, rather than system time
71 void TuningFork_frameDeltaTimeNanos(TFInstrumentKey id, TFDuration dt);
72 
73 // Start a trace segment
74 TFTraceHandle TuningFork_startTrace(TFInstrumentKey key);
75 
76 // Record a trace with the key and annotation set using startTrace
77 void TuningFork_endTrace(TFTraceHandle h);
78 
79 #ifdef __cplusplus
80 }
81 #endif
82