Tuesday, March 21, 2017

Performance Profiler in Visual Studio Not Showing Function Names

In Visual Studio 2015 while doing performance profiling, I ran into the problem of memory addresses of functions being shown instead of their names.

During operations I got these errors:

VSP2340: Environment variables were not properly set during profiling run and managed symbols may not resolve.  Please use vsperfclrenv before profiling.

and

Error        DA0002: It appears that the file was collected without properly setting the environment variables with VSPerfCLREnv.cmd. Symbols for managed binaries may not resolve.        C:\Git\gm.marketing.marketplace\MarketPlace.Web\Report170320(2).vsp    0   

Both of these issues should not happen if you are using the profiler inside Visual Studio.

The root cause was not running Visual Studio in Admin mode from the start.
Here's an example scenario to get functions names in Visual Studio 2015.

Start Visual Studio in Admin mode:


 Select from the tool bar "Analyze" > "Performance Profiler..." and then "Start"



 Select the appropriate method.  I've been using "Instrumentation" lately.



 Select your projects and then "Next"



Check "Enable Tier Interaction Profiling"

Then, "Next", and finally, "Finish"

IE should launch, and run through your test scenario.
 Then select "Stop profiling".



The Summary report will appear:

Then, if you select the "Functions" report, your functions should appear with a friendly name.

Friday, March 17, 2017

Example of How to Return Errors to JavaScript ajax() Calls from a MVC .Net Controller

Recently I needed to return error codes to an ajax() call in JavaScript from a .Net MVC Controller  using an ActionResult.

Here's one way to do it:

In the Controller:



[HttpGet]
public ActionResult MyControllerMethod()
{
 ...
   bool happyPath = ....
   bool error1 = ...
   if (happyPath)
      {
         return PartialView("_Makes", viewModel);
      }
    else
      {
      if(error1)
      {
         Response.StatusCode = (int) HttpStatusCode.BadRequest;
         Response.StatusDescription = "CustomError1"; //variable "errorThown" in ajax recieving call
         return Content("CustomError1");
      } else {
         Response.StatusCode = (int) HttpStatusCode.InternalServerError;
         Response.StatusDescription = "CustomError1"; //variable "errorThown" in ajax recieving call
         return Content("CustomError2");
      }
}

 Then call this Controller in your JavaScript and display appropriate error JavaScript messages

function getMyControllerMethodStuff() {
    var myUrl = '../Home/MyControllerMethod';
    $.ajax({url: myUrl, type: "GET", datatype: 'html'})
        .fail(function (jqXhr, textStatus, errorThrown) {
            if (errorThrown === "CustomError1") {
                displayCustomErrorAlert1();
            } else {
                displayCustomErrorAlert2();
            }
        })
        .done(function (data) {
    // happy path
    ...
        });
}

Thursday, March 16, 2017

Example of Syntax Highlighting with Emacs

Recently I had a log file that was complex and reading it was tedious.  I wrote a quick syntax highlighting mode to make it easier on my bleary eyes.  Here's  an example using a hypothetical log file from a security robot that patrols a zoo at night.

Here's a snippet of the zoo log file we want to highlight, "2017-04-11a.zlog":



 ========== Zoo Application Started ==========
2017-03-15 09:55:34,329  INFO - Entering Primate zone
2017-03-15 09:58:38,553  INFO -   Gorillas - ok
2017-03-15 09:59:58,034  INFO -   Monkeys - ok
2017-03-15 09:58:38,553  INFO - Exiting Primate zone

2017-03-15 09:55:34,329  INFO - Entering Serengeti zone
2017-03-15 09:58:39,453  WARN -   Lions - not found in enclosure
2017-03-15 09:58:39,453  ERROR -  Lions - outside of cage!!
2017-03-15 09:58:38,553  INFO - Exiting Serengeti zone

We want to highlight the date/time and the type of entry "INFO,WARN,ERROR", whether we are entering or exiting and the type of animals.


The rules for highlighting are in the mode file, "zoo-log-mode.el":



;;example file of emacs syntax highlighting for log files - mitch fincher 2017
(setq zoo-log-highlights
      '(
    ("INFO\\|DEBUG\\|WARN\\|ERROR" . font-lock-function-name-face)
    ;; 2017-03-14 20:36:34,406
    ;; \\{4\\} is regex for repeat previous item 4 times
        ("[0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\} [0-9][0-9]:[0-9][0-9]:[0-9][0-9],[0-9]\\{3\\}" . font-lock-constant-face)
    ("Entering\\|Exiting" . font-lock-keyword-face)
    ;;hightlight line that starts with "====" followed by anything
    ("^====.*" . font-lock-comment-face)
    ("Gorillas\\|Monkeys\\|Lions" . font-lock-doc-face)
    )
)

(define-derived-mode zoo-log-mode fundamental-mode "zoo-log"
  "major mode for editing zoo-log log files."
  (setq font-lock-defaults '(zoo-log-highlights)))

;;override default colors for some
(set-face-foreground 'font-lock-doc-face        "Purple")
(set-face-foreground 'font-lock-comment-face        "LightGreen")


This is what it looks like in reverse video:

To get this to run quickly copy and paste the above file into your emacs directory.  Copy and paste the log file anyway on your system.

1. Load the "zoo-log-mode.el" file into a buffer and enter the command via M-x, "eval-buffer".
2. Load the zlog file into another buffer and enter the command "zoo-log-mode" to set the mode.
3. Notice you should have syntax highlighting.

To make this permanent, we need to hack your .emacs file.

1. Add this line at the top of you .emacs file:
(load "zoo-log-mode")
2.  In your auto-mode-alist, add the zoo mode.  This assumes the zoo log files have a ".zlog" extenstion:
(setq auto-mode-alist
      '(("\\.text$" . indented-text-mode)
        ("\\.zlog$" . zoo-log-mode) ;; this line
         ...
))


If you are wondering what faces are available, here they are:
font-lock-builtin-face
font-lock-comment-face
font-lock-comment-delimiter-face
font-lock-constant-face
font-lock-doc-face
font-lock-doc-string-face
font-lock-function-name-face
font-lock-keyword-face
font-lock-negation-char-face
font-lock-preprocessor-face
font-lock-string-face
font-lock-type-face
font-lock-variable-name-face
font-lock-warning-face


Enjoy.
Let me know if this works for you.



Wednesday, February 08, 2017

How to format a json file in Emacs with manual install

Today I needed to reformat a ginormous json file, but could not use the package-manager instructions for Emacs at github.com/joshwnj/json-modefor fire-wall/network issues.

So I manually installed all the needed files and put this in my .emacs file:

(require 'json-snatcher) ;from https://github.com/Sterlingg/json-snatcher
(require 'json-reformat) ;from https://github.com/gongo/json-reformat
(require 'json-mode) ;from https://github.com/joshwnj/json-mode;

 Then to format a file, select all (c-x h) then  m-x  json-reformat-region.  Works like a charm.

Thanks to the contributors for creating these packages!



Tuesday, January 24, 2017

Agile Austin "Prepare Your Software Development for 2020" by Israel Gat

Israel Gat (@agile_exec) presented to sixty people at Agile Austin at Kasasa about the future of software development.
Yasser

Israel Gat

"I love software."




Big ideal:  Automated Insight Generation through Analytics processes is starting to trump the Software Development process in terms of value generation.


Instead of Hierarchical Value Generation/Value Flow, we need to do horizontal flow.

People are starting to get rid of middle person between human knowledge and data scientist and replace with Insightful Applications/Machine Learning.

A computer that used machine learning reached Israeli Master level in chess in 3 days.

Two Primary Drivers of Contemporary Software
1. Internet of Things
2. Machine Learning

The only way to cope with vast amounts of data from IoT is machine learning.

Four Messages:
1.  Foundation of software is value generation
2. Current software methodologies and frameworks will need to change in 2020
3. End State (2025? 2030?) is to have machine learning do 70% of value generation process.
4.  By 2018 will face a shortage of people with deep analytical skills to extract insights from collected data.  We will need 1.5 million managers who have the quantitative skills to make decisions based on analytical data.

Questions:
What to do when data quality is bad?
How to manage poor software quality in data analytics?
What will happen to all the people replaced by analytics?


What is Insight Generation?
Insight generation is the identification of novel, interesting, plausible, and understandable relations among element of a data set that
a) need to formulate action plan
b) it results in an improvement as measured by KPIs.

Case for Automated Insight Generation:
1. The amount of data is so huge, humans can't process it
2. We don't know how to really analyze and utilize Big Data
3. Time to decision is decreasing while data velocity is increasing - we don't have time to process anymore

What to do?
Don't let today's method/process/framework debates absorb all you attention cycles
Start in-house training programs in IoT and Machine Learning
Young kids want bleeding-edge projects






Monday, January 09, 2017

Austin .Net User's Group: Distributed Systems 101 by Colin Pear

Colin Pear from ClearMeasure (@colinpear) presented to this month's Austin .Net User's Group on Distributed Systems.  Here's a few pics:




My random notes:

Eric Brewer Cap Theory
Michael Perry Video)

Distributed Processing 
Pick any two:
1. Available
2. Consistent
3. Partition Tolerant

8 Fallacies of Distributed Computing by Peter Deutsch
The Network is reliable
Latency is zero
Bandwidth is infinite
The network is secure
The topology doesn't change
There is only one Administrator
Transport cost is zero
The network is homogeneous

Free book:  http://go.particular.net/2017ADN

Distributed systems are complex
It's a paradign shift
Communication is the key

Messaging:
Smart endpoints, dumb pipes, distributed routing

Types of Coupling:
Spatial - physical links
Platform - Can a Java app talk to .Net? 
Temporal - time based


Going distributed solves problems, but it's more complex and requires different thinking.

NServiceBus does heavy lifting.  It's not free, but Colin thinks it's well worth it.  $25 or $30 bucks per machine per month.

NServiceBus can use AzureServiceBus, RabbitMQ, MSQueue, or SqlServer.

course by Udi Dahan:  http://go.particular.net/ADT0109








Thursday, January 05, 2017

Front-end Web Development Things I've Been Learning Lately


How to tell the server what type of data you want back from an http request using the "q" syntax. The "Accept" header, of course, sets the types you want returned. The "q" variable tells your preference for each type. "q" is the quality, with 1.0 meaning you want this type above all, a lower value means you don't want this type as much. So in this example we want both json and xml, but we want json more.

Accept: application/json;q=0.8,text/xml;q=0.7

And remember, "Content-Type" tells the server the format of the POST data you are uploading.

Content-Type: application/json
How to tell if a variable is exactly 5 numbers?  Use a regular expression in JavaScript:

 function isVariableFiveDigits(zipCode) {
    return /^(\d{5})$/.test(zipCode);;
}





Why can't Firefox read my "event.srcElement"?
"srcElement" was an IE thing.  Use the standard, "event.target", instead.


function myFunc(event) {
   var target = event.target || event.srcElement;
   var myData= $(target).data('my-data'); 
... 
}



 How to make an anchor tag look disabled when it is "disabled":

.myAnchorClass[disabled] {
    opacity: .5;
    cursor: not-allowed;
}




How to get the "data" attribute value from an element example:

   <input type="text" data-target-color="red" onkeyup="myFunc(event)" ... />

function myFunc(event) {
   var targetColor = $(event.srcElement).data('target-color');
...
}



What's the difference between a "rem" and an "em" in css?
Both set the font-size based on ancestors, but "rem" always looks at the top root element, while "em" starts looking upward through its parents to find the first one with a font-size defined.


When removing an "href" in an anchor tag (and using the 'click' attribute instead) how to make the cursor look like it's over a link:

a.myClass { cursor: pointer; }
 



How to stop iOS from making input elements have rounded corners that look like a button:

#MyInputId {
    border-radius: 0;
}




How to pass arguments to a jQuery click function:
 In a Razor page I assign event data from our ViewBag to variables to be passed to "myFunction":
  $('#myButton').click({ size: "@ViewBag.size", colour: "@ViewBag.colour" }, myFunction);

In the receiving function the variables are in the event's data object:
 function myFunction(event) {
    var size= event.data.size;
    var colour= event.data.colour;




How to trigger a form submit from JavaScript in .Net MVC:

 $('#MyFormId').submit();                        




How to make a banner stay at the bottom of the screen:

.myClass {
    position: fixed;
    bottom: 10px;
    z-index: 100;
    min-height: 100px;
}



How to use media queries for responsive design:

in variables.less:
@screen-sm-min:              768px;

in regular less file:
 .close-button, .close {
opacity: 1.0;
margin-top: 27px;
@media(min-width:@screen-sm-min){
margin-right: 40px;
}
}



To force Visual Studio to warn you about Razor page errors during compilation, have it pre-compile those pages:
1.  Right-click on the Project and select "Unload Project".
2.  Right-click and select "Edit *.csproj"
3.  In the csproj file set MvcBuildViews to true:
    true
4.  Right-click and select "Reload Project".



To search all files with names matching "*.shtml" and replace "http://www.fincher.org" with "https://www.fincher.org"
 find -type f -name "*.shtml" -exec sed -i "s/http:\/\/www.fincher.org/https:\/\/www.fincher.org/g" {} \;



How to get rid of some network calls in the Chrome debugger?
In the Chrome debugger, under "Network" you can exclude calls with a particular string by prefacing it with a "-".  For example, to get rid of all calls with "transport", do this: