|
Lines 11-21
Link Here
|
| 11 |
***********************************************************************/ |
11 |
***********************************************************************/ |
| 12 |
package org.eclipse.tptp.trace.arm.internal.model; |
12 |
package org.eclipse.tptp.trace.arm.internal.model; |
| 13 |
|
13 |
|
|
|
14 |
import java.util.ArrayList; |
| 14 |
import java.util.HashMap; |
15 |
import java.util.HashMap; |
|
|
16 |
import java.util.Iterator; |
| 17 |
import java.util.List; |
| 15 |
import java.util.Properties; |
18 |
import java.util.Properties; |
| 16 |
|
19 |
|
| 17 |
import org.eclipse.tptp.trace.arm.internal.logging.ARMLogger; |
20 |
import org.eclipse.tptp.trace.arm.internal.logging.ARMLogger; |
|
|
21 |
import org.opengroup.arm40.metric.ArmMetric; |
| 22 |
import org.opengroup.arm40.metric.ArmMetricCounter32; |
| 23 |
import org.opengroup.arm40.metric.ArmMetricCounter32Definition; |
| 24 |
import org.opengroup.arm40.metric.ArmMetricCounter64; |
| 25 |
import org.opengroup.arm40.metric.ArmMetricCounter64Definition; |
| 26 |
import org.opengroup.arm40.metric.ArmMetricCounterFloat32; |
| 27 |
import org.opengroup.arm40.metric.ArmMetricCounterFloat32Definition; |
| 28 |
import org.opengroup.arm40.metric.ArmMetricDefinition; |
| 18 |
import org.opengroup.arm40.metric.ArmMetricFactory; |
29 |
import org.opengroup.arm40.metric.ArmMetricFactory; |
|
|
30 |
import org.opengroup.arm40.metric.ArmMetricGauge32; |
| 31 |
import org.opengroup.arm40.metric.ArmMetricGauge32Definition; |
| 32 |
import org.opengroup.arm40.metric.ArmMetricGauge64; |
| 33 |
import org.opengroup.arm40.metric.ArmMetricGauge64Definition; |
| 34 |
import org.opengroup.arm40.metric.ArmMetricGaugeFloat32; |
| 35 |
import org.opengroup.arm40.metric.ArmMetricGaugeFloat32Definition; |
| 36 |
import org.opengroup.arm40.metric.ArmMetricGroup; |
| 37 |
import org.opengroup.arm40.metric.ArmMetricGroupDefinition; |
| 38 |
import org.opengroup.arm40.metric.ArmMetricNumericId32; |
| 39 |
import org.opengroup.arm40.metric.ArmMetricNumericId32Definition; |
| 40 |
import org.opengroup.arm40.metric.ArmMetricNumericId64; |
| 41 |
import org.opengroup.arm40.metric.ArmMetricNumericId64Definition; |
| 42 |
import org.opengroup.arm40.metric.ArmMetricString32; |
| 43 |
import org.opengroup.arm40.metric.ArmMetricString32Definition; |
| 44 |
import org.opengroup.arm40.metric.ArmTransactionWithMetrics; |
| 45 |
import org.opengroup.arm40.metric.ArmTransactionWithMetricsDefinition; |
| 19 |
import org.opengroup.arm40.tranreport.ArmTranReport; |
46 |
import org.opengroup.arm40.tranreport.ArmTranReport; |
| 20 |
import org.opengroup.arm40.tranreport.ArmTranReportFactory; |
47 |
import org.opengroup.arm40.tranreport.ArmTranReportFactory; |
| 21 |
import org.opengroup.arm40.transaction.ArmApplication; |
48 |
import org.opengroup.arm40.transaction.ArmApplication; |
|
Lines 53-61
Link Here
|
| 53 |
|
80 |
|
| 54 |
/* The ARM 4.0 Application Instance for the TT product. */ |
81 |
/* The ARM 4.0 Application Instance for the TT product. */ |
| 55 |
private ArmApplication applicationInstance; |
82 |
private ArmApplication applicationInstance; |
| 56 |
|
83 |
|
| 57 |
/* Internal cache of the ARM 4.0 identity properties */ |
84 |
/* Internal cache of the ARM 4.0 identity properties : ArmTransactionDefinition*/ |
| 58 |
private HashMap armTranDefCache = new HashMap(30); |
85 |
private HashMap armTranDefCache = new HashMap(30); |
|
|
86 |
|
| 87 |
/* Internal cache of the ARM 4.0 identity properties : ArmTransactionWithMetricsDefinition*/ |
| 88 |
private HashMap armTranWithMetricDefCache = new HashMap(30); |
| 59 |
|
89 |
|
| 60 |
/* The ARM 4.0 Error handler */ |
90 |
/* The ARM 4.0 Error handler */ |
| 61 |
private ArmErrorCallback armErrorCallBack; |
91 |
private ArmErrorCallback armErrorCallBack; |
|
Lines 102-107
Link Here
|
| 102 |
.newInstance(); |
132 |
.newInstance(); |
| 103 |
tranFactory.setErrorCallback(armErrorCallBack); |
133 |
tranFactory.setErrorCallback(armErrorCallBack); |
| 104 |
} catch (Exception ex) { |
134 |
} catch (Exception ex) { |
|
|
135 |
ex.printStackTrace(); |
| 105 |
/* If error, then null */ |
136 |
/* If error, then null */ |
| 106 |
tranFactory = null; |
137 |
tranFactory = null; |
| 107 |
/* ArmTransFactoryInit_ERROR = IWAT0766E */ |
138 |
/* ArmTransFactoryInit_ERROR = IWAT0766E */ |
|
Lines 109-114
Link Here
|
| 109 |
ArmInstrumentMessages.getString("ArmTransFactoryInit_ERROR"), |
140 |
ArmInstrumentMessages.getString("ArmTransFactoryInit_ERROR"), |
| 110 |
ARMLogger.LOG, ex); |
141 |
ARMLogger.LOG, ex); |
| 111 |
} |
142 |
} |
|
|
143 |
catch(Throwable t) |
| 144 |
{ |
| 145 |
t.printStackTrace(); |
| 146 |
} |
| 112 |
} |
147 |
} |
| 113 |
|
148 |
|
| 114 |
return tranFactory; |
149 |
return tranFactory; |
|
Lines 152-158
Link Here
|
| 152 |
* @return the ArmMetricFactory. |
187 |
* @return the ArmMetricFactory. |
| 153 |
*/ |
188 |
*/ |
| 154 |
private ArmMetricFactory getArmMetricFactory() { |
189 |
private ArmMetricFactory getArmMetricFactory() { |
| 155 |
if (metricFactory != null) { |
190 |
if (metricFactory == null) { |
| 156 |
/* Check for the metric factory */ |
191 |
/* Check for the metric factory */ |
| 157 |
try { |
192 |
try { |
| 158 |
Properties p = System.getProperties(); |
193 |
Properties p = System.getProperties(); |
|
Lines 262-274
Link Here
|
| 262 |
*/ |
297 |
*/ |
| 263 |
public ArmTransaction transactionStart(InstrumentDataProvider data, |
298 |
public ArmTransaction transactionStart(InstrumentDataProvider data, |
| 264 |
ArmCorrelator parentCorrelator) { |
299 |
ArmCorrelator parentCorrelator) { |
| 265 |
|
|
|
| 266 |
ArmTransaction armTransaction = null; |
300 |
ArmTransaction armTransaction = null; |
| 267 |
|
301 |
|
| 268 |
if (tranFactory != null) { |
302 |
if (tranFactory != null) { |
| 269 |
ArmTransactionDefinition armTranDef = getArmTransactionDefinition(data); |
303 |
// create ArmTransaction/ArmTransactionWithMetric instance if there |
| 270 |
armTransaction = tranFactory.newArmTransaction(getArmApplication(), |
304 |
// is/isn't ARM metric. |
| 271 |
armTranDef); |
305 |
if (ArmMetricManager.getInstance().hasMetric()) { |
|
|
306 |
try { |
| 307 |
armTransaction = getArmTransactionWithMetric(data); |
| 308 |
} catch (Throwable e) { |
| 309 |
// TODO Auto-generated catch block |
| 310 |
e.printStackTrace(); |
| 311 |
} |
| 312 |
} else { |
| 313 |
ArmTransactionDefinition armTranDef = getArmTransactionDefinition(data); |
| 314 |
armTransaction = tranFactory.newArmTransaction( |
| 315 |
getArmApplication(), armTranDef); |
| 316 |
} |
| 272 |
|
317 |
|
| 273 |
String[] contextValues = data.getContextValues(); |
318 |
String[] contextValues = data.getContextValues(); |
| 274 |
for (int i = 0; i < contextValues.length; i++) { |
319 |
for (int i = 0; i < contextValues.length; i++) { |
|
Lines 283-288
Link Here
|
| 283 |
armTransaction.setUser(tranFactory.newArmUser( |
328 |
armTransaction.setUser(tranFactory.newArmUser( |
| 284 |
data.getUserName() == null ? "*" : data.getUserName(), null)); |
329 |
data.getUserName() == null ? "*" : data.getUserName(), null)); |
| 285 |
|
330 |
|
|
|
331 |
|
| 286 |
if (parentCorrelator == null) { |
332 |
if (parentCorrelator == null) { |
| 287 |
armTransaction.start(); |
333 |
armTransaction.start(); |
| 288 |
} else { |
334 |
} else { |
|
Lines 294-299
Link Here
|
| 294 |
} // end of transactionStart() |
340 |
} // end of transactionStart() |
| 295 |
|
341 |
|
| 296 |
/** |
342 |
/** |
|
|
343 |
* Create an ArmTransactionWithMetrics instance. |
| 344 |
* |
| 345 |
* @param data |
| 346 |
* @return |
| 347 |
*/ |
| 348 |
private ArmTransactionWithMetrics getArmTransactionWithMetric( |
| 349 |
InstrumentDataProvider data) { |
| 350 |
if (metricFactory == null) { |
| 351 |
getArmMetricFactory(); |
| 352 |
} |
| 353 |
|
| 354 |
String transName = data.getTransactionName(); |
| 355 |
ArmTransactionWithMetrics transactionWithMetrics = null; |
| 356 |
if (metricFactory != null) { |
| 357 |
synchronized (armTranWithMetricDefCache) { |
| 358 |
if (metricFactory != null) { |
| 359 |
List metrics = ArmMetricManager.getInstance().getMetrics(); |
| 360 |
ArmTransactionWithMetricsDefinition transactionWithMetricsDef = getArmTransactionWithMetricDefinition( |
| 361 |
transName, metrics); |
| 362 |
transactionWithMetrics = getArmTransactionWithMetric( |
| 363 |
transName, metrics, transactionWithMetricsDef); |
| 364 |
} |
| 365 |
} |
| 366 |
} |
| 367 |
|
| 368 |
return transactionWithMetrics; |
| 369 |
} |
| 370 |
|
| 371 |
/** |
| 372 |
* Create an ArmTransactionWithMetricsDefinition instance. Maybe should use |
| 373 |
* cache here. |
| 374 |
* |
| 375 |
* @param transName |
| 376 |
* @param metrics |
| 377 |
* @return |
| 378 |
*/ |
| 379 |
private ArmTransactionWithMetricsDefinition getArmTransactionWithMetricDefinition( |
| 380 |
String transName, List metrics) { |
| 381 |
ArmTransactionWithMetricsDefinition transactionWithMetricsDef; |
| 382 |
List metricsDef = getArmMetricDefs(metrics); |
| 383 |
|
| 384 |
ArmMetricDefinition[] metricDefArray = (ArmMetricDefinition[]) metricsDef |
| 385 |
.toArray(new ArmMetricDefinition[metricsDef.size()]); |
| 386 |
|
| 387 |
ArmMetricGroupDefinition metGroupDef = metricFactory |
| 388 |
.newArmMetricGroupDefinition(metricDefArray); |
| 389 |
|
| 390 |
transactionWithMetricsDef = (ArmTransactionWithMetricsDefinition) armTranWithMetricDefCache |
| 391 |
.get(transName); |
| 392 |
|
| 393 |
if (transactionWithMetricsDef == null) { |
| 394 |
transactionWithMetricsDef = metricFactory |
| 395 |
.newArmTransactionWithMetricsDefinition( |
| 396 |
getArmApplicationDefinition(), transName, null, |
| 397 |
metGroupDef, null); |
| 398 |
|
| 399 |
armTranWithMetricDefCache.put(transName, transactionWithMetricsDef); |
| 400 |
} |
| 401 |
return transactionWithMetricsDef; |
| 402 |
} |
| 403 |
|
| 404 |
/** |
| 405 |
* Get the ArmMetricDefinition instances. The elements of parameter metrics |
| 406 |
* will be updated to match the metric and it's definition.<br> |
| 407 |
* TODO Move switch-case here to some other place. For example, another |
| 408 |
* classes. switch-case is not good coding style. |
| 409 |
* |
| 410 |
* @param metrics |
| 411 |
* List of ArmMetricManager.Metric. |
| 412 |
* @return List of ArmMetricDefinition. |
| 413 |
*/ |
| 414 |
private List getArmMetricDefs(List metrics) { |
| 415 |
List metricDefs = new ArrayList(); |
| 416 |
for (Iterator iterator = metrics.iterator(); iterator.hasNext();) { |
| 417 |
ArmMetricManager.Metric metric = (ArmMetricManager.Metric) iterator |
| 418 |
.next(); |
| 419 |
ArmMetricDefinition metricDefinition = metric.getDefinition(); |
| 420 |
if (metricDefinition == null) { |
| 421 |
// Big switch-case to create ArmMetricDefinition instance. |
| 422 |
switch (metric.getMetricType()) { |
| 423 |
case ArmMetricConstants.ArmMetricCounter32: |
| 424 |
metricDefinition = metricFactory |
| 425 |
.newArmMetricCounter32Definition( |
| 426 |
getArmApplicationDefinition(), metric |
| 427 |
.getMetricName(), null, |
| 428 |
ArmMetricDefinition.METRIC_USE_GENERAL, |
| 429 |
null); |
| 430 |
break; |
| 431 |
case ArmMetricConstants.ArmMetricCounter64: |
| 432 |
metricDefinition = metricFactory |
| 433 |
.newArmMetricCounter64Definition( |
| 434 |
getArmApplicationDefinition(), metric |
| 435 |
.getMetricName(), null, |
| 436 |
ArmMetricDefinition.METRIC_USE_GENERAL, |
| 437 |
null); |
| 438 |
break; |
| 439 |
case ArmMetricConstants.ArmMetricCounterFloat32: |
| 440 |
metricDefinition = metricFactory |
| 441 |
.newArmMetricCounterFloat32Definition( |
| 442 |
getArmApplicationDefinition(), metric |
| 443 |
.getMetricName(), null, |
| 444 |
ArmMetricDefinition.METRIC_USE_GENERAL, |
| 445 |
null); |
| 446 |
break; |
| 447 |
case ArmMetricConstants.ArmMetricGauge32: |
| 448 |
metricDefinition = metricFactory |
| 449 |
.newArmMetricGauge32Definition( |
| 450 |
getArmApplicationDefinition(), metric |
| 451 |
.getMetricName(), null, |
| 452 |
ArmMetricDefinition.METRIC_USE_GENERAL, |
| 453 |
null); |
| 454 |
break; |
| 455 |
case ArmMetricConstants.ArmMetricGauge64: |
| 456 |
metricDefinition = metricFactory |
| 457 |
.newArmMetricGauge64Definition( |
| 458 |
getArmApplicationDefinition(), metric |
| 459 |
.getMetricName(), null, |
| 460 |
ArmMetricDefinition.METRIC_USE_GENERAL, |
| 461 |
null); |
| 462 |
break; |
| 463 |
case ArmMetricConstants.ArmMetricGaugeFloat32: |
| 464 |
metricDefinition = metricFactory |
| 465 |
.newArmMetricGaugeFloat32Definition( |
| 466 |
getArmApplicationDefinition(), metric |
| 467 |
.getMetricName(), null, |
| 468 |
ArmMetricDefinition.METRIC_USE_GENERAL, |
| 469 |
null); |
| 470 |
break; |
| 471 |
case ArmMetricConstants.ArmMetricNumericId32: |
| 472 |
metricDefinition = metricFactory |
| 473 |
.newArmMetricNumericId32Definition( |
| 474 |
getArmApplicationDefinition(), metric |
| 475 |
.getMetricName(), null, |
| 476 |
ArmMetricDefinition.METRIC_USE_GENERAL, |
| 477 |
null); |
| 478 |
break; |
| 479 |
case ArmMetricConstants.ArmMetricNumericId64: |
| 480 |
metricDefinition = metricFactory |
| 481 |
.newArmMetricNumericId64Definition( |
| 482 |
getArmApplicationDefinition(), metric |
| 483 |
.getMetricName(), null, |
| 484 |
ArmMetricDefinition.METRIC_USE_GENERAL, |
| 485 |
null); |
| 486 |
break; |
| 487 |
case ArmMetricConstants.ArmMetricString32: |
| 488 |
metricDefinition = metricFactory |
| 489 |
.newArmMetricString32Definition( |
| 490 |
getArmApplicationDefinition(), metric |
| 491 |
.getMetricName(), null, |
| 492 |
ArmMetricDefinition.METRIC_USE_GENERAL, |
| 493 |
null); |
| 494 |
break; |
| 495 |
default: |
| 496 |
metricDefinition = null; |
| 497 |
break; |
| 498 |
} |
| 499 |
} |
| 500 |
if (metricDefinition != null) { |
| 501 |
metricDefs.add(metricDefinition); |
| 502 |
metric.setDefinition(metricDefinition); |
| 503 |
} |
| 504 |
} |
| 505 |
return metricDefs; |
| 506 |
} |
| 507 |
|
| 508 |
/** |
| 509 |
* Create an ArmTransactionWithMetrics instance. |
| 510 |
* |
| 511 |
* @param transName |
| 512 |
* @param metrics |
| 513 |
* @param transactionWithMetricsDef |
| 514 |
* @return |
| 515 |
*/ |
| 516 |
private ArmTransactionWithMetrics getArmTransactionWithMetric( |
| 517 |
String transName, List metrics, |
| 518 |
ArmTransactionWithMetricsDefinition transactionWithMetricsDef) { |
| 519 |
ArmTransactionWithMetrics transactionWithMetrics; |
| 520 |
List armMetrics = getArmMetric(metrics); |
| 521 |
|
| 522 |
ArmMetric[] metricDefArray = (ArmMetric[]) armMetrics |
| 523 |
.toArray(new ArmMetric[armMetrics.size()]); |
| 524 |
|
| 525 |
ArmMetricGroup metGroup = metricFactory.newArmMetricGroup( |
| 526 |
transactionWithMetricsDef.getMetricGroupDefinition(), |
| 527 |
metricDefArray); |
| 528 |
|
| 529 |
transactionWithMetrics = metricFactory.newArmTransactionWithMetrics( |
| 530 |
getArmApplication(), transactionWithMetricsDef, metGroup); |
| 531 |
|
| 532 |
return transactionWithMetrics; |
| 533 |
} |
| 534 |
|
| 535 |
/** |
| 536 |
* Get the ArmMetricDefinition instances.<br> |
| 537 |
* TODO Move switch-case here to some other place. For example, another |
| 538 |
* classes. switch-case is not good coding style. |
| 539 |
* |
| 540 |
* @param metrics |
| 541 |
* List of ArmMetricManager.Metric. |
| 542 |
* @return List of ArmMetric. |
| 543 |
*/ |
| 544 |
private List getArmMetric(List metrics) { |
| 545 |
List armMetrics = new ArrayList(); |
| 546 |
for (Iterator iterator = metrics.iterator(); iterator.hasNext();) { |
| 547 |
ArmMetricManager.Metric metric = (ArmMetricManager.Metric) iterator |
| 548 |
.next(); |
| 549 |
ArmMetric armMetric = null; |
| 550 |
ArmMetricDefinition metricDefinition = metric.getDefinition(); |
| 551 |
if (metricDefinition != null) { |
| 552 |
String metricValue = metric.getMetricValue(); |
| 553 |
// Big switch-case to create ArmMetric instance. |
| 554 |
switch (metric.getMetricType()) { |
| 555 |
case ArmMetricConstants.ArmMetricCounter32: |
| 556 |
ArmMetricCounter32 armMetricCounter32 = metricFactory |
| 557 |
.newArmMetricCounter32((ArmMetricCounter32Definition) metricDefinition); |
| 558 |
armMetricCounter32.set(Integer.parseInt(metricValue)); |
| 559 |
armMetric = armMetricCounter32; |
| 560 |
break; |
| 561 |
case ArmMetricConstants.ArmMetricCounter64: |
| 562 |
ArmMetricCounter64 armMetricCounter64 = metricFactory |
| 563 |
.newArmMetricCounter64((ArmMetricCounter64Definition) metricDefinition); |
| 564 |
armMetricCounter64.set(Long.parseLong(metricValue)); |
| 565 |
armMetric = armMetricCounter64; |
| 566 |
break; |
| 567 |
case ArmMetricConstants.ArmMetricCounterFloat32: |
| 568 |
ArmMetricCounterFloat32 armMetricCounterFloat32 = metricFactory |
| 569 |
.newArmMetricCounterFloat32((ArmMetricCounterFloat32Definition) metricDefinition); |
| 570 |
armMetricCounterFloat32.set(Float.parseFloat(metricValue)); |
| 571 |
armMetric = armMetricCounterFloat32; |
| 572 |
break; |
| 573 |
case ArmMetricConstants.ArmMetricGauge32: |
| 574 |
ArmMetricGauge32 armMetricGauge32 = metricFactory |
| 575 |
.newArmMetricGauge32((ArmMetricGauge32Definition) metricDefinition); |
| 576 |
armMetricGauge32.set(Integer.parseInt(metricValue)); |
| 577 |
armMetric = armMetricGauge32; |
| 578 |
break; |
| 579 |
case ArmMetricConstants.ArmMetricGauge64: |
| 580 |
ArmMetricGauge64 armMetricGauge64 = metricFactory |
| 581 |
.newArmMetricGauge64((ArmMetricGauge64Definition) metricDefinition); |
| 582 |
armMetricGauge64.set(Long.parseLong(metricValue)); |
| 583 |
armMetric = armMetricGauge64; |
| 584 |
break; |
| 585 |
case ArmMetricConstants.ArmMetricGaugeFloat32: |
| 586 |
ArmMetricGaugeFloat32 armMetricGaugeFloat32 = metricFactory |
| 587 |
.newArmMetricGaugeFloat32((ArmMetricGaugeFloat32Definition) metricDefinition); |
| 588 |
armMetricGaugeFloat32.set(Float.parseFloat(metricValue)); |
| 589 |
armMetric = armMetricGaugeFloat32; |
| 590 |
break; |
| 591 |
case ArmMetricConstants.ArmMetricNumericId32: |
| 592 |
ArmMetricNumericId32 armMetricNumericId32 = metricFactory |
| 593 |
.newArmMetricNumericId32((ArmMetricNumericId32Definition) metricDefinition); |
| 594 |
armMetricNumericId32.set(Integer.parseInt(metricValue)); |
| 595 |
armMetric = armMetricNumericId32; |
| 596 |
break; |
| 597 |
case ArmMetricConstants.ArmMetricNumericId64: |
| 598 |
ArmMetricNumericId64 armMetricNumericId64 = metricFactory |
| 599 |
.newArmMetricNumericId64((ArmMetricNumericId64Definition) metricDefinition); |
| 600 |
armMetricNumericId64.set(Long.parseLong(metricValue)); |
| 601 |
armMetric = armMetricNumericId64; |
| 602 |
break; |
| 603 |
case ArmMetricConstants.ArmMetricString32: |
| 604 |
ArmMetricString32 armMetricString32 = metricFactory |
| 605 |
.newArmMetricString32((ArmMetricString32Definition) metricDefinition); |
| 606 |
armMetricString32.set(metricValue); |
| 607 |
armMetric = armMetricString32; |
| 608 |
break; |
| 609 |
default: |
| 610 |
armMetric = null; |
| 611 |
break; |
| 612 |
} |
| 613 |
} |
| 614 |
if (armMetric != null) { |
| 615 |
armMetrics.add(armMetric); |
| 616 |
} |
| 617 |
} |
| 618 |
return armMetrics; |
| 619 |
} |
| 620 |
|
| 621 |
/** |
| 297 |
* The wrapper method for the arm stop() call. |
622 |
* The wrapper method for the arm stop() call. |
| 298 |
* |
623 |
* |
| 299 |
* @param transaction the transaction data |
624 |
* @param transaction the transaction data |