• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright (C) 2006-2007 The Android Open Source Project
2 **
3 ** This software is licensed under the terms of the GNU General Public
4 ** License version 2, as published by the Free Software Foundation, and
5 ** may be copied, distributed, and modified under those terms.
6 **
7 ** This program is distributed in the hope that it will be useful,
8 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
9 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10 ** GNU General Public License for more details.
11 */
12 
13 #ifndef TRACE_H
14 #define TRACE_H
15 
16 #include <inttypes.h>
17 #include "trace_common.h"
18 
19 extern uint64_t start_time, end_time;
20 extern uint64_t elapsed_usecs;
21 extern uint64 Now();
22 
23 struct TranslationBlock;
24 
25 // For tracing dynamic execution of basic blocks
26 typedef struct TraceBB {
27     char	*filename;
28     FILE	*fstream;
29     BBRec	buffer[kMaxNumBasicBlocks];
30     BBRec	*next;		// points to next record in buffer
31     uint64_t	flush_time;	// time of last buffer flush
32     char	compressed[kCompressedSize];
33     char	*compressed_ptr;
34     char	*high_water_ptr;
35     int64_t	prev_bb_num;
36     uint64_t	prev_bb_time;
37     uint64_t	current_bb_num;
38     uint64_t	current_bb_start_time;
39     uint64_t	recnum;		// counts number of trace records
40     uint32_t	current_bb_addr;
41     int		num_insns;
42 } TraceBB;
43 
44 // For tracing simuation start times of instructions
45 typedef struct TraceInsn {
46     char	*filename;
47     FILE	*fstream;
48     InsnRec	dummy;		// this is here so we can use buffer[-1]
49     InsnRec	buffer[kInsnBufferSize];
50     InsnRec	*current;
51     uint64_t	prev_time;	// time of last instruction start
52     char	compressed[kCompressedSize];
53     char	*compressed_ptr;
54     char	*high_water_ptr;
55 } TraceInsn;
56 
57 // For tracing the static information about a basic block
58 typedef struct TraceStatic {
59     char	*filename;
60     FILE	*fstream;
61     uint32_t	insns[kMaxInsnPerBB];
62     int		next_insn;
63     uint64_t	bb_num;
64     uint32_t	bb_addr;
65     int		is_thumb;
66 } TraceStatic;
67 
68 // For tracing load and store addresses
69 typedef struct TraceAddr {
70     char	*filename;
71     FILE	*fstream;
72     AddrRec	buffer[kMaxNumAddrs];
73     AddrRec	*next;
74     char	compressed[kCompressedSize];
75     char	*compressed_ptr;
76     char	*high_water_ptr;
77     uint32_t	prev_addr;
78     uint64_t	prev_time;
79 } TraceAddr;
80 
81 // For tracing exceptions
82 typedef struct TraceExc {
83     char	*filename;
84     FILE	*fstream;
85     char	compressed[kCompressedSize];
86     char	*compressed_ptr;
87     char	*high_water_ptr;
88     uint64_t	prev_time;
89     uint64_t	prev_bb_recnum;
90 } TraceExc;
91 
92 // For tracing process id changes
93 typedef struct TracePid {
94     char	*filename;
95     FILE	*fstream;
96     char	compressed[kCompressedSize];
97     char	*compressed_ptr;
98     uint64_t	prev_time;
99 } TracePid;
100 
101 // For tracing Dalvik VM method enter and exit
102 typedef struct TraceMethod {
103     char	*filename;
104     FILE	*fstream;
105     char	compressed[kCompressedSize];
106     char	*compressed_ptr;
107     uint64_t	prev_time;
108     uint32_t	prev_addr;
109     int32_t	prev_pid;
110 } TraceMethod;
111 
112 extern TraceBB trace_bb;
113 extern TraceInsn trace_insn;
114 extern TraceStatic trace_static;
115 extern TraceAddr trace_load;
116 extern TraceAddr trace_store;
117 extern TraceExc trace_exc;
118 extern TracePid trace_pid;
119 extern TraceMethod trace_method;
120 
121 // The simulated time, in clock ticks, starting with one.
122 extern uint64_t sim_time;
123 
124 // This variable == 1 if we are currently tracing, otherwise == 0.
125 extern int tracing;
126 extern int trace_all_addr;
127 extern int trace_cache_miss;
128 
129 extern void start_tracing();
130 extern void stop_tracing();
131 extern void trace_init(const char *filename);
132 extern void trace_bb_start(uint32_t bb_addr);
133 extern void trace_add_insn(uint32_t insn, int is_thumb);
134 extern void trace_bb_end();
135 
136 extern int get_insn_ticks_arm(uint32_t insn);
137 extern int get_insn_ticks_thumb(uint32_t  insn);
138 
139 extern void trace_exception(uint32 pc);
140 extern void trace_bb_helper(uint64_t bb_num, TranslationBlock *tb);
141 extern void trace_insn_helper();
142 extern void sim_dcache_load(uint32_t addr);
143 extern void sim_dcache_store(uint32_t addr, uint32_t val);
144 extern void sim_dcache_swp(uint32_t addr);
145 extern void trace_interpreted_method(uint32_t addr, int call_type);
146 
147 extern const char *trace_filename;
148 extern int tracing;
149 extern int trace_cache_miss;
150 extern int trace_all_addr;
151 
152 #endif /* TRACE_H */
153