Skip to content
This repository
Browse code

Add a slider to control the batch size.

This change adds a toolbar with a slider to directly set the number of
events per batch, which controls the frequency of stack trace samples.
  • Loading branch information...
commit d4cfaf21267b77d499b45636da5618a15abca612 1 parent 055a27b
Andrew Clinton authored May 11, 2013
5  Loader.C
@@ -41,6 +41,7 @@ Loader::Loader(MemoryState *state, StackTraceMap *stack, MMapMap *mmapmap)
41 41
     , myMMapMap(mmapmap)
42 42
     , myTotalEvents(0)
43 43
     , myPendingClear(false)
  44
+    , myBlockSize(MV_BlockSize)
44 45
     , myChild(-1)
45 46
     , myPipeFD(0)
46 47
     , myPipe(0)
@@ -193,7 +194,7 @@ Loader::openPipe(int argc, char *argv[])
193 194
     // Queue up some tokens
194 195
     myNextToken = 1;
195 196
     for (int i = 1; i < MV_BufCount; i++)
196  
-	writeToken(MV_BlockSize);
  197
+	writeToken(myBlockSize);
197 198
 
198 199
     return true;
199 200
 }
@@ -455,7 +456,7 @@ Loader::loadFromPipe()
455 456
     {
456 457
 	LoaderBlockHandle block(new LoaderBlock(mySharedData->myData[myIdx]));
457 458
 
458  
-	writeToken(MV_BlockSize);
  459
+	writeToken(myBlockSize);
459 460
 
460 461
 	incBuf(myIdx);
461 462
 
8  Loader.h
@@ -78,6 +78,12 @@ class Loader : public QThread {
78 78
 		    myPendingClear = true;
79 79
 		}
80 80
 
  81
+    // Regulates the interval between stack traces
  82
+    void	setBlockSize(int size)
  83
+		{
  84
+		    myBlockSize = SYSclamp(size, 1, MV_BlockSize);
  85
+		}
  86
+
81 87
     MemoryState	*getBaseState() const { return myState; }
82 88
 
83 89
     uint64	getTotalEvents() const { return myTotalEvents; }
@@ -118,6 +124,8 @@ class Loader : public QThread {
118 124
     std::unique_ptr<MemoryState> myPendingState;
119 125
     bool		 myPendingClear;
120 126
 
  127
+    int			 myBlockSize;
  128
+
121 129
     // Child process
122 130
     pid_t	 myChild;
123 131
     int		 myPipeFD;
68  Window.C
@@ -34,8 +34,55 @@
34 34
 
35 35
 static const QSize	theDefaultSize(800, 600);
36 36
 
  37
+LogSlider::LogSlider(const char *name, int maxlogval, int deflogval)
  38
+{
  39
+    mySlider = new QSlider(Qt::Horizontal);
  40
+    mySlider->setRange(0, maxlogval);
  41
+    mySlider->setSingleStep(1);
  42
+    mySlider->setPageStep(5);
  43
+    mySlider->setTickPosition(QSlider::TicksBothSides);
  44
+    mySlider->setTracking(true);
  45
+    mySlider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Ignored);
  46
+    mySlider->setFixedWidth(300);
  47
+
  48
+    myLabel = new QLabel(name);
  49
+    myNumber = new QLabel;
  50
+    myNumber->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Ignored);
  51
+    myNumber->setFixedWidth(50);
  52
+    myNumber->setAlignment(Qt::AlignLeft | Qt::AlignVCenter);
  53
+
  54
+    QHBoxLayout	*layout = new QHBoxLayout;
  55
+
  56
+    layout->addWidget(myLabel);
  57
+    layout->addWidget(mySlider);
  58
+    layout->addWidget(myNumber);
  59
+
  60
+    setLayout(layout);
  61
+
  62
+    connect(mySlider, SIGNAL(valueChanged(int)), this, SLOT(fromLog(int)));
  63
+
  64
+    mySlider->setValue(deflogval);
  65
+    fromLog(mySlider->value());
  66
+}
  67
+
  68
+void
  69
+LogSlider::setLogValue(int value)
  70
+{
  71
+    mySlider->setValue(value);
  72
+}
  73
+
  74
+void LogSlider::fromLog(int value)
  75
+{
  76
+    value = 1 << value;
  77
+    myNumber->setNum(value);
  78
+    emit valueChanged(value);
  79
+}
  80
+
  81
+
37 82
 Window::Window(int argc, char *argv[])
38 83
 {
  84
+    const char	*batchsize = extractOption(argc, argv, "--batch-size=");
  85
+
39 86
     myScrollArea = new MemViewScroll(this);
40 87
 
41 88
     setStatusBar(statusBar());
@@ -128,6 +175,22 @@ Window::Window(int argc, char *argv[])
128 175
 
129 176
     myScrollArea->setViewport(myMemView);
130 177
     setCentralWidget(myScrollArea);
  178
+
  179
+    myToolBar = new QToolBar("Tools");
  180
+    myToolBar->setAllowedAreas(Qt::TopToolBarArea | Qt::BottomToolBarArea);
  181
+    addToolBar(Qt::TopToolBarArea, myToolBar);
  182
+
  183
+    LogSlider *slider = new LogSlider("Batch Size", 15, 15);
  184
+
  185
+    myToolBar->addWidget(slider);
  186
+
  187
+    connect(slider, SIGNAL(valueChanged(int)), myMemView, SLOT(batchSize(int)));
  188
+
  189
+    if (batchsize)
  190
+    {
  191
+	int value = (int)(log((double)atoi(batchsize))/log(2.0));
  192
+	slider->setLogValue(value);
  193
+    }
131 194
 }
132 195
 
133 196
 Window::~Window()
@@ -289,6 +352,11 @@ void MemViewWidget::datatype(QAction *action)
289 352
     myDataType = action->actionGroup()->actions().indexOf(action) - 1;
290 353
 }
291 354
 
  355
+void MemViewWidget::batchSize(int value)
  356
+{
  357
+    myLoader->setBlockSize(value);
  358
+}
  359
+
292 360
 // Load a file into a buffer.  The buffer is owned by the caller, and
293 361
 // should be freed with delete[].
294 362
 static char *
31  Window.h
@@ -40,9 +40,28 @@ class MemViewWidget;
40 40
 class MemViewScroll;
41 41
 class Loader;
42 42
 
43  
-class Window : public QMainWindow {
44  
-    Q_OBJECT
  43
+// A horizontal slider widget with a label to the left and right.  The
  44
+// right label shows the numeric value of the slider.  The slider values
  45
+// are mapped to powers of 2.
  46
+class LogSlider : public QWidget { Q_OBJECT
  47
+public:
  48
+    LogSlider(const char *name, int maxlogval, int deflogval);
  49
+
  50
+    void    setLogValue(int value);
  51
+
  52
+signals:
  53
+    void    valueChanged(int value);
  54
+
  55
+public slots:
  56
+    void    fromLog(int value);
  57
+
  58
+private:
  59
+    QLabel	*myLabel;
  60
+    QSlider	*mySlider;
  61
+    QLabel	*myNumber;
  62
+};
45 63
 
  64
+class Window : public QMainWindow { Q_OBJECT
46 65
 public:
47 66
 	     Window(int argc, char *argv[]);
48 67
     virtual ~Window();
@@ -81,6 +100,8 @@ class Window : public QMainWindow {
81 100
     QActionGroup	*myDataTypeGroup;
82 101
     QAction		*myDataType[theDataTypeCount];
83 102
 
  103
+    QToolBar		*myToolBar;
  104
+
84 105
     MemViewWidget	*myMemView;
85 106
     MemViewScroll	*myScrollArea;
86 107
 };
@@ -97,9 +118,7 @@ class MemViewScroll : public QAbstractScrollArea {
97 118
 };
98 119
 
99 120
 // A widget to render the memory visualization.
100  
-class MemViewWidget : public QGLWidget {
101  
-    Q_OBJECT
102  
-
  121
+class MemViewWidget : public QGLWidget { Q_OBJECT
103 122
 public:
104 123
 	     MemViewWidget(int argc, char *argv[],
105 124
 			    QWidget *parent,
@@ -151,6 +170,8 @@ private slots:
151 170
 
152 171
     void    dimmer();
153 172
 
  173
+    void    batchSize(int value);
  174
+
154 175
 private:
155 176
     GLImage<uint32>	 myImage;
156 177
     QScrollBar		*myVScrollBar;
3  main.C
@@ -31,6 +31,9 @@ usage()
31 31
     fprintf(stderr, "\t--ignore-bits=n\n"
32 32
 	"\t\tDrop the n least significant bits in memory addresses.\n"
33 33
 	"\t\tThis option can be used to optimize memory use. [2]\n");
  34
+    fprintf(stderr, "\t--batch-size=n\n"
  35
+	"\t\tTake a stack trace sample after every n events.\n"
  36
+	"\t\tThis value must be between 1 and 32768. [32768]\n");
34 37
     fprintf(stderr, "\t--tool=[memview|lackey]\n"
35 38
 	"\t\tBy default, memview will use the 'memview' valgrind\n"
36 39
 	"\t\ttool.  If you have an unpatched valgrind, you can force the\n"
6  valgrind/memview/mv_main.c
@@ -554,13 +554,17 @@ static void flushEventsRange(IRSB* sb, Int start, Int size)
554 554
     IRExpr *entries_addr = mkU64((ULong)&theEntries);
555 555
     IRExpr *entries = load(ENDIAN, Ity_I32, entries_addr);
556 556
 
  557
+    IRExpr *max_entries_addr = mkU64((ULong)&theMaxEntries);
  558
+    IRExpr *max_entries = load(ENDIAN, Ity_I32, max_entries_addr);
  559
+
557 560
     IRDirty*   di =
558 561
 	unsafeIRDirty_0_N(0,
559 562
 	    "flush_data", VG_(fnptr_to_fnentry)( flush_data ),
560 563
 	    mkIRExprVec_0() );
561 564
 
562 565
     di->guard =
563  
-	binop(Iop_CmpLT32S, mkU32(theMaxEntries - size), entries);
  566
+	binop(Iop_CmpLT32S, max_entries,
  567
+		binop(Iop_Add32, entries, mkU32(size)));
564 568
 
565 569
     addStmtToIRSB( sb, IRStmt_Dirty(di) );
566 570
 

0 notes on commit d4cfaf2

Please sign in to comment.
Something went wrong with that request. Please try again.