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