Browse Source

[profile] Provide methods for profiling individual stages of operations

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 10 years ago
parent
commit
a0da06c306
2 changed files with 41 additions and 11 deletions
  1. 6
    4
      src/arch/i386/transitions/librm_test.c
  2. 35
    7
      src/include/ipxe/profile.h

+ 6
- 4
src/arch/i386/transitions/librm_test.c View File

51
  */
51
  */
52
 static void librm_test_exec ( void ) {
52
 static void librm_test_exec ( void ) {
53
 	unsigned int i;
53
 	unsigned int i;
54
-	unsigned long p2r_elapsed;
54
+	unsigned long timestamp;
55
+	unsigned int discard_d;
55
 
56
 
56
 	/* Profile mode transitions.  We want to profile each
57
 	/* Profile mode transitions.  We want to profile each
57
 	 * direction of the transition separately, so perform an RDTSC
58
 	 * direction of the transition separately, so perform an RDTSC
61
 	for ( i = 0 ; i < PROFILE_COUNT ; i++ ) {
62
 	for ( i = 0 ; i < PROFILE_COUNT ; i++ ) {
62
 		profile_start ( &p2r_profiler );
63
 		profile_start ( &p2r_profiler );
63
 		__asm__ __volatile__ ( REAL_CODE ( "rdtsc\n\t" )
64
 		__asm__ __volatile__ ( REAL_CODE ( "rdtsc\n\t" )
64
-				       : "=A" ( r2p_profiler.started ) : );
65
+				       : "=a" ( timestamp ), "=d" ( discard_d )
66
+				       : );
67
+		profile_start_at ( &r2p_profiler, timestamp );
65
 		profile_stop ( &r2p_profiler );
68
 		profile_stop ( &r2p_profiler );
66
-		p2r_elapsed = ( r2p_profiler.started - p2r_profiler.started );
67
-		profile_update ( &p2r_profiler, p2r_elapsed );
69
+		profile_stop_at ( &p2r_profiler, timestamp );
68
 	}
70
 	}
69
 }
71
 }
70
 
72
 

+ 35
- 7
src/include/ipxe/profile.h View File

9
 
9
 
10
 FILE_LICENCE ( GPL2_OR_LATER );
10
 FILE_LICENCE ( GPL2_OR_LATER );
11
 
11
 
12
-#include <stdint.h>
13
 #include <bits/profile.h>
12
 #include <bits/profile.h>
14
 #include <ipxe/tables.h>
13
 #include <ipxe/tables.h>
15
 
14
 
26
 	/** Name */
25
 	/** Name */
27
 	const char *name;
26
 	const char *name;
28
 	/** Start timestamp */
27
 	/** Start timestamp */
29
-	uint64_t started;
28
+	unsigned long started;
29
+	/** Stop timestamp */
30
+	unsigned long stopped;
30
 	/** Number of samples */
31
 	/** Number of samples */
31
 	unsigned int count;
32
 	unsigned int count;
32
 	/** Mean sample value (scaled) */
33
 	/** Mean sample value (scaled) */
62
 extern unsigned long profile_variance ( struct profiler *profiler );
63
 extern unsigned long profile_variance ( struct profiler *profiler );
63
 extern unsigned long profile_stddev ( struct profiler *profiler );
64
 extern unsigned long profile_stddev ( struct profiler *profiler );
64
 
65
 
66
+/**
67
+ * Start profiling
68
+ *
69
+ * @v profiler		Profiler
70
+ * @v started		Start timestamp
71
+ */
72
+static inline __attribute__ (( always_inline )) void
73
+profile_start_at ( struct profiler *profiler, unsigned long started ) {
74
+
75
+	/* If profiling is active then record start timestamp */
76
+	if ( PROFILING )
77
+		profiler->started = started;
78
+}
79
+
65
 /**
80
 /**
66
  * Start profiling
81
  * Start profiling
67
  *
82
  *
72
 
87
 
73
 	/* If profiling is active then record start timestamp */
88
 	/* If profiling is active then record start timestamp */
74
 	if ( PROFILING )
89
 	if ( PROFILING )
75
-		profiler->started = profile_timestamp();
90
+		profile_start_at ( profiler, profile_timestamp() );
76
 }
91
 }
77
 
92
 
78
 /**
93
 /**
79
  * Record profiling result
94
  * Record profiling result
80
  *
95
  *
81
  * @v profiler		Profiler
96
  * @v profiler		Profiler
97
+ * @v stopped		Stop timestamp
82
  */
98
  */
83
 static inline __attribute__ (( always_inline )) void
99
 static inline __attribute__ (( always_inline )) void
84
-profile_stop ( struct profiler *profiler ) {
85
-	uint64_t ended;
100
+profile_stop_at ( struct profiler *profiler, unsigned long stopped ) {
86
 
101
 
87
 	/* If profiling is active then record end timestamp and update stats */
102
 	/* If profiling is active then record end timestamp and update stats */
88
 	if ( PROFILING ) {
103
 	if ( PROFILING ) {
89
-		ended = profile_timestamp();
90
-		profile_update ( profiler, ( ended - profiler->started ) );
104
+		profiler->stopped = stopped;
105
+		profile_update ( profiler, ( stopped - profiler->started ) );
91
 	}
106
 	}
92
 }
107
 }
93
 
108
 
109
+/**
110
+ * Record profiling result
111
+ *
112
+ * @v profiler		Profiler
113
+ */
114
+static inline __attribute__ (( always_inline )) void
115
+profile_stop ( struct profiler *profiler ) {
116
+
117
+	/* If profiling is active then record end timestamp and update stats */
118
+	if ( PROFILING )
119
+		profile_stop_at ( profiler, profile_timestamp() );
120
+}
121
+
94
 #endif /* _IPXE_PROFILE_H */
122
 #endif /* _IPXE_PROFILE_H */

Loading…
Cancel
Save