aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/scripts/python/syscall-counts-by-pid.py
blob: daf314cc5dd313e9fca436eafb82282ea4f40324 (plain) (blame)
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
65
66
67
68
69
70
71
72
73
74
# system call counts, by pid
# (c) 2010, Tom Zanussi <tzanussi@gmail.com>
# Licensed under the terms of the GNU GPL License version 2
#
# Displays system-wide system call totals, broken down by syscall.
# If a [comm] arg is specified, only syscalls called by [comm] are displayed.

import os, sys

sys.path.append(os.environ['PERF_EXEC_PATH'] + \
	'/scripts/python/Perf-Trace-Util/lib/Perf/Trace')

from perf_trace_context import *
from Core import *
from Util import syscall_name

usage = "perf script -s syscall-counts-by-pid.py [comm]\n";

for_comm = None
for_pid = None

if len(sys.argv) > 2:
	sys.exit(usage)

if len(sys.argv) > 1:
	try:
		for_pid = int(sys.argv[1])
	except:
		for_comm = sys.argv[1]

syscalls = autodict()

def trace_begin():
	print "Press control+C to stop and show the summary"

def trace_end():
	print_syscall_totals()

def raw_syscalls__sys_enter(event_name, context, common_cpu,
	common_secs, common_nsecs, common_pid, common_comm,
	common_callchain, id, args):

	if (for_comm and common_comm != for_comm) or \
	   (for_pid  and common_pid  != for_pid ):
		return
	try:
		syscalls[common_comm][common_pid][id] += 1
	except TypeError:
		syscalls[common_comm][common_pid][id] = 1

def syscalls__sys_enter(event_name, context, common_cpu,
	common_secs, common_nsecs, common_pid, common_comm,
	id, args):
	raw_syscalls__sys_enter(**locals())

def print_syscall_totals():
    if for_comm is not None:
	    print "\nsyscall events for %s:\n\n" % (for_comm),
    else:
	    print "\nsyscall events by comm/pid:\n\n",

    print "%-40s  %10s\n" % ("comm [pid]/syscalls", "count"),
    print "%-40s  %10s\n" % ("----------------------------------------", \
                                 "----------"),

    comm_keys = syscalls.keys()
    for comm in comm_keys:
	    pid_keys = syscalls[comm].keys()
	    for pid in pid_keys:
		    print "\n%s [%d]\n" % (comm, pid),
		    id_keys = syscalls[comm][pid].keys()
		    for id, val in sorted(syscalls[comm][pid].iteritems(), \
				  key = lambda(k, v): (v, k),  reverse = True):
			    print "  %-38s  %10d\n" % (syscall_name(id), val),
384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675
#ifndef __wavefront_h__
#define __wavefront_h__

/* WaveFront header file.
 *   
 * Copyright (C) by Paul Barton-Davis 1998
 *
 * This program is distributed under the GNU GENERAL PUBLIC LICENSE (GPL)
 * Version 2 (June 1991). See the "COPYING" file distributed with this software
 * for more info.  
 */

#if (!defined(__GNUC__) && !defined(__GNUG__))

     You will not be able to compile this file correctly without gcc, because
     it is necessary to pack the "wavefront_alias" structure to a size
     of 22 bytes, corresponding to 16-bit alignment (as would have been
     the case on the original platform, MS-DOS). If this is not done,
     then WavePatch-format files cannot be read/written correctly.
     The method used to do this here ("__attribute__((packed)") is
     completely compiler dependent.
     
     All other wavefront_* types end up aligned to 32 bit values and
     still have the same (correct) size.

#else

     /* However, note that as of G++ 2.7.3.2, g++ was unable to
	correctly parse *type* __attribute__ tags. It will do the
	right thing if we use the "packed" attribute on each struct
	member, which has the same semantics anyway. 
     */

#endif /* __GNUC__ */

/***************************** WARNING ********************************
  PLEASE DO NOT MODIFY THIS FILE IN ANY WAY THAT AFFECTS ITS ABILITY TO 
  BE USED WITH EITHER C *OR* C++.
 **********************************************************************/

#ifndef NUM_MIDIKEYS 
#define NUM_MIDIKEYS 128
#endif  /* NUM_MIDIKEYS */

#ifndef NUM_MIDICHANNELS
#define NUM_MIDICHANNELS 16
#endif  /* NUM_MIDICHANNELS */

/* These are very useful/important. the original wavefront interface
   was developed on a 16 bit system, where sizeof(int) = 2
   bytes. Defining things like this makes the code much more portable, and
   easier to understand without having to toggle back and forth
   between a 16-bit view of the world and a 32-bit one. 
 */   

typedef short INT16;
typedef unsigned short UINT16;
typedef int INT32;
typedef unsigned int UINT32;
typedef char CHAR8;
typedef unsigned char UCHAR8;

/* Pseudo-commands not part of the WaveFront command set.
   These are used for various driver controls and direct
   hardware control.
 */

#define WFC_DEBUG_DRIVER                0
#define WFC_FX_IOCTL                    1
#define WFC_PATCH_STATUS                2
#define WFC_PROGRAM_STATUS              3
#define WFC_SAMPLE_STATUS               4
#define WFC_DISABLE_INTERRUPTS          5
#define WFC_ENABLE_INTERRUPTS           6
#define WFC_INTERRUPT_STATUS            7
#define WFC_ROMSAMPLES_RDONLY           8
#define WFC_IDENTIFY_SLOT_TYPE          9

/* Wavefront synth commands
 */

#define WFC_DOWNLOAD_SAMPLE		0x80
#define WFC_DOWNLOAD_BLOCK		0x81
#define WFC_DOWNLOAD_MULTISAMPLE	0x82
#define WFC_DOWNLOAD_SAMPLE_ALIAS	0x83
#define WFC_DELETE_SAMPLE		0x84
#define WFC_REPORT_FREE_MEMORY		0x85
#define WFC_DOWNLOAD_PATCH		0x86
#define WFC_DOWNLOAD_PROGRAM		0x87
#define WFC_SET_SYNTHVOL		0x89
#define WFC_SET_NVOICES			0x8B
#define WFC_DOWNLOAD_DRUM		0x90
#define WFC_GET_SYNTHVOL		0x92
#define WFC_GET_NVOICES			0x94
#define WFC_DISABLE_CHANNEL		0x9A
#define WFC_ENABLE_CHANNEL		0x9B
#define WFC_MISYNTH_OFF			0x9D
#define WFC_MISYNTH_ON			0x9E
#define WFC_FIRMWARE_VERSION		0x9F
#define WFC_GET_NSAMPLES		0xA0
#define WFC_DISABLE_DRUM_PROGRAM	0xA2
#define WFC_UPLOAD_PATCH		0xA3
#define WFC_UPLOAD_PROGRAM		0xA4
#define WFC_SET_TUNING			0xA6
#define WFC_GET_TUNING			0xA7
#define WFC_VMIDI_ON			0xA8
#define WFC_VMIDI_OFF			0xA9
#define WFC_MIDI_STATUS			0xAA
#define WFC_GET_CHANNEL_STATUS		0xAB
#define WFC_DOWNLOAD_SAMPLE_HEADER	0xAC
#define WFC_UPLOAD_SAMPLE_HEADER	0xAD
#define WFC_UPLOAD_MULTISAMPLE		0xAE
#define WFC_UPLOAD_SAMPLE_ALIAS		0xAF
#define WFC_IDENTIFY_SAMPLE_TYPE	0xB0
#define WFC_DOWNLOAD_EDRUM_PROGRAM	0xB1
#define WFC_UPLOAD_EDRUM_PROGRAM	0xB2
#define WFC_SET_EDRUM_CHANNEL		0xB3
#define WFC_INSTOUT_LEVELS		0xB4
#define WFC_PEAKOUT_LEVELS		0xB5
#define WFC_REPORT_CHANNEL_PROGRAMS	0xB6
#define WFC_HARDWARE_VERSION		0xCF
#define WFC_UPLOAD_SAMPLE_PARAMS	0xD7
#define WFC_DOWNLOAD_OS			0xF1
#define WFC_NOOP                        0xFF

#define WF_MAX_SAMPLE   512
#define WF_MAX_PATCH    256
#define WF_MAX_PROGRAM  128

#define WF_SECTION_MAX  44   /* longest OS section length */

/* # of bytes we send to the board when sending it various kinds of
   substantive data, such as samples, patches and programs.
*/

#define WF_PROGRAM_BYTES 32
#define WF_PATCH_BYTES 132
#define WF_SAMPLE_BYTES 27
#define WF_SAMPLE_HDR_BYTES 25
#define WF_ALIAS_BYTES 25
#define WF_DRUM_BYTES 9
#define WF_MSAMPLE_BYTES 259 /* (MIDI_KEYS * 2) + 3 */

#define WF_ACK     0x80
#define WF_DMA_ACK 0x81

/* OR-values for MIDI status bits */

#define WF_MIDI_VIRTUAL_ENABLED 0x1
#define WF_MIDI_VIRTUAL_IS_EXTERNAL 0x2
#define WF_MIDI_IN_TO_SYNTH_DISABLED 0x4

/* slot indexes for struct address_info: makes code a little more mnemonic */

#define WF_SYNTH_SLOT         0
#define WF_INTERNAL_MIDI_SLOT 1
#define WF_EXTERNAL_MIDI_SLOT 2

/* Magic MIDI bytes used to switch I/O streams on the ICS2115 MPU401
   emulation. Note these NEVER show up in output from the device and
   should NEVER be used in input unless Virtual MIDI mode has been 
   disabled. If they do show up as input, the results are unpredictable.
*/

#define WF_EXTERNAL_SWITCH  0xFD
#define WF_INTERNAL_SWITCH  0xF9

/* Debugging flags */

#define WF_DEBUG_CMD 0x1
#define WF_DEBUG_DATA 0x2
#define WF_DEBUG_LOAD_PATCH 0x4
#define WF_DEBUG_IO 0x8

/* WavePatch file format stuff */

#define WF_WAVEPATCH_VERSION     120;  /*  Current version number (1.2)  */
#define WF_MAX_COMMENT           64    /*  Comment length */
#define WF_NUM_LAYERS            4
#define WF_NAME_LENGTH           32
#define WF_SOURCE_LENGTH         260

#define BankFileID     "Bank"
#define DrumkitFileID  "DrumKit"
#define ProgramFileID  "Program"

struct wf_envelope
{
    UCHAR8 attack_time:7;
    UCHAR8 Unused1:1;

    UCHAR8 decay1_time:7;
    UCHAR8 Unused2:1;

    UCHAR8 decay2_time:7;
    UCHAR8 Unused3:1;

    UCHAR8 sustain_time:7;
    UCHAR8 Unused4:1;

    UCHAR8 release_time:7;
    UCHAR8 Unused5:1;

    UCHAR8 release2_time:7;
    UCHAR8 Unused6:1;

    CHAR8 attack_level;
    CHAR8 decay1_level;
    CHAR8 decay2_level;
    CHAR8 sustain_level;
    CHAR8 release_level;

    UCHAR8 attack_velocity:7;
    UCHAR8 Unused7:1;

    UCHAR8 volume_velocity:7;
    UCHAR8 Unused8:1;

    UCHAR8 keyboard_scaling:7;
    UCHAR8 Unused9:1;
};
typedef struct wf_envelope wavefront_envelope;

struct wf_lfo
{
    UCHAR8 sample_number;

    UCHAR8 frequency:7;
    UCHAR8 Unused1:1;

    UCHAR8 am_src:4;
    UCHAR8 fm_src:4;

    CHAR8 fm_amount;
    CHAR8 am_amount;
    CHAR8 start_level;
    CHAR8 end_level;

    UCHAR8 ramp_delay:7;
    UCHAR8 wave_restart:1; /* for LFO2 only */

    UCHAR8 ramp_time:7;
    UCHAR8 Unused2:1;
};
typedef struct wf_lfo wavefront_lfo;

struct wf_patch
{
    INT16  frequency_bias;         /*  ** THIS IS IN MOTOROLA FORMAT!! ** */

    UCHAR8 amplitude_bias:7;
    UCHAR8 Unused1:1;

    UCHAR8 portamento:7;
    UCHAR8 Unused2:1;

    UCHAR8 sample_number;

    UCHAR8 pitch_bend:4;
    UCHAR8 sample_msb:1;
    UCHAR8 Unused3:3;

    UCHAR8 mono:1;
    UCHAR8 retrigger:1;
    UCHAR8 nohold:1;
    UCHAR8 restart:1;
    UCHAR8 filterconfig:2; /* SDK says "not used" */
    UCHAR8 reuse:1;
    UCHAR8 reset_lfo:1;    

    UCHAR8 fm_src2:4;
    UCHAR8 fm_src1:4;