Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 200251 | Differences between
and this patch

Collapse All | Expand All

(-)src-native/src/JPIAgent/ECWrapper.h (-3 / +4 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2005 - 2007 IBM Corporation, Intel Corporation.
2
 * Copyright (c) 2005 - 2008 IBM Corporation, Intel Corporation.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 32-39 Link Here
32
    ECWrapper(CPrint* pCPrint, CFilters* pCFilters, COptions* pCOptions);
32
    ECWrapper(CPrint* pCPrint, CFilters* pCFilters, COptions* pCOptions);
33
    ~ECWrapper(void);
33
    ~ECWrapper(void);
34
34
35
    void InitACCollector(CEC_Callbacks* callbacks);
35
    void InitACCollector();
36
36
	void RegisterMartiniCallbacks(CEC_Callbacks* callbacks);
37
	
37
//protected:
38
//protected:
38
    static CPrint* m_pCPrint;
39
    static CPrint* m_pCPrint;
39
    static CFilters* m_pCFilters;
40
    static CFilters* m_pCFilters;
(-)src-native/src/JPIAgent/ECWrapper.cpp (-52 / +125 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2005 - 2007 IBM Corporation, Intel Corporation.
2
 * Copyright (c) 2005 - 2008 IBM Corporation, Intel Corporation.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 47-114 Link Here
47
47
48
//=== ACC_ENV ===============================================================================================
48
//=== ACC_ENV ===============================================================================================
49
49
50
static boolean ACTracingStarted = false;
51
static boolean appTracingStarted = false;
52
static boolean tracingStarted = false;
53
static boolean printingStarted = false;
54
55
static void startTracing();
56
static void start();
57
static void stopTracing();
58
static void stop();
59
60
extern "C" int isApplicationMode() {
61
	return (ECWrapper::m_pCOptions != NULL) &&	ECWrapper::m_pCOptions->isApplicationMode();
62
}
63
64
API_EXPORT void ACC_CALL ACStartTracing() {
65
    LOG_TRACE("ACStartTracing command!");
66
	if (ACTracingStarted) return;
67
	
68
	ACTracingStarted = true;
69
	startTracing();
70
}
71
72
extern "C" void appStartTracing() {
73
    LOG_TRACE("appStartTracing command!");
74
	if (appTracingStarted) return;
75
	
76
	appTracingStarted = true;
77
	startTracing();
78
}
79
50
/** START_TRACING  *************************************************************
80
/** START_TRACING  *************************************************************
51
* This is the entry point which must be called to start a trace. It takes
81
* This is the entry point which must be called to start a trace. It takes
52
* care of emitting all the header information.
82
* care of emitting all the header information.
53
*/
83
*/
54
API_EXPORT void ACC_CALL 
84
static void startTracing() {
55
StartTracing() 
85
	if (tracingStarted) return;
56
{
86
	
57
    LOG_TRACE("StartTracing command!");
87
	boolean applicationMode = false;
58
    LOG_ASSERT(ECWrapper::m_pCPrint != 0);
88
	boolean standaloneMode = false;
59
    ECWrapper::m_pCPrint->m_jvmtiAgent_suspendIO = false;
89
	
60
    ECWrapper::m_pCPrint->PrintStartingFragments();
90
	if (ECWrapper::m_pCOptions != NULL) {
61
}
91
		applicationMode = ECWrapper::m_pCOptions->isApplicationMode();
62
92
		standaloneMode = ECWrapper::m_pCOptions->isStandAlone(); 
63
/** STOP_TRACING  **************************************************************
93
	}
64
* This is where a trace is stopped.
94
	
65
*/
95
	boolean toTrace = (standaloneMode || ACTracingStarted) && (appTracingStarted || !applicationMode);
66
API_EXPORT void ACC_CALL 
96
67
StopTracing() 
97
	if (!toTrace) return;
68
{
98
	
69
    LOG_TRACE("StopTracing command!");
99
	start();
70
    LOG_ASSERT(ECWrapper::m_pCPrint != 0);
100
	tracingStarted = true;
71
    LOG_ASSERT(ECWrapper::m_pCOptions != 0);
72
    ECWrapper::m_pCPrint->printTraceEndElement();
73
    ECWrapper::m_pCPrint->m_jvmtiAgent_suspendIO = true;
74
}
101
}
75
102
76
API_EXPORT void ACC_CALL 
103
static void start() {
77
Start()
78
{
79
    LOG_TRACE("Start command!");
104
    LOG_TRACE("Start command!");
105
106
   	LOG_ASSERT(ECWrapper::m_pCPrint != 0);
107
   	ECWrapper::m_pCPrint->m_jvmtiAgent_suspendIO = false;
108
109
	if (!printingStarted) {
110
    	ECWrapper::m_pCPrint->PrintStartingFragments();
111
		printingStarted = true;
112
	}
113
	
80
    LOG_ASSERT(ECWrapper::m_pCallbacks != 0);
114
    LOG_ASSERT(ECWrapper::m_pCallbacks != 0);
115
81
    ECWrapper::m_pCallbacks->Start();
116
    ECWrapper::m_pCallbacks->Start();
82
}
117
}
83
118
84
API_EXPORT void ACC_CALL 
119
API_EXPORT void ACC_CALL ACStopTracing() {
85
Stop()
120
    LOG_TRACE("ACStop command!");
86
{
121
    if (!ACTracingStarted) return;
87
    LOG_TRACE("Stop command!");
122
    
88
    LOG_ASSERT(ECWrapper::m_pCallbacks != 0);
123
    ACTracingStarted = false;
89
    ECWrapper::m_pCallbacks->Stop();
124
    stopTracing();
90
}
125
}
91
126
92
API_EXPORT void ACC_CALL
127
extern "C" void appStopTracing() {
93
Resume()
128
    LOG_TRACE("appStop command!");
94
{
129
    if (!appTracingStarted) return;
95
    LOG_TRACE("Resume command!");
130
    
96
    LOG_ASSERT(ECWrapper::m_pCallbacks != 0);
131
    appTracingStarted = false;
97
    LOG_ASSERT(ECWrapper::m_pCPrint != 0);
132
    stopTracing();
98
    ECWrapper::m_pCPrint->m_jvmtiAgent_suspendIO = false;
99
    ECWrapper::m_pCallbacks->Start();
100
}
133
}
101
134
102
API_EXPORT void ACC_CALL
135
/** STOP_TRACING  **************************************************************
103
Pause()
136
* This is where a trace is stopped.
104
{
137
*/
105
    LOG_TRACE("Pause command!");
138
static void stopTracing() {
139
	if (!tracingStarted) return;
140
141
	boolean applicationMode = false;
142
	boolean standaloneMode = false;
143
	
144
	if (ECWrapper::m_pCOptions != NULL) {
145
		applicationMode = ECWrapper::m_pCOptions->isApplicationMode();
146
		standaloneMode = ECWrapper::m_pCOptions->isStandAlone(); 
147
	}
148
	
149
	boolean toTrace = (standaloneMode || ACTracingStarted) && (appTracingStarted || !applicationMode);
150
	if (toTrace) return;
151
	
152
	tracingStarted = false;
153
	stop();
154
}
155
156
static void stop() {
157
    LOG_TRACE("Stop command!");
158
	    
106
    LOG_ASSERT(ECWrapper::m_pCallbacks != 0);
159
    LOG_ASSERT(ECWrapper::m_pCallbacks != 0);
107
    LOG_ASSERT(ECWrapper::m_pCPrint != 0);
108
    ECWrapper::m_pCallbacks->Stop();
160
    ECWrapper::m_pCallbacks->Stop();
161
   	LOG_ASSERT(ECWrapper::m_pCPrint != 0);
109
    ECWrapper::m_pCPrint->m_jvmtiAgent_suspendIO = true;
162
    ECWrapper::m_pCPrint->m_jvmtiAgent_suspendIO = true;
110
}
163
}
111
164
165
extern "C" void printCustomElement(const char* str) {
166
    LOG_ASSERT(ECWrapper::m_pCPrint != 0);
167
    ECWrapper::m_pCPrint->printCustomElement(str);
168
}
169
112
API_EXPORT void ACC_CALL
170
API_EXPORT void ACC_CALL
113
Attach()
171
Attach()
114
{
172
{
Lines 123-128 Link Here
123
    LOG_TRACE("Detach command!");
181
    LOG_TRACE("Detach command!");
124
    LOG_ASSERT(ECWrapper::m_pCallbacks != 0);
182
    LOG_ASSERT(ECWrapper::m_pCallbacks != 0);
125
    ECWrapper::m_pCallbacks->Detach();
183
    ECWrapper::m_pCallbacks->Detach();
184
185
   	LOG_ASSERT(ECWrapper::m_pCPrint != 0);
186
    
187
	if (printingStarted) {
188
    	ECWrapper::m_pCPrint->printTraceEndElement();
189
		printingStarted = false;
190
    }
191
192
    ECWrapper::m_pCPrint->m_jvmtiAgent_suspendIO = true;
126
}
193
}
127
194
128
API_EXPORT void ACC_CALL
195
API_EXPORT void ACC_CALL
Lines 164-170 Link Here
164
{
231
{
165
    LOG_TRACE("RunGC command!");
232
    LOG_TRACE("RunGC command!");
166
    LOG_ASSERT(ECWrapper::m_pCallbacks != 0);
233
    LOG_ASSERT(ECWrapper::m_pCallbacks != 0);
167
    ECWrapper::m_pCallbacks->CustomCommand(RUN_GC_COMMAND, 0);
234
    if (ECWrapper::m_pCallbacks != NULL) {
235
    	ECWrapper::m_pCallbacks->CustomCommand(RUN_GC_COMMAND, 0);
236
    }
237
}
238
239
extern "C" void runGC() {
240
	RunGC();
168
}
241
}
169
242
170
API_EXPORT void ACC_CALL
243
API_EXPORT void ACC_CALL
Lines 201-212 Link Here
201
ECWrapper::PrepareACCEnv() 
274
ECWrapper::PrepareACCEnv() 
202
{
275
{
203
    static ACCFunctions_ functions;
276
    static ACCFunctions_ functions;
204
    functions.StartTracing = &StartTracing;
277
    functions.StartTracing = &ACStartTracing;
205
    functions.StopTracing = &StopTracing;
278
    functions.StopTracing = &ACStopTracing;
206
    functions.Start = &Start;
279
207
    functions.Stop = &Stop;
208
    functions.Pause = &Pause;
209
    functions.Resume = &Resume;
210
    functions.Detach = &Detach;
280
    functions.Detach = &Detach;
211
    functions.Attach = &Attach;
281
    functions.Attach = &Attach;
212
    functions.AddFilter = &AddFilter;
282
    functions.AddFilter = &AddFilter;
Lines 223-232 Link Here
223
    return &ac_env;
293
    return &ac_env;
224
}
294
}
225
295
296
void ECWrapper::RegisterMartiniCallbacks(CEC_Callbacks* callbacks) {
297
    m_pCallbacks = callbacks;
298
}
299
226
void 
300
void 
227
ECWrapper::InitACCollector(CEC_Callbacks* callbacks)
301
ECWrapper::InitACCollector()
228
{
302
{
229
    m_pCallbacks = callbacks;
230
    ACC_ENV* ac_env = PrepareACCEnv();
303
    ACC_ENV* ac_env = PrepareACCEnv();
231
304
232
    Martini::OSA::ILibraryLoader* libraryLoader;
305
    Martini::OSA::ILibraryLoader* libraryLoader;
(-)src-native/src/JPIAgent/ECJvmtiAgent.cpp (-4 / +13 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2005 - 2007 IBM Corporation, Intel Corporation.
2
 * Copyright (c) 2005 - 2008 IBM Corporation, Intel Corporation.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 74-84 Link Here
74
    bool static isInitACCollectorInvoked = false;
74
    bool static isInitACCollectorInvoked = false;
75
    int res = m_Callbacks.RegisterMartiniCallback_(command, callback);
75
    int res = m_Callbacks.RegisterMartiniCallback_(command, callback);
76
    if (res == 1) {
76
    if (res == 1) {
77
        if ((command == CMD_START) && m_Options.isStandAlone()) {
77
        if ((command == CMD_START) && m_Options.isStandAlone() && !m_Options.isApplicationMode()) {
78
            m_Print.m_jvmtiAgent_suspendIO = false; 
79
        	m_Print.PrintStartingFragments();
80
        
78
            m_Callbacks.Start();
81
            m_Callbacks.Start();
79
        }
82
        }
80
        if (!isInitACCollectorInvoked && m_Callbacks.ProfCallbacksAvailable() && !m_Options.isStandAlone()) {
83
        
81
            m_ECWrapper.InitACCollector(&m_Callbacks);
84
        if (!isInitACCollectorInvoked && m_Callbacks.ProfCallbacksAvailable()) {
85
            m_ECWrapper.RegisterMartiniCallbacks(&m_Callbacks);
86
 			
87
 			if (!m_Options.isStandAlone()) {
88
            	m_ECWrapper.InitACCollector();
89
            }
90
            
82
            isInitACCollectorInvoked = true;
91
            isInitACCollectorInvoked = true;
83
        }
92
        }
84
    }
93
    }
(-)src-native/src/JPIAgent/Options.cpp (-112 / +86 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2005 - 2007 IBM Corporation, Intel Corporation.
2
 * Copyright (c) 2005 - 2008 IBM Corporation, Intel Corporation.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 57-63 Link Here
57
{
57
{
58
         1                         /* Provide timestamps by default */
58
         1                         /* Provide timestamps by default */
59
        ,0                         /* Standalone mode */
59
        ,0                         /* Standalone mode */
60
//        ,0                         /* Application mode */
60
        ,0                         /* Application mode */
61
        ,1                         /* Enabled mode */
61
        ,1                         /* Enabled mode */
62
        ,1                         /* Filters */
62
        ,1                         /* Filters */
63
        ,1                         /* Options */
63
        ,1                         /* Options */
Lines 115-140 Link Here
115
    strcpy(m_jvmtiAgent_Options.workDir, DEFAULT_WORK_DIR); 
115
    strcpy(m_jvmtiAgent_Options.workDir, DEFAULT_WORK_DIR); 
116
}
116
}
117
117
118
int 
119
COptions::getToken(const char **src, char *buf, int buflen, char sep)
120
{
121
    int i;
122
    const char *p = *src;
123
    for (i = 0; i < buflen; i++) {
124
        if (p[i] == 0 || p[i] == sep) {
125
            buf[i] = 0;
126
            if (p[i] == sep) {
127
                i++;
128
            }
129
            *src += i;
130
            return i;
131
        }
132
        buf[i] = p[i];
133
    }
134
    /* overflow */
135
    return 0;
136
}
137
138
/** PRINT_USAGE **********************************************************************
118
/** PRINT_USAGE **********************************************************************
139
* Print the command line useage of the program.
119
* Print the command line useage of the program.
140
*/
120
*/
Lines 155-160 Link Here
155
        "\n"
135
        "\n"
156
        "Supported option names and values:\n"
136
        "Supported option names and values:\n"
157
        "  server=standalone|enabled|controlled\n" 
137
        "  server=standalone|enabled|controlled\n" 
138
        "  api=true|false\tProfiler API (default is false)\n" 
158
        "  file=<file>\t\tOutput file (default is %s)\n"
139
        "  file=<file>\t\tOutput file (default is %s)\n"
159
        "  \t\t\tOnly applicable when server=standalone\n"
140
        "  \t\t\tOnly applicable when server=standalone\n"
160
        "  filters=<file>\tFilter definition file (default is %s)\n"
141
        "  filters=<file>\tFilter definition file (default is %s)\n"
Lines 434-563 Link Here
434
    return rc;
415
    return rc;
435
}
416
}
436
417
437
/** PROCESS_INVOCATION_OPTIONS *******************************************
418
int COptions::parseOptions(char* buf) {
438
* Takes the command line parameters and populates the m_jvmtiAgent_Options
419
	int outputSpecified = 0;
439
* with the correct values based upon the options specified.
440
* @param   optionString - the command line args
441
* @returns
442
*/
443
444
int
445
COptions::ProcessInvocationOptions(const char *str)
446
{
447
    char *buf = 0; 
448
    int buflen; 
449
    int outputSpecified = 0;
450
    if (str == 0) str = "";
451
420
452
    /* if "help" is specified print out the useage */
421
	char* pnext = buf;
453
    if ((STRICOLL(str, "help")) == 0) {
422
    while (pnext) {
454
        return -1;
423
    	char* pname = pnext;	// current tag
455
    }
424
    	
456
425
    	pnext = strchr(pnext, ',');
457
    while (*str) {
426
    	if (pnext != NULL) {
458
        buflen= strlen(str)+1; 
427
    		*pnext++ = '\0';	// next tag
459
        buf = (char *)malloc(buflen); 
428
    	}
460
        if (!buf) {
429
    	
461
            goto mem_error; 
430
    	char* pvalue = strchr(pname, '=');
462
        }
431
    	if (pvalue != NULL) {
432
    		*pvalue++ = '\0';
433
    	}
463
434
464
        /* All options contain an "=" */
465
        if (!getToken(&str, buf, buflen, '=')) {
466
            goto bad_option;
467
        }
468
        /* Specied output file */
435
        /* Specied output file */
469
        if (STRICOLL(buf, "file") == 0) {
436
        if (STRICOLL(pname, "file") == 0) {
470
            if (outputSpecified || !getToken(&str, buf, buflen, ',')) {
437
            if (outputSpecified || pvalue == NULL) return -1;
471
                goto bad_option;
438
            
472
            }
439
            strcpyrealloc(&m_jvmtiAgent_Options.outputFileName, pvalue);
473
            strcpyrealloc(&m_jvmtiAgent_Options.outputFileName, buf);
474
            outputSpecified = 1;
440
            outputSpecified = 1;
475
        } else if (STRICOLL(buf, "filters") == 0) {
441
        } else if (STRICOLL(pname, "filters") == 0) {
476
            if (!getToken(&str, buf, buflen, ',')) {
442
            if (pvalue == NULL) return -1;
477
                goto bad_option;
443
            
478
            }
444
            strcpyrealloc(&m_jvmtiAgent_Options.filterFileName, pvalue);
479
            strcpyrealloc(&m_jvmtiAgent_Options.filterFileName,buf);
480
//        } else if (STRICOLL(buf, "debug") == 0) {
481
//            if (!getToken(&str, buf, buflen, ',')) {
482
//                goto bad_option;
483
//            } else {
484
//                goto bad_option;
485
//            }
486
        }
445
        }
487
        /* Mode of operation */
446
        /* Mode of operation */
488
        else if (STRICOLL(buf, "server") == 0) {
447
        else if (STRICOLL(pname, "server") == 0) {
489
            if (!getToken(&str, buf, buflen, ',')) {
448
            if (pvalue == NULL) return -1; 
490
                goto bad_option;
449
491
            }
492
            /* If standalone */
450
            /* If standalone */
493
            if (STRICOLL(buf,"standalone") == 0) {
451
            if (STRICOLL(pvalue,"standalone") == 0) {
494
                m_jvmtiAgent_Options.standalone = 1;
452
                m_jvmtiAgent_Options.standalone = 1;
495
                m_jvmtiAgent_Options.enabled = 0;
453
                m_jvmtiAgent_Options.enabled = 0;
496
            }
454
            }
497
            /* If enabled */
455
            /* If enabled */
498
            else if (STRICOLL(buf, "enabled") == 0) {
456
            else if (STRICOLL(pvalue, "enabled") == 0) {
499
                m_jvmtiAgent_Options.standalone = 0;
457
                m_jvmtiAgent_Options.standalone = 0;
500
                m_jvmtiAgent_Options.enabled = 1;
458
                m_jvmtiAgent_Options.enabled = 1;
501
            }
459
            }
502
            /* If controlled */
460
            /* If controlled */
503
            else if (STRICOLL(buf, "controlled") == 0) {
461
            else if (STRICOLL(pvalue, "controlled") == 0) {
504
                m_jvmtiAgent_Options.standalone = 0;
462
                m_jvmtiAgent_Options.standalone = 0;
505
                m_jvmtiAgent_Options.enabled = 0;
463
                m_jvmtiAgent_Options.enabled = 0;
506
            } else {
464
            } else {
507
                goto bad_option;
465
                return -1;
508
            }
466
            }
509
        } else if (STRICOLL(buf, "workDir") == 0) {
467
        } else if (STRICOLL(pname, "api") == 0) {
510
            if (!getToken(&str, buf, buflen, ',')) {
468
            if (pvalue == NULL) return -1; 
511
                goto bad_option;
469
        
470
            if (STRICOLL(pvalue, "true") == 0) {
471
            	m_jvmtiAgent_Options.application = 1;
512
            }
472
            }
513
            strcpyrealloc(&m_jvmtiAgent_Options.workDir, buf);
473
        } else if (STRICOLL(pname, "workDir") == 0) {
474
            if (pvalue == NULL) return -1;
475
476
            strcpyrealloc(&m_jvmtiAgent_Options.workDir, pvalue);
514
477
515
            /* create the directory */
478
            /* create the directory */
516
            if (MKDIR(m_jvmtiAgent_Options.workDir) != 0 && errno != EEXIST) {
479
            if (MKDIR(m_jvmtiAgent_Options.workDir) != 0 && errno != EEXIST) {
517
                /* couldn't create the dir and it doesn't exists either */
480
                /* couldn't create the dir and it doesn't exists either */
518
                perror(m_jvmtiAgent_Options.workDir);
481
                perror(m_jvmtiAgent_Options.workDir);
519
                goto bad_option;
482
                return -1;
520
            }
483
            }
521
484
522
            /* end of workDir */
485
            /* end of workDir */
523
        } else if (STRICOLL(buf, "profile") == 0) {
486
        } else if (STRICOLL(pname, "profile") == 0) {
524
            m_jvmtiAgent_Options.profileFile;
487
            m_jvmtiAgent_Options.profileFile;
525
            if (!getToken(&str, buf, buflen, ',')) {
488
            if (pvalue == NULL) return -1;
526
                goto bad_option;
489
527
            }
490
            strcpyrealloc(&m_jvmtiAgent_Options.profileFile, pvalue);
528
            strcpyrealloc(&m_jvmtiAgent_Options.profileFile, buf);
529
        } else {
491
        } else {
530
            char *buf2 = (char *)malloc(buflen); 
492
            if (pvalue == NULL) return -1;
531
            if (!getToken(&str, buf2, buflen, ',')) {
493
            SetProfileOption(pname, pvalue);
532
                free(buf2); 
533
                return -1;
534
            }
535
            SetProfileOption(buf, buf2);
536
            free(buf2); 
537
        }
494
        }
538
//        } else {
495
	}
539
//            /* unknown option */
496
	
540
//            fprintf(stderr, "Unknown option \"%s\"\n", buf);
497
	return 0;
541
//            fflush(stderr); 
498
}
542
//            goto bad_option;
499
543
//        }
500
/** PROCESS_INVOCATION_OPTIONS *******************************************
544
    }
501
* Takes the command line parameters and populates the m_jvmtiAgent_Options
545
    if (buf) {
502
* with the correct values based upon the options specified.
546
        free (buf); 
503
* @param   optionString - the command line args
504
* @returns
505
*/
506
507
int COptions::ProcessInvocationOptions(const char *str) {
508
    char* buf;
509
510
    if (str == NULL) return 0;
511
512
    /* if "help" is specified print out the useage */
513
    if ((STRICOLL(str, "help")) == 0) {
514
        return -1;
547
    }
515
    }
548
    return 0;
549
516
550
bad_option:
517
	buf = (char*) malloc(strlen(str) + 1);
551
    if (buf) {
518
	if (buf == NULL) {
552
        free(buf); 
519
    	fprintf(stderr, "Memory allocation error\n"); 
520
    	fflush(stderr);
521
    	return -1;
522
    } 
523
524
	strcpy(buf, str);
525
	 
526
    int r = parseOptions(buf);
527
    free(buf);
528
    
529
    if (r < 0) {
530
    	fprintf(stderr, "Illegal TIAgent option\n");
531
    	fflush(stderr);
553
    }
532
    }
554
    fprintf(stderr, "Bad TIAgent option\n");
533
    
555
    fflush(stderr); 
534
    return r;
556
    return -1;
557
mem_error:
558
    fprintf(stderr, "Memory allocation error\n"); 
559
    fflush(stderr); 
560
    return -1; 
561
}
535
}
562
536
563
/** CHECK_OPTIONS_CONSISTENCY ********************************************
537
/** CHECK_OPTIONS_CONSISTENCY ********************************************
(-)src-native/src/JPIAgent/Options.h (-3 / +7 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2005 - 2007 IBM Corporation, Intel Corporation.
2
 * Copyright (c) 2005 - 2008 IBM Corporation, Intel Corporation.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 36-42 Link Here
36
    typedef struct {
36
    typedef struct {
37
        unsigned int timestamp:1;                  /* Provide timestamps on all events (TRUE) */
37
        unsigned int timestamp:1;                  /* Provide timestamps on all events (TRUE) */
38
        unsigned int standalone:1;                 /* Standalone mode  (FALSE) */
38
        unsigned int standalone:1;                 /* Standalone mode  (FALSE) */
39
//        unsigned int application:1;                /* Application mode (FALSE) */
39
        unsigned int application:1;                /* Application mode (FALSE) */
40
        unsigned int enabled:1;                    /* Enabled mode  ie. attachable (TRUE)  */
40
        unsigned int enabled:1;                    /* Enabled mode  ie. attachable (TRUE)  */
41
        unsigned int filters:1;                    /* Print FILTER Elements (TRUE) */
41
        unsigned int filters:1;                    /* Print FILTER Elements (TRUE) */
42
        unsigned int options:1;                    /* Print OPTIONS Elements (TRUE) */
42
        unsigned int options:1;                    /* Print OPTIONS Elements (TRUE) */
Lines 126-131 Link Here
126
            return (m_jvmtiAgent_Options.enabled == 1) ;
126
            return (m_jvmtiAgent_Options.enabled == 1) ;
127
        }
127
        }
128
128
129
        bool isApplicationMode() {
130
            return (m_jvmtiAgent_Options.application == 1);
131
        }
132
129
        // is CG pfofiler aggregated
133
        // is CG pfofiler aggregated
130
        bool isCGExecDetails() {
134
        bool isCGExecDetails() {
131
            return (!isEnabled()) && (m_jvmtiAgent_Options.cgExecDetails == 1); //in enabled mode we support aggregated cg profiler only
135
            return (!isEnabled()) && (m_jvmtiAgent_Options.cgExecDetails == 1); //in enabled mode we support aggregated cg profiler only
Lines 154-160 Link Here
154
        ***/ 
158
        ***/ 
155
        void addUnknownOption(char *key, char *value);
159
        void addUnknownOption(char *key, char *value);
156
160
157
        int getToken(const char **src, char *buf, int buflen, char sep);
161
		int parseOptions(char* buf);
158
162
159
        /* Get the absolute directory path for the optheap working dir*/
163
        /* Get the absolute directory path for the optheap working dir*/
160
        void getWorkDir(char* buf);
164
        void getWorkDir(char* buf);
(-).classpath (+1 lines)
Lines 1-6 Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
1
<?xml version="1.0" encoding="UTF-8"?>
2
<classpath>
2
<classpath>
3
	<classpathentry kind="src" path="src.config"/>
3
	<classpathentry kind="src" path="src.config"/>
4
	<classpathentry kind="src" path="src"/>
4
	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
5
	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
5
	<classpathentry combineaccessrules="false" kind="src" path="/org.eclipse.tptp.platform.agentcontroller"/>
6
	<classpathentry combineaccessrules="false" kind="src" path="/org.eclipse.tptp.platform.agentcontroller"/>
6
	<classpathentry kind="output" path="bin"/>
7
	<classpathentry kind="output" path="bin"/>
(-)src-native/src/ACCollector/ACCollector.cpp (-18 / +8 lines)
Lines 1-5 Link Here
1
/************************************************************************
1
/************************************************************************
2
 * Copyright (c) 2005, 2007 Intel Corporation.
2
 * Copyright (c) 2005, 2008 Intel Corporation.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 135-151 Link Here
135
    }
135
    }
136
136
137
    if (m_isEnabledDataCollection) {
137
    if (m_isEnabledDataCollection) {
138
        m_ACC_env->StartTracing();
139
        m_ACC_env->Attach(); 
138
        m_ACC_env->Attach(); 
140
        m_isWaiting = false;
139
        m_isWaiting = false;
141
        m_ACC_env->Start();
140
        m_ACC_env->StartTracing();
142
        m_isTracing = true;
141
        m_isTracing = true;
143
    }
142
    }
144
    else {
143
    else {
145
        m_ACC_env->Attach(); 
144
        m_ACC_env->Attach(); 
146
        m_isWaiting = false;
145
        m_isWaiting = false;
147
        m_isTracing = true;
146
        m_isTracing  = true;
148
        m_isFirstAfterStart = true;
149
    }
147
    }
150
//    if (m_ACC_env->IsAgentInitialized()) {
148
//    if (m_ACC_env->IsAgentInitialized()) {
151
//        SendVMAgentInitializedCommand();
149
//        SendVMAgentInitializedCommand();
Lines 163-169 Link Here
163
    if (!isAgentInitialized(cmdBlock->getContextID())) {
161
    if (!isAgentInitialized(cmdBlock->getContextID())) {
164
        return 0;
162
        return 0;
165
    }
163
    }
166
    m_ACC_env->Stop();
167
    m_ACC_env->Detach();
164
    m_ACC_env->Detach();
168
    m_ACC_env->StopTracing();
165
    m_ACC_env->StopTracing();
169
    m_isTracing = false;
166
    m_isTracing = false;
Lines 178-194 Link Here
178
        return 0;
175
        return 0;
179
    }
176
    }
180
177
181
178
    m_ACC_env->StartTracing(); 
182
    if (m_isFirstAfterStart && !m_isEnabledDataCollection) {
183
        m_ACC_env->StartTracing();
184
//        m_ACC_env->Start();
185
        m_ACC_env->Resume();
186
        m_isFirstAfterStart = false;
187
    }
188
    else {
189
        m_ACC_env->Resume();
190
    }
191
192
179
193
    return BaseCollectorImpl::resume(cmdBlock);
180
    return BaseCollectorImpl::resume(cmdBlock);
194
}
181
}
Lines 203-209 Link Here
203
    if (!isAgentInitialized(cmdBlock->getContextID())) {
190
    if (!isAgentInitialized(cmdBlock->getContextID())) {
204
        return 0;
191
        return 0;
205
    }
192
    }
206
    m_ACC_env->Pause();
193
194
    m_ACC_env->StopTracing();
207
    return BaseCollectorImpl::pause(cmdBlock);
195
    return BaseCollectorImpl::pause(cmdBlock);
208
}
196
}
209
197
Lines 369-379 Link Here
369
    this->processCommandLine(0, cargv);
357
    this->processCommandLine(0, cargv);
370
    
358
    
371
    this->registerAgent();
359
    this->registerAgent();
360
372
    if (isControlled) {
361
    if (isControlled) {
373
        while(m_isWaiting) {
362
        while(m_isWaiting) {
374
            Sleep(100);
363
            Sleep(100);
375
        };
364
        };
376
    }
365
    }
366
377
    return 0;
367
    return 0;
378
}
368
}
379
369
(-)src-native/include/JPIAgent/ACC_Env.h (-21 / +1 lines)
Lines 1-5 Link Here
1
/************************************************************************
1
/************************************************************************
2
 * Copyright (c) 2005 - 2007 Intel Corporation.
2
 * Copyright (c) 2005 - 2008 Intel Corporation.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 38-47 Link Here
38
struct ACCFunctions_ {
38
struct ACCFunctions_ {
39
    void (ACC_CALL *StartTracing)();
39
    void (ACC_CALL *StartTracing)();
40
    void (ACC_CALL *StopTracing)();
40
    void (ACC_CALL *StopTracing)();
41
    void (ACC_CALL *Start)();
42
    void (ACC_CALL *Stop)();
43
    void (ACC_CALL *Pause)();
44
    void (ACC_CALL *Resume)();
45
    void (ACC_CALL *Detach)();
41
    void (ACC_CALL *Detach)();
46
    void (ACC_CALL *Attach)();
42
    void (ACC_CALL *Attach)();
47
    void (ACC_CALL *AddFilter)(char *iid, char *classPattern, char *methodPattern, char *filterMode);//strcmp("INCLUDE", mode) == 0 ? INCLUDE : EXCLUDE
43
    void (ACC_CALL *AddFilter)(char *iid, char *classPattern, char *methodPattern, char *filterMode);//strcmp("INCLUDE", mode) == 0 ? INCLUDE : EXCLUDE
Lines 66-87 Link Here
66
        functions->StopTracing();
62
        functions->StopTracing();
67
    }
63
    }
68
64
69
    void Start() {
70
        functions->Start();
71
    }
72
73
    void Stop() {
74
        functions->Stop();
75
    }
76
77
    void Pause() {
78
        functions->Pause();
79
    }
80
81
    void Resume() {
82
        functions->Resume();
83
    }
84
85
    void Detach() {
65
    void Detach() {
86
        functions->Detach();
66
        functions->Detach();
87
    }
67
    }
(-)src-native/src/JPIAgent/Profiler.c (+73 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Intel Corporation.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * $Id: Profiler.c,v 1.0 2008/01/21 21:32:13 ialelekov Exp $ 
9
 ***********************************************************************/
10
11
#include "Profiler.h"
12
13
extern void appStartTracing();		// defined in ECWrapper.cpp
14
extern void appStopTracing();
15
extern int isApplicationMode();
16
extern int runGC();
17
extern void printCustomElement(const char* str);
18
19
JNIEXPORT jint JNICALL Java_org_eclipse_tptp_profiler_Profiler_initialize0
20
  (JNIEnv *env, jobject thisObj) {
21
  
22
  	return isApplicationMode() ? 0 : -1;
23
  }
24
25
/*
26
 * Class:     org_eclipse_tptp_profiler_Profiler
27
 * Method:    startProfiling0
28
 * Signature: ()I
29
 */
30
JNIEXPORT jint JNICALL Java_org_eclipse_tptp_profiler_Profiler_startProfiling0
31
  (JNIEnv *env, jobject thisObj) {
32
33
  	appStartTracing();
34
  
35
  	return 0;
36
  }
37
38
/*
39
 * Class:     org_eclipse_tptp_profiler_Profiler
40
 * Method:    stopProfiling0
41
 * Signature: ()I
42
 */
43
JNIEXPORT jint JNICALL Java_org_eclipse_tptp_profiler_Profiler_stopProfiling0
44
  (JNIEnv *env, jobject thisObj) {
45
46
	if (!isApplicationMode()) return -1;
47
  	
48
	appStopTracing();
49
  
50
  	return 0;
51
  }
52
  
53
/*
54
 * Class:     org_eclipse_tptp_profiler_Profiler
55
 * Method:    runGC0
56
 * Signature: ()I
57
 */
58
JNIEXPORT jint JNICALL Java_org_eclipse_tptp_profiler_Profiler_runGC0
59
  (JNIEnv *env, jobject thisObj) {
60
61
	runGC();
62
  
63
  	return 0;
64
  }
65
   
66
 JNIEXPORT void JNICALL Java_org_eclipse_tptp_profiler_Profiler_emitXMLFragment0
67
  (JNIEnv *env, jobject thisObj, jstring xmlFragment) {
68
 
69
 	const char *native = (*env)->GetStringUTFChars(env, xmlFragment, NULL);
70
 	printCustomElement(native);
71
	(*env)->ReleaseStringUTFChars(env, xmlFragment, native);
72
 }
73
 
(-)src/org/eclipse/tptp/profiler/Profiler.java (+95 lines)
Added Link Here
1
package org.eclipse.tptp.profiler;
2
3
public class Profiler {
4
	private final static String AGENT_NAME = "JPIAgent";
5
	private static Profiler instance = null;
6
	private static boolean nativesAvailable = false;
7
8
	private boolean isProfiling = false;
9
	private boolean isActive = false;
10
11
	static {
12
		try {
13
			System.loadLibrary(AGENT_NAME);
14
			nativesAvailable = true;
15
		}
16
		catch(Throwable e) {}
17
	}
18
	
19
	/**
20
	 * Native delegate to startup the profiler.  Checks to see if profiling is possible.
21
	 */
22
	 private native int initialize0();
23
24
	 private Profiler() {
25
		isActive = initialize0() == 0;
26
	}
27
	
28
	public static Profiler getProfiler() throws ProfilerNotAvailableException {
29
		if (!nativesAvailable) throw new ProfilerNotAvailableException();
30
		
31
		if (instance == null) instance = new Profiler();
32
		
33
		if (!instance.isActive) throw new ProfilerAPINotAvailableException();
34
		
35
		return instance;
36
	}
37
38
	/**
39
	 * Native delegate of startProfiling().
40
	 * @returns  0 - the profile session was created successfuly.
41
	 *
42
	 */
43
	private native int startProfiling0();
44
	
45
	public boolean startProfiling() throws ProfilerNotAvailableException {
46
		if (!isActive) throw new ProfilerAPINotAvailableException();
47
48
		synchronized(this) {
49
			if (!isProfiling) {
50
				isProfiling = startProfiling0() == 0;
51
			}
52
		}
53
		
54
		return isProfiling;
55
	}
56
	
57
	/**
58
	 * Native delgate to stopProfiling.
59
	 */
60
	private native int stopProfiling0();
61
	
62
	public boolean stopProfiling() throws ProfilerNotAvailableException {
63
		if (!isActive) throw new ProfilerAPINotAvailableException();
64
65
		synchronized(this) {
66
			if (isProfiling) {
67
				isProfiling = !(stopProfiling0() == 0);
68
			}
69
		}
70
		
71
		return !isProfiling;
72
	}
73
	
74
	/**
75
	 * Native delgate to runGC.
76
	 */
77
	private native int runGC0();
78
	
79
	public void runGC() throws ProfilerNotAvailableException {
80
		if (!isActive) throw new ProfilerAPINotAvailableException();
81
82
		runGC0();
83
	}
84
	
85
	/**
86
	 * Native delgate to emitXMLFragment.
87
	 */
88
	private native void emitXMLFragment0(String xmlFragment);
89
	
90
	public void emitXMLFragment(String xmlFragment) throws ProfilerNotAvailableException {
91
		if (!isActive) throw new ProfilerAPINotAvailableException();
92
93
		emitXMLFragment0(xmlFragment);
94
	}
95
}
(-)src/org/eclipse/tptp/profiler/ProfilerNotAvailableException.java (+5 lines)
Added Link Here
1
package org.eclipse.tptp.profiler;
2
3
public class ProfilerNotAvailableException extends Exception {
4
	private static final long serialVersionUID = 1L;
5
}
(-)src-native/src/JPIAgent/Profiler.h (+63 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Intel Corporation.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * $Id: Profiler.h,v 1.0 2008/01/21 21:32:13 ialelekov Exp $ 
9
 ***********************************************************************/
10
 
11
/* DO NOT EDIT THIS FILE - it is machine generated */
12
#include <jni.h>
13
/* Header for class org_eclipse_tptp_platform_jvmti_runtime_profiler_Profiler */
14
15
#ifndef _Included_org_eclipse_tptp_profiler_Profiler
16
#define _Included_org_eclipse_tptp_profiler_Profiler
17
#ifdef __cplusplus
18
extern "C" {
19
#endif
20
/*
21
 * Class:     org_eclipse_tptp_profiler_Profiler
22
 * Method:    initialize0
23
 * Signature: ()I
24
 */
25
JNIEXPORT jint JNICALL Java_org_eclipse_tptp_profiler_Profiler_initialize0
26
  (JNIEnv *, jobject);
27
28
/*
29
 * Class:     org_eclipse_tptp_profiler_Profiler
30
 * Method:    startProfiling0
31
 * Signature: ()I
32
 */
33
JNIEXPORT jint JNICALL Java_org_eclipse_tptp_profiler_Profiler_startProfiling0
34
  (JNIEnv *, jobject);
35
36
/*
37
 * Class:     org_eclipse_tptp_profiler_Profiler
38
 * Method:    stopProfiling0
39
 * Signature: ()I
40
 */
41
JNIEXPORT jint JNICALL Java_org_eclipse_tptp_profiler_Profiler_stopProfiling0
42
  (JNIEnv *, jobject);
43
44
/*
45
 * Class:     org_eclipse_tptp_profiler_Profiler
46
 * Method:    runGC0
47
 * Signature: ()I
48
 */
49
JNIEXPORT jint JNICALL Java_org_eclipse_tptp_profiler_Profiler_runGC0
50
  (JNIEnv *, jobject);
51
52
/*
53
 * Class:     org_eclipse_tptp_profiler_Profiler
54
 * Method:    emitXMLFragment0
55
 * Signature: (Ljava/lang/String;)I
56
 */
57
JNIEXPORT void JNICALL Java_org_eclipse_tptp_profiler_Profiler_emitXMLFragment0
58
  (JNIEnv *, jobject, jstring);
59
60
#ifdef __cplusplus
61
}
62
#endif
63
#endif
(-)src/org/eclipse/tptp/profiler/ProfilerAPINotAvailableException.java (+5 lines)
Added Link Here
1
package org.eclipse.tptp.profiler;
2
3
public class ProfilerAPINotAvailableException extends ProfilerNotAvailableException {
4
	private static final long serialVersionUID = 1L;
5
}

Return to bug 200251