1 | /******************************************************************************
|
---|
2 | * $Header: /CommonBe/agmsmith/Programming/SteadyCast/KernelLeakTest/RCS/KernelLeaker.cpp,v 1.2 2019/11/22 21:42:23 agmsmith Exp $
|
---|
3 | *
|
---|
4 | * Compile with: g++ -lbe KernelLeaker.cpp
|
---|
5 | *
|
---|
6 | * Looking in to a kernel_team memory leak - seems to happen when BMessages are
|
---|
7 | * sent to different teams when using the same BMessenger. Run it and watch
|
---|
8 | * the memory usage in ProcessController for the kernel_team, you'll see it
|
---|
9 | * cranking up slowly. When the program is exited, the leaks remain.
|
---|
10 | *
|
---|
11 | * By AGMS, write to agmsmith@ncf.ca
|
---|
12 | */
|
---|
13 |
|
---|
14 | /* Standard C Library. */
|
---|
15 |
|
---|
16 | #include <stdio.h>
|
---|
17 | #include <stdlib.h>
|
---|
18 |
|
---|
19 | /* BeOS (Be Operating System) headers. */
|
---|
20 |
|
---|
21 | #include <Application.h>
|
---|
22 |
|
---|
23 | static const char *g_AppSignature =
|
---|
24 | "application/x-vnd.agmsmith.kernel-leak-20191122";
|
---|
25 |
|
---|
26 |
|
---|
27 | class KernelLeakerApp : public BApplication
|
---|
28 | {
|
---|
29 | public:
|
---|
30 | /* Constructor and destructor. */
|
---|
31 | KernelLeakerApp ();
|
---|
32 | ~KernelLeakerApp ();
|
---|
33 |
|
---|
34 | /* BeOS virtual functions. */
|
---|
35 | virtual void Pulse ();
|
---|
36 | virtual bool QuitRequested ();
|
---|
37 | virtual void ReadyToRun ();
|
---|
38 |
|
---|
39 | };
|
---|
40 |
|
---|
41 |
|
---|
42 | /******************************************************************************
|
---|
43 | * Implementation of the KernelLeakerApp class. Constructor, destructor and
|
---|
44 | * the rest of the member functions in mostly alphabetical order.
|
---|
45 | */
|
---|
46 |
|
---|
47 | KernelLeakerApp::KernelLeakerApp () : BApplication (g_AppSignature)
|
---|
48 | {
|
---|
49 | SetName ("Kernel Leaker $Revision: 1.2 $");
|
---|
50 | }
|
---|
51 |
|
---|
52 |
|
---|
53 | KernelLeakerApp::~KernelLeakerApp ()
|
---|
54 | {
|
---|
55 | }
|
---|
56 |
|
---|
57 |
|
---|
58 | void KernelLeakerApp::Pulse ()
|
---|
59 | {
|
---|
60 | status_t ErrorCode = B_OK;
|
---|
61 | BMessage ReplyMessage;
|
---|
62 | BMessage ScriptMessage;
|
---|
63 |
|
---|
64 | static const char *Signatures[] = { // Deskbar and Tracker.
|
---|
65 | "application/x-vnd.Be-TSKB",
|
---|
66 | "application/x-vnd.Be-TRAK",
|
---|
67 | "application/x-vnd.Be-TSKB",
|
---|
68 | "application/x-vnd.Be-TRAK",
|
---|
69 | "application/x-vnd.Be-TSKB",
|
---|
70 | "application/x-vnd.Be-TRAK",
|
---|
71 | "application/x-vnd.Be-TSKB",
|
---|
72 | "application/x-vnd.Be-TRAK",
|
---|
73 | "application/x-vnd.Be-TSKB",
|
---|
74 | "application/x-vnd.Be-TRAK",
|
---|
75 | NULL
|
---|
76 | };
|
---|
77 |
|
---|
78 | int iSig;
|
---|
79 | for (iSig = 0; Signatures[iSig] != NULL; iSig++)
|
---|
80 | {
|
---|
81 | ErrorCode = B_OK;
|
---|
82 | BMessenger MessengerToTarget(Signatures[iSig], -1, &ErrorCode);
|
---|
83 | if (ErrorCode != B_OK)
|
---|
84 | {
|
---|
85 | printf ("Failed to set target.\n");
|
---|
86 | return;
|
---|
87 | }
|
---|
88 |
|
---|
89 | // Send BMessages to various loopers in the target application.
|
---|
90 |
|
---|
91 | int i;
|
---|
92 | for (i = 0; i < 10; i++)
|
---|
93 | {
|
---|
94 | ScriptMessage.MakeEmpty ();
|
---|
95 | ScriptMessage.what = B_GET_PROPERTY;
|
---|
96 | ScriptMessage.AddSpecifier ("InternalName");
|
---|
97 | ScriptMessage.AddSpecifier ("Looper", (int32) i);
|
---|
98 | ReplyMessage.MakeEmpty ();
|
---|
99 | ErrorCode = MessengerToTarget.SendMessage (
|
---|
100 | &ScriptMessage, &ReplyMessage,
|
---|
101 | 100000 /* delivery timeout */, 100000 /* reply timeout */);
|
---|
102 | const char *NameString = NULL;
|
---|
103 | if (ErrorCode != B_OK || ReplyMessage.FindString ("result",
|
---|
104 | &NameString) != B_OK || NameString == NULL)
|
---|
105 | continue; // Ignore Loopers that don't exist or aren't scriptable.
|
---|
106 |
|
---|
107 | // printf ("Name %d: %s\n", i, NameString);
|
---|
108 | }
|
---|
109 | }
|
---|
110 | }
|
---|
111 |
|
---|
112 |
|
---|
113 | bool KernelLeakerApp::QuitRequested ()
|
---|
114 | {
|
---|
115 | return BApplication::QuitRequested ();
|
---|
116 | }
|
---|
117 |
|
---|
118 |
|
---|
119 | void KernelLeakerApp::ReadyToRun ()
|
---|
120 | {
|
---|
121 | // Turn on the periodic Pulse() callback, maximum speed is 1/10 of a second,
|
---|
122 | // though that's too fast (can't process quit messages).
|
---|
123 |
|
---|
124 | SetPulseRate (1500000);
|
---|
125 | }
|
---|
126 |
|
---|
127 |
|
---|
128 | /******************************************************************************
|
---|
129 | * Finally, the main program which drives it all.
|
---|
130 | */
|
---|
131 |
|
---|
132 | int main (int argc, char**)
|
---|
133 | {
|
---|
134 | KernelLeakerApp MyApp;
|
---|
135 |
|
---|
136 | if (MyApp.InitCheck () == 0)
|
---|
137 | {
|
---|
138 | MyApp.Run ();
|
---|
139 | }
|
---|
140 | printf ("Finished running the Kernel Leaker experiment.\n");
|
---|
141 | return 0;
|
---|
142 | }
|
---|
143 |
|
---|
144 |
|
---|
145 | /******************************************************************************
|
---|
146 | * $Log: KernelLeaker.cpp,v $
|
---|
147 | * Revision 1.2 2019/11/22 21:42:23 agmsmith
|
---|
148 | * Adapted for BeOS too (no BMessenger::SetTo() function).
|
---|
149 | *
|
---|
150 | * Revision 1.1 2019/11/22 21:34:59 agmsmith
|
---|
151 | * Initial revision
|
---|
152 | */
|
---|