Weekly Notes for Week 07
- In the lecture on February, 11th I will finish with the Chapter “Introduction” and will start the discussion of System Structures (Chapter 2).
- The 1st mandatory assignment will be made available on the course homepage during week 8.
- The following voluntary reading material will augment my presentation of DTrace, bpftrace, and perf. It might only be needed for week 08.
- Dynamic Instrumentation of Production Systems, Bryan M. Cantrill, Michael W. Shapiro and Adam H. Leventhal, Solaris Kernel Development Sun Microsystems link
- bpftrace and its bpftrace Tutorial
- DTrace Intro, pdf and Brandan Gregg’s page on dtrace
- The examples that were shown in the lecture can already be downloaded here, and will very likely be updated in week 8.
- Voluntary reading for SystemTap
- Voluntary reading on Linux kernel profiling with perf
- Note: The slides used in the lecture for the second chapter differ significantly from the original slides provided by Wiley.
Tutorial Session Week 07
- Prepare for the Tutorial Session in Week 07 from Chapter 1 the following exercises
- 1.1, 1.3, 1.4, 1.5, 1.6, 1.8, 1.10, 1.11 (Practice Exercises)
- 1.12, 1.14, 1.16, 1.19, 1.24 (Exercises)
C Programming (refresh)
- Which of the following is the proper declaration of a pointer?
- int x;
- int &x;
- ptr x;
- int *x;
- Which of the following gives the memory address of integer variable a?
- *a;
- a;
- &a;
- address(a);
- Which of the following gives the memory address of a variable pointed to by pointer a?
- a;
- *a;
- &a;
- address(a);
- Which of the following gives the value stored at the address pointed to by pointer a?
- a;
- val(a);
- *a;
- &a;
- Which of the following is the proper keyword or function to allocate memory in C?
- new
- malloc
- create
- value
- Which of the following is the proper keyword or function to deallocate memory?
- free
- delete
- clear
- remove
- Repeat the discussion of the four following examples to swap the content of two variables. Which of the examples are correct, which are wrong?
- Analyse the following C source code. Discuss what it does (this prepares you for the 1st mandatory assignment).
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include "dm510_msgbox.h"
#include <stdlib.h>
#include <string.h>
typedef struct _msg_t msg_t;
struct _msg_t{
msg_t* previous;
int length;
char* message;
};
static msg_t *bottom = NULL;
static msg_t *top = NULL;
int dm510_msgbox_put( char *buffer, int length ) {
msg_t* msg = malloc(sizeof(msg_t));
msg->previous = NULL;
msg->length = length;
msg->message = malloc(length);
memcpy(msg->message, buffer, length);
if (bottom == NULL) {
bottom = msg;
top = msg;
} else {
/* not empty stack */
msg->previous = top;
top = msg;
}
return 0;
}
int dm510_msgbox_get( char* buffer, int length ) {
if (top != NULL) {
msg_t* msg = top;
int mlength = msg->length;
top = msg->previous;
/* copy message */
memcpy(buffer, msg->message, mlength);
/* free memory */
free(msg->message);
free(msg);
return mlength;
}
return -1;
}
int main(int argc, char** argv) {
char *in = "This is a stupid message.";
char msg[50];
int msglen;
/* Send a message containing 'in' */
dm510_msgbox_put(in, strlen(in)+1);
/* Read a message */
msglen = dm510_msgbox_get(msg, 50);
return 0;
}