blob: e73951baf2f44e09015700669a56de0ec466c1b9 [file] [log] [blame]
yuezonghe824eb0c2024-06-27 02:32:26 -07001//**************************************************************************
2//*
3//* Copyright (c) 2016 ZTE Corporation.
4//*
5//**************************************************************************
6// geanfeng
7
8//**************************************************************************
9//* ½Å±¾½âÎöÇøÓò
10//**************************************************************************
11
12//¶¨Òå¾Ö²¿±äÁ¿
13local &os_time0 &os_time1 &os_time2 &os_time3 &os_time4 &os_time5 &os_time6 &os_time7
14local &os_time_cnt &os_next_time
15local &os_swap_last &os_swap_cnt &os_swap_next
16local &os_irq_start_last &os_irq_start_cnt &os_irq_start_next
17local &os_irq_end_last &os_irq_end_cnt &os_irq_end_next
18
19//for linux
20local &os_softirq_start_last &os_softirq_start_cnt &os_softirq_start_next
21local &os_softirq_end_last &os_softirq_end_cnt &os_softirq_end_next
22local &os_timer_start_last &os_timer_start_cnt &os_timer_start_next
23local &os_timer_end_last &os_timer_end_cnt &os_timer_end_next
24
25local &os_irq_enable &os_softirq_enable &os_timer_enable
26&os_irq_enable=1
27&os_softirq_enable=0
28&os_timer_enable=0
29
30//for tos
31local &os_dsr_start_last &os_dsr_start_cnt &os_dsr_start_next
32local &os_dsr_end_last &os_dsr_end_cnt &os_dsr_end_next
33&os_dsr_enable=0
34
35//´´½¨Ò»¸ö´°¿Ú£»
36&width=20.
37&nameWidth=20.
38&fileColumns=200.
39&fileLines=500.
40
41area.create trace &fileColumns &fileLines
42area.clear trace
43area.select trace
44
45//´ò¿ªÎļþ£»
46&dir=os.pwd()+"\log"
47if !os.dir(&dir)
48(
49 mkdir &dir
50)
51&file="&dir\result.txt"
52area.open trace &file
53area.view trace
54
55//Èç¹ûT32ÔÚÔËÐÐÒª¶Ïס£»
56if run()
57(
58 break
59)
60
61if symbol.exist(init_task)
62(
63 gosub LinuxTrace
64)
65
66if symbol.exist(tos_except)
67(
68 gosub TosTrace
69)
70
71area.close trace
72
73ENDDO
74//****ÔËÐнáÊø*****
75
76//*****************º¯Êý¶¨Òå**********************
77
78; ---------------------------------------------------------
79LinuxTrace:
80local &result
81
82if v.value(g_os_ddr_swapin_statistic)==0
83(
84 RETURN
85)
86
87&os_swap_last=v.value(g_os_ddr_swapin_statistic->index)
88&os_swap_cnt=v.value(sizeof(g_os_ddr_swapin_statistic->statistics)/sizeof(g_os_ddr_swapin_statistic->statistics[0]))
89&os_swap_next=&os_swap_last
90
91if &os_irq_enable==1
92(
93 &os_irq_start_last=v.value(g_os_ddr_irq_start_statistic->index)
94 &os_irq_start_cnt=v.value(sizeof(g_os_ddr_irq_start_statistic->statistics)/sizeof(g_os_ddr_irq_start_statistic->statistics[0]))
95 &os_irq_start_next=&os_irq_start_last
96 &os_irq_end_last=v.value(g_os_ddr_irq_end_statistic->index)
97 &os_irq_end_cnt=v.value(sizeof(g_os_ddr_irq_end_statistic->statistics)/sizeof(g_os_ddr_irq_end_statistic->statistics[0]))
98 &os_irq_end_next=&os_irq_end_last
99)
100else
101(
102 &os_irq_start_next=-1
103 &os_irq_end_next=-1
104)
105
106if &os_softirq_enable==1
107(
108 &os_softirq_start_last=v.value(g_os_ddr_softirq_start_statistic->index)
109 &os_softirq_start_cnt=v.value(sizeof(g_os_ddr_softirq_start_statistic->statistics)/sizeof(g_os_ddr_softirq_start_statistic->statistics[0]))
110 &os_softirq_start_next=&os_softirq_start_last
111 &os_softirq_end_last=v.value(g_os_ddr_softirq_end_statistic->index)
112 &os_softirq_end_cnt=v.value(sizeof(g_os_ddr_softirq_end_statistic->statistics)/sizeof(g_os_ddr_softirq_end_statistic->statistics[0]))
113 &os_softirq_end_next=&os_softirq_end_last
114)
115else
116(
117 &os_softirq_start_next=-1
118 &os_softirq_end_next=-1
119)
120
121if &os_timer_enable==1
122(
123 &os_timer_start_last=v.value(g_os_ddr_timer_start_statistic->index)
124 &os_timer_start_cnt=v.value(sizeof(g_os_ddr_timer_start_statistic->statistics)/sizeof(g_os_ddr_timer_start_statistic->statistics[0]))
125 &os_timer_start_next=&os_timer_start_last
126 &os_timer_end_last=v.value(g_os_ddr_timer_end_statistic->index)
127 &os_timer_end_cnt=v.value(sizeof(g_os_ddr_timer_end_statistic->statistics)/sizeof(g_os_ddr_timer_end_statistic->statistics[0]))
128 &os_timer_end_next=&os_timer_end_last
129)
130else
131(
132 &os_timer_start_next=-1
133 &os_timer_end_next=-1
134)
135
136//³õʼ»¯timeÊýÖµ
137if &os_swap_next==-1
138(
139 &os_time0=-1
140)
141else
142(
143 &os_time0=v.value(g_os_ddr_swapin_statistic->statistics[&os_swap_next].data2)
144)
145if &os_irq_start_next==-1
146(
147 &os_time1=-1
148)
149else
150(
151 &os_time1=v.value(g_os_ddr_irq_start_statistic->statistics[&os_irq_start_next].data2)
152)
153if &os_irq_end_next==-1
154(
155 &os_time2=-1
156)
157else
158(
159 &os_time2=v.value(g_os_ddr_irq_end_statistic->statistics[&os_irq_end_next].data2)
160)
161if &os_softirq_start_next==-1
162(
163 &os_time3=-1
164)
165else
166(
167 &os_time3=v.value(g_os_ddr_softirq_start_statistic->statistics[&os_softirq_start_next].data2)
168)
169if &os_softirq_end_next==-1
170(
171 &os_time4=-1
172)
173else
174(
175 &os_time4=v.value(g_os_ddr_softirq_end_statistic->statistics[&os_softirq_end_next].data2)
176)
177if &os_timer_start_next==-1
178(
179 &os_time5=-1
180)
181else
182(
183 &os_time5=v.value(g_os_ddr_timer_start_statistic->statistics[&os_timer_start_next].data2)
184)
185if &os_timer_end_next==-1
186(
187 &os_time6=-1
188)
189else
190(
191 &os_time6=v.value(g_os_ddr_timer_end_statistic->statistics[&os_timer_end_next].data2)
192)
193
194&os_time_cnt=7.
195&os_next_time=0.
196
197print format.string("Name",32,' ')+" "+"Index"+" "+"Time"+" "+"Exce"
198
199&result=0
200while &result==0
201(
202 gosub LinuxPrintNextLine
203 if ((&os_swap_next==-1)&&(&os_irq_start_next==-1)&&(&os_irq_end_next==-1)&&(&os_softirq_start_next==-1)&&(&os_softirq_end_next==-1)&&(&os_timer_start_next==-1)&&(&os_timer_end_next==-1))
204 (
205 print "END"
206 &result=-1
207 )
208)
209RETURN
210
211; ---------------------------------------------------------
212LinuxPrintNextLine:
213local &time &str &line_index
214
215gosub GetMinTimeIndex &os_time_cnt
216ENTRY &index
217
218if &index==0
219(
220 local &task &addr
221 &task=v.value(g_os_ddr_swapin_statistic->statistics[&os_swap_next].data1)
222 &addr=v.value(&((struct task_struct*)&task)->comm)
223 &str="THREAD: "+data.string(D:&addr)
224 &line_index=&os_swap_next
225 &time=&os_time0
226 gosub GetNextIndex &os_swap_cnt &os_swap_last &os_swap_next
227 ENTRY &os_swap_next
228 if &os_swap_next==-1
229 (
230 &os_time0=-1
231 )
232 else
233 (
234 &os_time0=v.value(g_os_ddr_swapin_statistic->statistics[&os_swap_next].data2)
235 )
236)
237else if &index==1
238(
239 local &irq &addr
240 &irq=v.value(g_os_ddr_irq_start_statistic->statistics[&os_irq_start_next].data1)
241 &addr=v.value(irq_desc[&irq].action->name)
242 &str="IRQSTA: "+data.string(D:&addr)+" S"
243 &line_index=&os_irq_start_next
244 &time=&os_time1
245 gosub GetNextIndex &os_irq_start_cnt &os_irq_start_last &os_irq_start_next
246 ENTRY &os_irq_start_next
247 if &os_irq_start_next==-1
248 (
249 &os_time1=-1
250 )
251 else
252 (
253 &os_time1=v.value(g_os_ddr_irq_start_statistic->statistics[&os_irq_start_next].data2)
254 )
255)
256else if &index==2
257(
258 local &irq &addr
259 &irq=v.value(g_os_ddr_irq_end_statistic->statistics[&os_irq_end_next].data1)
260 &addr=v.value(irq_desc[&irq].action->name)
261 &str="IRQEND: "+data.string(D:&addr)+" E"
262 &line_index=&os_irq_end_next
263 &time=&os_time2
264 gosub GetNextIndex &os_irq_end_cnt &os_irq_end_last &os_irq_end_next
265 ENTRY &os_irq_end_next
266 if &os_irq_end_next==-1
267 (
268 &os_time2=-1
269 )
270 else
271 (
272 &os_time2=v.value(g_os_ddr_irq_end_statistic->statistics[&os_irq_end_next].data2)
273 )
274)
275else if &index==3
276(
277 local &vec &func
278 &time=v.value(g_os_ddr_softirq_start_statistic->statistics[&os_softirq_start_next].data2)
279 &vec=v.value(g_os_ddr_softirq_start_statistic->statistics[&os_softirq_start_next].data1)
280 &func=v.value(softirq_vec[&vec].action)
281 &str="SIRQS: "+symbol.function(P:&func)+" S"
282 &line_index=&os_softirq_start_next
283 &time=&os_time3
284 gosub GetNextIndex &os_softirq_start_cnt &os_softirq_start_last &os_softirq_start_next
285 ENTRY &os_softirq_start_next
286 if &os_softirq_start_next==-1
287 (
288 &os_time3=-1
289 )
290 else
291 (
292 &os_time3=v.value(g_os_ddr_softirq_start_statistic->statistics[&os_softirq_start_next].data2)
293 )
294)
295else if &index==4
296(
297 local &vec &func
298 &time=v.value(g_os_ddr_softirq_end_statistic->statistics[&os_softirq_end_next].data2)
299 &vec=v.value(g_os_ddr_softirq_end_statistic->statistics[&os_softirq_end_next].data1)
300 &func=v.value(softirq_vec[&vec].action)
301 &str="SIRQE: "+symbol.function(P:&func)+" E"
302 &line_index=&os_softirq_end_next
303 &time=&os_time4
304 gosub GetNextIndex &os_softirq_end_cnt &os_softirq_end_last &os_softirq_end_next
305 ENTRY &os_softirq_end_next
306 if &os_softirq_end_next==-1
307 (
308 &os_time4=-1
309 )
310 else
311 (
312 &os_time4=v.value(g_os_ddr_softirq_end_statistic->statistics[&os_softirq_end_next].data2)
313 )
314)
315else if &index==5
316(
317 local &func
318 &time=v.value(g_os_ddr_timer_start_statistic->statistics[&os_timer_start_next].data2)
319 &func=v.value(g_os_ddr_timer_start_statistic->statistics[&os_timer_start_next].data1)
320 &str="TIMERS: "+symbol.function(P:&func)+" S"
321 &line_index=&os_timer_start_next
322 &time=&os_time5
323 gosub GetNextIndex &os_timer_start_cnt &os_timer_start_last &os_timer_start_next
324 ENTRY &os_timer_start_next
325 if &os_timer_start_next==-1
326 (
327 &os_time5=-1
328 )
329 else
330 (
331 &os_time5=v.value(g_os_ddr_timer_start_statistic->statistics[&os_timer_start_next].data2)
332 )
333)
334else if &index==6
335(
336 local &func
337 &time=v.value(g_os_ddr_timer_end_statistic->statistics[&os_timer_end_next].data2)
338 &func=v.value(g_os_ddr_timer_end_statistic->statistics[&os_timer_end_next].data1)
339 &str="TIMERE: "+symbol.function(P:&func)+" E"
340 &line_index=&os_timer_end_next
341 &time=&os_time6
342 gosub GetNextIndex &os_timer_end_cnt &os_timer_end_last &os_timer_end_next
343 ENTRY &os_timer_end_next
344 if &os_timer_end_next==-1
345 (
346 &os_time6=-1
347 )
348 else
349 (
350 &os_time6=v.value(g_os_ddr_timer_end_statistic->statistics[&os_timer_end_next].data2)
351 )
352)
353else
354(
355 print "Unknown Type"
356)
357
358gosub GetMinTime &os_time_cnt
359ENTRY &os_next_time
360
361print format.string("&str",32,' ')+" "+format.DecimalU(8,&line_index)+" "+format.DecimalU(1,&time)+" "+format.DecimalU(1,&os_next_time-&time)
362
363RETURN
364
365; ---------------------------------------------------------
366GetNextIndex:
367ENTRY &cnt &last_index &cur_index
368local &index
369
370if !((&cur_index>=0.)&&(&cur_index<&cnt))
371(
372 RETURN -1
373)
374
375&index=&cur_index+1
376if &index>=&cnt
377(
378 &index=0
379)
380if &index==&last_index
381(
382 &index=-1
383)
384RETURN &index
385
386; ---------------------------------------------------------
387GetMinTimeIndex:
388ENTRY &cnt
389local &i &min_index &min_val
390local &value &index
391
392&i=0.
393&min_index=0.
394&min_val=0xFFFFFFFF
395
396while &i<&cnt
397(
398 &index=string.cut("&i",-1)
399 &&value=&os_time&index
400 if (&value!=-1)&&(&min_val>=&value)
401 (
402 &min_val=&value
403 &min_index=&i
404 )
405 &i=&i+1
406)
407
408RETURN &min_index
409
410; ---------------------------------------------------------
411GetMinTime:
412ENTRY &cnt
413local &i &min_index &min_val
414local &value &index
415
416&i=0.
417&min_index=0.
418&min_val=0xFFFFFFFF
419
420while &i<&cnt
421(
422 &index=string.cut("&i",-1)
423 &&value=&os_time&index
424 if (&value!=-1)&&(&min_val>=&value)
425 (
426 &min_val=&value
427 &min_index=&i
428 )
429 &i=&i+1
430)
431
432RETURN &min_val
433
434; ---------------------------------------------------------
435TosPrintNextLine:
436local &time &str &line_index
437
438
439gosub GetMinTimeIndex &os_time_cnt
440ENTRY &index
441
442if &index==0
443(
444 local &task &addr
445 &task=v.value(g_os_ddr_swapin_statistic->statistics[&os_swap_next].data1)
446 &addr=v.value(&((Cyg_Thread*)&task)->thread_name)
447 &str="THREAD: "+data.string(D:&addr)
448 &line_index=&os_swap_next
449 &time=&os_time0
450 gosub GetNextIndex &os_swap_cnt &os_swap_last &os_swap_next
451 ENTRY &os_swap_next
452 if &os_swap_next==-1
453 (
454 &os_time0=-1
455 )
456 else
457 (
458 &os_time0=v.value(g_os_ddr_swapin_statistic->statistics[&os_swap_next].data2)
459 )
460)
461else if &index==1
462(
463 local &irq &addr
464 &irq=v.value(g_os_ddr_irq_start_statistic->statistics[&os_irq_start_next].data1)
465 &str="IRQSTA: "+format.DecimalU(1,&irq)+" S"
466 &line_index=&os_irq_start_next
467 &time=&os_time1
468 gosub GetNextIndex &os_irq_start_cnt &os_irq_start_last &os_irq_start_next
469 ENTRY &os_irq_start_next
470 if &os_irq_start_next==-1
471 (
472 &os_time1=-1
473 )
474 else
475 (
476 &os_time1=v.value(g_os_ddr_irq_start_statistic->statistics[&os_irq_start_next].data2)
477 )
478)
479else if &index==2
480(
481 local &irq &addr
482 &irq=v.value(g_os_ddr_irq_end_statistic->statistics[&os_irq_end_next].data1)
483 &str="IRQEND: "+format.DecimalU(1,&irq)+" E"
484 &line_index=&os_irq_end_next
485 &time=&os_time2
486 gosub GetNextIndex &os_irq_end_cnt &os_irq_end_last &os_irq_end_next
487 ENTRY &os_irq_end_next
488 if &os_irq_end_next==-1
489 (
490 &os_time2=-1
491 )
492 else
493 (
494 &os_time2=v.value(g_os_ddr_irq_end_statistic->statistics[&os_irq_end_next].data2)
495 )
496)
497else if &index==3
498(
499 local &dsr &addr
500 &dsr=v.value(g_os_ddr_dsr_start_statistic->statistics[&os_dsr_start_next].data1)
501 &str="DSRSTA: "+format.DecimalU(1,&dsr)+" S"
502 &line_index=&os_dsr_start_next
503 &time=&os_time3
504 gosub GetNextIndex &os_dsr_start_cnt &os_dsr_start_last &os_dsr_start_next
505 ENTRY &os_dsr_start_next
506 if &os_dsr_start_next==-1
507 (
508 &os_time3=-1
509 )
510 else
511 (
512 &os_time3=v.value(g_os_ddr_dsr_start_statistic->statistics[&os_dsr_start_next].data2)
513 )
514)
515else if &index==4
516(
517 local &dsr &addr
518 &dsr=v.value(g_os_ddr_dsr_end_statistic->statistics[&os_dsr_end_next].data1)
519 &str="DSREND: "+format.DecimalU(1,&dsr)+" E"
520 &line_index=&os_dsr_end_next
521 &time=&os_time4
522 gosub GetNextIndex &os_dsr_end_cnt &os_dsr_end_last &os_dsr_end_next
523 ENTRY &os_dsr_end_next
524 if &os_dsr_end_next==-1
525 (
526 &os_time4=-1
527 )
528 else
529 (
530 &os_time4=v.value(g_os_ddr_dsr_end_statistic->statistics[&os_dsr_end_next].data2)
531 )
532)
533else
534(
535 print "Unknown Type"
536)
537
538gosub GetMinTime &os_time_cnt
539ENTRY &os_next_time
540
541print format.string("&str",32,' ')+" "+format.DecimalU(8,&line_index)+" "+format.DecimalU(1,&time)+" "+format.DecimalU(1,&os_next_time-&time)
542
543RETURN
544
545; ---------------------------------------------------------
546TosTrace:
547local &result
548
549if v.value(g_os_ddr_swapin_statistic)==0
550(
551 RETURN
552)
553
554&os_swap_last=v.value(g_os_ddr_swapin_statistic->index)
555&os_swap_cnt=v.value(sizeof(g_os_ddr_swapin_statistic->statistics)/sizeof(g_os_ddr_swapin_statistic->statistics[0]))
556&os_swap_next=&os_swap_last
557
558if &os_irq_enable==1
559(
560 &os_irq_start_last=v.value(g_os_ddr_irq_start_statistic->index)
561 &os_irq_start_cnt=v.value(sizeof(g_os_ddr_irq_start_statistic->statistics)/sizeof(g_os_ddr_irq_start_statistic->statistics[0]))
562 &os_irq_start_next=&os_irq_start_last
563 &os_irq_end_last=v.value(g_os_ddr_irq_end_statistic->index)
564 &os_irq_end_cnt=v.value(sizeof(g_os_ddr_irq_end_statistic->statistics)/sizeof(g_os_ddr_irq_end_statistic->statistics[0]))
565 &os_irq_end_next=&os_irq_end_last
566)
567else
568(
569 &os_irq_start_next=-1
570 &os_irq_end_next=-1
571)
572
573if &os_dsr_enable==1
574(
575 &os_dsr_start_last=v.value(g_os_ddr_dsr_start_statistic->index)
576 &os_dsr_start_cnt=v.value(sizeof(g_os_ddr_dsr_start_statistic->statistics)/sizeof(g_os_ddr_dsr_start_statistic->statistics[0]))
577 &os_dsr_start_next=&os_dsr_start_last
578 &os_dsr_end_last=v.value(g_os_ddr_dsr_end_statistic->index)
579 &os_dsr_end_cnt=v.value(sizeof(g_os_ddr_dsr_end_statistic->statistics)/sizeof(g_os_ddr_dsr_end_statistic->statistics[0]))
580 &os_dsr_end_next=&os_dsr_end_last
581)
582else
583(
584 &os_dsr_start_next=-1
585 &os_dsr_end_next=-1
586)
587
588if &os_swap_next==-1
589(
590 &os_time0=-1
591)
592else
593(
594 &os_time0=v.value(g_os_ddr_swapin_statistic->statistics[&os_swap_next].data2)
595)
596if &os_irq_start_next==-1
597(
598 &os_time1=-1
599)
600else
601(
602 &os_time1=v.value(g_os_ddr_irq_start_statistic->statistics[&os_irq_start_next].data2)
603)
604if &os_irq_end_next==-1
605(
606 &os_time2=-1
607)
608else
609(
610 &os_time2=v.value(g_os_ddr_irq_end_statistic->statistics[&os_irq_end_next].data2)
611)
612
613if &os_dsr_start_next==-1
614(
615 &os_time3=-1
616)
617else
618(
619 &os_time3=v.value(g_os_ddr_dsr_start_statistic->statistics[&os_dsr_start_next].data2)
620)
621if &os_dsr_end_next==-1
622(
623 &os_time4=-1
624)
625else
626(
627 &os_time4=v.value(g_os_ddr_dsr_end_statistic->statistics[&os_dsr_end_next].data2)
628)
629
630&os_time_cnt=5.
631&os_next_time=0.
632
633print format.string("Name",32,' ')+" "+"Index"+" "+"Time"+" "+"Exce"
634
635&result=0
636while &result==0
637(
638 gosub TosPrintNextLine
639 if ((&os_swap_next==-1)&&(&os_irq_start_next==-1)&&(&os_irq_end_next==-1)&&(&os_dsr_start_next==-1)&&(&os_dsr_end_next==-1))
640 (
641 print "END"
642 &result=-1
643 )
644)
645
646RETURN