Enrico Granata | f58cece | 2013-03-08 20:29:13 +0000 | [diff] [blame] | 1 | // |
| 2 | // main.cpp |
| 3 | // PerfTestDriver |
| 4 | // |
| 5 | // Created by Enrico Granata on 3/6/13. |
| 6 | // Copyright (c) 2013 Apple Inc. All rights reserved. |
| 7 | // |
| 8 | |
| 9 | #include <CoreFoundation/CoreFoundation.h> |
| 10 | |
| 11 | #include "lldb-perf/lib/Timer.h" |
| 12 | #include "lldb-perf/lib/Metric.h" |
| 13 | #include "lldb-perf/lib/Measurement.h" |
| 14 | #include "lldb-perf/lib/TestCase.h" |
| 15 | #include "lldb-perf/lib/Xcode.h" |
| 16 | |
| 17 | #include <iostream> |
| 18 | #include <unistd.h> |
| 19 | #include <fstream> |
| 20 | |
Greg Clayton | 7b8f738 | 2013-03-18 22:34:00 +0000 | [diff] [blame] | 21 | using namespace lldb_perf; |
Enrico Granata | f58cece | 2013-03-08 20:29:13 +0000 | [diff] [blame] | 22 | |
| 23 | class SketchTest : public TestCase |
| 24 | { |
| 25 | public: |
| 26 | SketchTest () : |
Greg Clayton | 1080faf | 2013-03-19 19:30:33 +0000 | [diff] [blame] | 27 | m_fetch_frames_measurement ([this] () -> void |
| 28 | { |
| 29 | Xcode::FetchFrames (GetProcess(),false,false); |
| 30 | }, "fetch-frames", "time to dump backtrace for every frame in every thread"), |
| 31 | m_file_line_bp_measurement([this] (const char* file, uint32_t line) -> void |
| 32 | { |
| 33 | Xcode::CreateFileLineBreakpoint(GetTarget(), file, line); |
| 34 | }, "file-line-bkpt", "time to set a breakpoint given a file and line"), |
| 35 | m_fetch_modules_measurement ([this] () -> void |
| 36 | { |
| 37 | Xcode::FetchModules(GetTarget()); |
| 38 | }, "fetch-modules", "time to get info for all modules in the process"), |
| 39 | m_fetch_vars_measurement([this] (int depth) -> void |
| 40 | { |
| 41 | SBProcess process (GetProcess()); |
| 42 | auto threads_count = process.GetNumThreads(); |
| 43 | for (size_t thread_num = 0; thread_num < threads_count; thread_num++) |
| 44 | { |
| 45 | SBThread thread(process.GetThreadAtIndex(thread_num)); |
| 46 | SBFrame frame(thread.GetFrameAtIndex(0)); |
| 47 | Xcode::FetchVariables(frame,depth,GetVerbose()); |
| 48 | } |
| 49 | }, "fetch-vars", "time to dump variables for the topmost frame in every thread"), |
| 50 | m_run_expr_measurement([this] (SBFrame frame, const char* expr) -> void |
| 51 | { |
| 52 | SBValue value(frame.EvaluateExpression(expr, lldb::eDynamicCanRunTarget)); |
| 53 | Xcode::FetchVariable (value, 0, GetVerbose()); |
| 54 | }, "run-expr", "time to evaluate an expression and display the result") |
Enrico Granata | f58cece | 2013-03-08 20:29:13 +0000 | [diff] [blame] | 55 | {} |
| 56 | |
| 57 | virtual |
| 58 | ~SketchTest () |
| 59 | { |
| 60 | } |
| 61 | |
Greg Clayton | e0b924e | 2013-03-19 04:41:22 +0000 | [diff] [blame] | 62 | virtual bool |
Enrico Granata | f58cece | 2013-03-08 20:29:13 +0000 | [diff] [blame] | 63 | Setup (int argc, const char** argv) |
| 64 | { |
Greg Clayton | 1080faf | 2013-03-19 19:30:33 +0000 | [diff] [blame] | 65 | //SetVerbose(true); |
Enrico Granata | 8691057 | 2013-03-14 19:00:42 +0000 | [diff] [blame] | 66 | m_app_path.assign(argv[1]); |
| 67 | m_doc_path.assign(argv[2]); |
Enrico Granata | f58cece | 2013-03-08 20:29:13 +0000 | [diff] [blame] | 68 | m_out_path.assign(argv[3]); |
| 69 | TestCase::Setup(argc,argv); |
| 70 | m_target = m_debugger.CreateTarget(m_app_path.c_str()); |
| 71 | const char* file_arg = m_doc_path.c_str(); |
| 72 | const char* persist_arg = "-ApplePersistenceIgnoreState"; |
| 73 | const char* persist_skip = "YES"; |
| 74 | const char* empty = nullptr; |
| 75 | const char* args[] = {file_arg,persist_arg,persist_skip,empty}; |
Greg Clayton | e0b924e | 2013-03-19 04:41:22 +0000 | [diff] [blame] | 76 | SBLaunchInfo launch_info (args); |
Greg Clayton | 1080faf | 2013-03-19 19:30:33 +0000 | [diff] [blame] | 77 | m_file_line_bp_measurement("SKTDocument.m",245); |
| 78 | m_file_line_bp_measurement("SKTDocument.m",283); |
| 79 | m_file_line_bp_measurement("SKTText.m",326); |
Greg Clayton | e0b924e | 2013-03-19 04:41:22 +0000 | [diff] [blame] | 80 | return Launch (launch_info); |
Enrico Granata | f58cece | 2013-03-08 20:29:13 +0000 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | void |
| 84 | DoTest () |
| 85 | { |
Greg Clayton | 1080faf | 2013-03-19 19:30:33 +0000 | [diff] [blame] | 86 | m_fetch_frames_measurement(); |
| 87 | m_fetch_modules_measurement(); |
| 88 | m_fetch_vars_measurement(1); |
Enrico Granata | f58cece | 2013-03-08 20:29:13 +0000 | [diff] [blame] | 89 | } |
| 90 | |
Greg Clayton | 7b8f738 | 2013-03-18 22:34:00 +0000 | [diff] [blame] | 91 | virtual void |
| 92 | TestStep (int counter, ActionWanted &next_action) |
Enrico Granata | f58cece | 2013-03-08 20:29:13 +0000 | [diff] [blame] | 93 | { |
Greg Clayton | 7b8f738 | 2013-03-18 22:34:00 +0000 | [diff] [blame] | 94 | switch (counter) |
| 95 | { |
| 96 | case 0: |
| 97 | { |
| 98 | DoTest (); |
Greg Clayton | 1080faf | 2013-03-19 19:30:33 +0000 | [diff] [blame] | 99 | m_file_line_bp_measurement("SKTDocument.m",254); |
Greg Clayton | 7b8f738 | 2013-03-18 22:34:00 +0000 | [diff] [blame] | 100 | next_action.Continue(); |
| 101 | } |
| 102 | break; |
| 103 | |
| 104 | case 1: |
| 105 | { |
| 106 | DoTest (); |
Greg Clayton | e0b924e | 2013-03-19 04:41:22 +0000 | [diff] [blame] | 107 | m_run_expr_measurement(m_thread.GetFrameAtIndex(0),"properties"); |
| 108 | m_run_expr_measurement(m_thread.GetFrameAtIndex(0),"[properties description]"); |
| 109 | m_run_expr_measurement(m_thread.GetFrameAtIndex(0),"typeName"); |
| 110 | m_run_expr_measurement(m_thread.GetFrameAtIndex(0),"data"); |
| 111 | m_run_expr_measurement(m_thread.GetFrameAtIndex(0),"[data description]"); |
Greg Clayton | 7b8f738 | 2013-03-18 22:34:00 +0000 | [diff] [blame] | 112 | next_action.Continue(); |
| 113 | } |
| 114 | break; |
| 115 | |
| 116 | case 2: |
| 117 | { |
| 118 | DoTest (); |
| 119 | next_action.Continue(); |
| 120 | } |
| 121 | break; |
| 122 | |
| 123 | case 3: |
| 124 | { |
| 125 | DoTest (); |
Greg Clayton | e0b924e | 2013-03-19 04:41:22 +0000 | [diff] [blame] | 126 | next_action.StepOver(m_thread); |
Greg Clayton | 7b8f738 | 2013-03-18 22:34:00 +0000 | [diff] [blame] | 127 | } |
| 128 | break; |
| 129 | |
| 130 | case 4: |
| 131 | { |
| 132 | DoTest (); |
Greg Clayton | e0b924e | 2013-03-19 04:41:22 +0000 | [diff] [blame] | 133 | m_run_expr_measurement(m_thread.GetFrameAtIndex(0),"layoutManager"); |
| 134 | m_run_expr_measurement(m_thread.GetFrameAtIndex(0),"contents"); |
| 135 | next_action.StepOver(m_thread); |
Greg Clayton | 7b8f738 | 2013-03-18 22:34:00 +0000 | [diff] [blame] | 136 | } |
| 137 | break; |
| 138 | |
| 139 | case 5: |
| 140 | { |
| 141 | DoTest (); |
Greg Clayton | e0b924e | 2013-03-19 04:41:22 +0000 | [diff] [blame] | 142 | next_action.StepOver(m_thread); |
Greg Clayton | 7b8f738 | 2013-03-18 22:34:00 +0000 | [diff] [blame] | 143 | } |
| 144 | break; |
| 145 | |
| 146 | case 6: |
| 147 | { |
| 148 | DoTest (); |
Greg Clayton | e0b924e | 2013-03-19 04:41:22 +0000 | [diff] [blame] | 149 | next_action.StepOver(m_thread); |
Greg Clayton | 7b8f738 | 2013-03-18 22:34:00 +0000 | [diff] [blame] | 150 | } |
| 151 | break; |
| 152 | |
| 153 | case 7: |
| 154 | { |
| 155 | DoTest (); |
Greg Clayton | e0b924e | 2013-03-19 04:41:22 +0000 | [diff] [blame] | 156 | m_run_expr_measurement(m_thread.GetFrameAtIndex(0),"@\"an NSString\""); |
| 157 | m_run_expr_measurement(m_thread.GetFrameAtIndex(0),"[(id)@\"an NSString\" description]"); |
| 158 | m_run_expr_measurement(m_thread.GetFrameAtIndex(0),"@[@1,@2,@3]"); |
| 159 | next_action.StepOut(m_thread); |
Greg Clayton | 7b8f738 | 2013-03-18 22:34:00 +0000 | [diff] [blame] | 160 | } |
| 161 | break; |
| 162 | |
| 163 | case 8: |
| 164 | { |
| 165 | DoTest (); |
Greg Clayton | e0b924e | 2013-03-19 04:41:22 +0000 | [diff] [blame] | 166 | m_run_expr_measurement(m_thread.GetFrameAtIndex(0),"[graphics description]"); |
| 167 | m_run_expr_measurement(m_thread.GetFrameAtIndex(0),"[selectionIndexes description]"); |
| 168 | m_run_expr_measurement(m_thread.GetFrameAtIndex(0),"(BOOL)NSIntersectsRect(rect, graphicDrawingBounds)"); |
Greg Clayton | 7b8f738 | 2013-03-18 22:34:00 +0000 | [diff] [blame] | 169 | next_action.Kill(); |
| 170 | } |
| 171 | break; |
| 172 | |
| 173 | default: |
| 174 | { |
| 175 | next_action.Kill(); |
| 176 | } |
| 177 | break; |
Enrico Granata | f58cece | 2013-03-08 20:29:13 +0000 | [diff] [blame] | 178 | } |
Enrico Granata | f58cece | 2013-03-08 20:29:13 +0000 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | void |
| 182 | Results () |
| 183 | { |
Enrico Granata | f58cece | 2013-03-08 20:29:13 +0000 | [diff] [blame] | 184 | CFCMutableArray array; |
Enrico Granata | 24ccabf | 2013-03-08 20:50:36 +0000 | [diff] [blame] | 185 | m_fetch_frames_measurement.Write(array); |
| 186 | m_file_line_bp_measurement.Write(array); |
| 187 | m_fetch_modules_measurement.Write(array); |
| 188 | m_fetch_vars_measurement.Write(array); |
| 189 | m_run_expr_measurement.Write(array); |
Enrico Granata | f58cece | 2013-03-08 20:29:13 +0000 | [diff] [blame] | 190 | |
| 191 | CFDataRef xmlData = CFPropertyListCreateData(kCFAllocatorDefault, array.get(), kCFPropertyListXMLFormat_v1_0, 0, NULL); |
| 192 | |
| 193 | CFURLRef file = CFURLCreateFromFileSystemRepresentation(NULL, (const UInt8*)m_out_path.c_str(), m_out_path.size(), FALSE); |
| 194 | |
| 195 | CFURLWriteDataAndPropertiesToResource(file,xmlData,NULL,NULL); |
| 196 | } |
| 197 | |
| 198 | private: |
Greg Clayton | 1080faf | 2013-03-19 19:30:33 +0000 | [diff] [blame] | 199 | Measurement<lldb_perf::TimeGauge, std::function<void()>> m_fetch_frames_measurement; |
| 200 | Measurement<lldb_perf::TimeGauge, std::function<void(const char*, uint32_t)>> m_file_line_bp_measurement; |
| 201 | Measurement<lldb_perf::TimeGauge, std::function<void()>> m_fetch_modules_measurement; |
| 202 | Measurement<lldb_perf::TimeGauge, std::function<void(int)>> m_fetch_vars_measurement; |
| 203 | Measurement<lldb_perf::TimeGauge, std::function<void(SBFrame, const char*)>> m_run_expr_measurement; |
Enrico Granata | f58cece | 2013-03-08 20:29:13 +0000 | [diff] [blame] | 204 | |
Enrico Granata | f58cece | 2013-03-08 20:29:13 +0000 | [diff] [blame] | 205 | std::string m_app_path; |
| 206 | std::string m_doc_path; |
| 207 | std::string m_out_path; |
| 208 | }; |
| 209 | |
| 210 | // argv[1] == path to app |
| 211 | // argv[2] == path to document |
| 212 | // argv[3] == path to result |
| 213 | int main(int argc, const char * argv[]) |
| 214 | { |
| 215 | SketchTest skt; |
| 216 | TestCase::Run(skt,argc,argv); |
| 217 | return 0; |
| 218 | } |
| 219 | |